diff --git a/src/redux/thunk/GetByThunk.ts b/src/redux/thunk/GetByThunk.ts index bcb1a26..cb1d165 100644 --- a/src/redux/thunk/GetByThunk.ts +++ b/src/redux/thunk/GetByThunk.ts @@ -4,12 +4,9 @@ import {CustomJoke} from "../../model/CustomJoke"; import {setCustomJokeById} from "../actions/CustomJoke"; export const getItem = (uri:string, constructor : (json:any) => TItem, setItem: (item: TItem) => any) => { - //In order to use await your callback must be asynchronous using async keyword. return async dispatch => { - //Then perform your asynchronous operations. try { const promise = await fetch(uri); - //Then use the json method to get json data from api/ const Json = await promise.json(); const Item: TItem = constructor(Json); dispatch(setItem(Item)); diff --git a/src/redux/thunk/GetThunk.ts b/src/redux/thunk/GetThunk.ts index fe8845e..f5542c3 100644 --- a/src/redux/thunk/GetThunk.ts +++ b/src/redux/thunk/GetThunk.ts @@ -6,12 +6,9 @@ import {CustomJoke} from "../../model/CustomJoke"; import {setCustomJokesList} from "../actions/CustomJoke"; export const getList = (uri:string, constructor : (json:any) => TList, setList: (list: TList[]) => any) => { - //In order to use await your callback must be asynchronous using async keyword. return async dispatch => { - //Then perform your asynchronous operations. try { const promise = await fetch(uri); - //Then use the json method to get json data from api/ const listJson = await promise.json(); const List: TList[] = listJson.map(elt => constructor(elt)); dispatch(setList(List)); diff --git a/src/screens/AddScreen.tsx b/src/screens/AddScreen.tsx index 2cc460d..5488cab 100644 --- a/src/screens/AddScreen.tsx +++ b/src/screens/AddScreen.tsx @@ -11,7 +11,6 @@ import {postCustomJoke} from "../redux/thunk/PostThunk"; export default function AddScreen() { // @ts-ignore - const allJokes = useSelector(state => state.customReducer.jokes); const dispatch = useDispatch(); const MAX_LENGTH = 10; const [joke, onChangeJoke] = React.useState(''); @@ -29,44 +28,6 @@ export default function AddScreen() { clearFields(); }; - // const [joke, setJoke] = useState(""); - // const [jokeFall, setJokeFall] = useState(""); - // const [category, setCategory] = useState(""); - // const [categoryExceeded, setCategoryExceeded] = useState(false); - // const [buttonDisabled, setButtonDisabled] = useState(true); - // const MAX_CATEGORY_LENGTH = 10; - // const dispatch = useDispatch(); - - // useEffect(() => { - // if (joke !== "" && jokeFall !== "" && category !== "") { - // setButtonDisabled(false); - // } else { - // setButtonDisabled(true); - // } - // }, [joke, jokeFall, category]); - // const postjoke = async () => { - // // @ts-ignore - // await dispatch(postJoke(joke, jokeFall, category)); - // clearFields(); - // }; - // - // const clearFields = () => { - // setJoke(""); - // setJokeFall(""); - // setCategory(""); - // setCategoryExceeded(false); - // setButtonDisabled(true); - // }; - - // const handleCategoryChange = (text) => { - // if (text.length > MAX_CATEGORY_LENGTH) { - // setCategoryExceeded(true); - // } else { - // setCategoryExceeded(false); - // setCategory(text); - // } - // }; - return ( Blague diff --git a/src/screens/JokeDetailsScreen.tsx b/src/screens/JokeDetailsScreen.tsx index c1c518f..830d884 100644 --- a/src/screens/JokeDetailsScreen.tsx +++ b/src/screens/JokeDetailsScreen.tsx @@ -5,7 +5,6 @@ import {useDispatch, useSelector} from "react-redux"; import React, {useEffect, useState} from "react"; import {getCustomJokeById, getJokeById} from "../redux/thunk/GetByThunk"; import JokeDetail from "../components/JokeDetail"; -import {CustomJoke} from "../model/CustomJoke"; export default function JokeDetailsScreen({route}) { const idJokeDetail = route.params.idJoke; @@ -32,47 +31,7 @@ export default function JokeDetailsScreen({route}) { }; loadCustomJoke(); } - // const loadJoke = async () => { - // // @ts-ignore - // await dispatch(getJokeById(idJokeDetail)); - // }; - // const loadCustomJoke = async () => { - // // @ts-ignore - // await dispatch(getCustomJokeById(idJokeDetail)); - // }; - // loadCustomJoke(); - // loadJoke(); }, [dispatch]); - - // const loadCustomJoke = async () => { - // // @ts-ignore - // await dispatch(getCustomJokeById(idJokeDetail)); - // }; - - // // @ts-ignore - // const sampleJokes = useSelector(state => state.sampleReducer.jokes); - // // @ts-ignore - // const customJokes = useSelector(state => state.customReducer.customJoke); - // const dispatch = useDispatch(); - // - // useEffect(() => { - // const loadSamplesJokes = async () => { - // // @ts-ignore - // await dispatch(getSampleJokesList()); - // }; - // loadSamplesJokes(); - // }, [dispatch]); - // - // const loadCustomJokes = async () => { - // // @ts-ignore - // await dispatch(getCustomJokeById()); - // }; - // - // const [showCustomJoke, setCustomJoke] = useState(false); // état local pour contrôler la visibilité de la description - // const toggleDescription = () => { - // setCustomJoke(!showCustomJoke); - // loadCustomJokes(); - // }; return (