import ChallengeCard from "@/components/ChallengeCard" import { useChallenges } from "@/hooks/useChallenges" import { Challenge } from "@/utils/features/challenges/challengesSlice" import { FontAwesome6 } from "@expo/vector-icons" import { useRouter } from "expo-router" import { useState } from "react" import { FlatList, StyleSheet } from "react-native" import { Appbar, Button, Dialog, Divider, FAB, List, MD3Colors, Modal, Portal, Snackbar, Surface, Text, TextInput } from "react-native-paper" export default function ChallengesList() { const router = useRouter() const challenges = useChallenges() const [editChallengeVisible, setEditChallengeVisible] = useState(false) const [editChallengeTitle, setEditChallengeTitle] = useState("") const [editChallengeDescription, setEditChallengeDescription] = useState("") const [editChallengeReward, setEditChallengeReward] = useState(0) const [editChallengeId, setEditChallengeId] = useState(null) const [displayedChallenge, setDisplayedChallenge] = useState(null) const [confirmDeletedVisible, setConfirmDeleteVisible] = useState(false) const [successSnackbarVisible, setSuccessSnackbarVisible] = useState(false) const [successMessage, setSuccessMessage] = useState("") const [errorVisible, setErrorVisible] = useState(false) const [error, setError] = useState([200, ""]) return ( {router.canGoBack() ? router.back()} /> : undefined} `challenge-list-item-${challenge.id}`} ItemSeparatorComponent={() => } renderItem={(item) => setDisplayedChallenge(item.item)} />} /> setSuccessSnackbarVisible(false)} onIconPress={() => setSuccessSnackbarVisible(false)}> {successMessage} setErrorVisible(false)} onIconPress={() => setErrorVisible(false)}> Erreur {error[0]} : {error[1]} { if (editChallengeId) { setEditChallengeTitle("") setEditChallengeDescription("") setEditChallengeReward(0) setEditChallengeId(null) } setEditChallengeVisible(true) }} /> setDisplayedChallenge(null)} contentContainerStyle={{ flex: 1, marginHorizontal: 20, marginVertical: 100 }}> { setEditChallengeTitle(displayedChallenge?.title ?? "") setEditChallengeDescription(displayedChallenge?.description ?? "") setEditChallengeReward(displayedChallenge?.reward ?? 0) setEditChallengeId(displayedChallenge?.id ?? null) setEditChallengeVisible(true) }} onDelete={() => setConfirmDeleteVisible(true)} style={{ flexGrow: 1 }} /> setEditChallengeVisible(false)}> {editChallengeId ? "Modification d'un défi" : "Ajout d'un défi"} setEditChallengeReward(+text)} error={!editChallengeReward} onEndEditing={() => { }} /> setConfirmDeleteVisible(false)}> Êtes-vous sûre ? Voulez-vous vraiment supprimer le défi « {displayedChallenge?.title} » ? Cette opération est irréversible ! ) } function ChallengeListItem({ challenge, onPress }: { challenge: Challenge, onPress?: () => void }) { const description = Récompense : {challenge.reward} return ( ) } const styles = StyleSheet.create({ addButton: { position: 'absolute', right: 25, bottom: 25, } })