|
|
|
@ -2,26 +2,80 @@ import '../types/extension';
|
|
|
|
|
import {StyleSheet, View} from "react-native";
|
|
|
|
|
import {purpleColor} from "../assets/Theme";
|
|
|
|
|
import {useDispatch, useSelector} from "react-redux";
|
|
|
|
|
import React, {useEffect} from "react";
|
|
|
|
|
import { getJokeById } from "../redux/thunk/GetByThunk";
|
|
|
|
|
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;
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const joke = useSelector(state => state.sampleReducer.joke);
|
|
|
|
|
const joke = useSelector(state => state.sampleReducer.jokes);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const customJoke = useSelector(state => state.customReducer.customJoke);
|
|
|
|
|
const [isCustomJoke, setCustomJoke] = useState(false); // état local pour contrôler la visibilité de la description
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const loadJoke = async () => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
await dispatch(getJokeById(idJokeDetail));
|
|
|
|
|
};
|
|
|
|
|
loadJoke();
|
|
|
|
|
if(idJokeDetail instanceof Number) {
|
|
|
|
|
const loadJoke = async () => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
await dispatch(getJokeById(idJokeDetail));
|
|
|
|
|
};
|
|
|
|
|
loadJoke();
|
|
|
|
|
setCustomJoke(!isCustomJoke)
|
|
|
|
|
} else {
|
|
|
|
|
const loadCustomJoke = async () => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
await dispatch(getCustomJokeById(idJokeDetail));
|
|
|
|
|
};
|
|
|
|
|
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 (
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
<JokeDetail joke={joke}/>
|
|
|
|
|
<JokeDetail joke={isCustomJoke ? joke : customJoke}/>
|
|
|
|
|
</View>
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|