From dba5b511ae79943210ec7a88be7e6aaaa1bac82c Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 14 Dec 2024 11:55:11 +0100 Subject: [PATCH] =?UTF-8?q?Affichage=20de=20la=20liste=20des=20d=C3=A9fis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/app/(tabs)/_layout.tsx | 2 +- client/app/(tabs)/challenges.tsx | 9 +- client/app/_layout.tsx | 1 + client/app/challenges-list.tsx | 151 ++++++++++++++++++++++++++++ client/components/ChallengeCard.tsx | 17 ++-- 5 files changed, 168 insertions(+), 12 deletions(-) create mode 100644 client/app/challenges-list.tsx diff --git a/client/app/(tabs)/_layout.tsx b/client/app/(tabs)/_layout.tsx index 2df0456..f2cefac 100644 --- a/client/app/(tabs)/_layout.tsx +++ b/client/app/(tabs)/_layout.tsx @@ -25,7 +25,7 @@ export default function TabLayout() { , }} diff --git a/client/app/(tabs)/challenges.tsx b/client/app/(tabs)/challenges.tsx index 413f28d..543fad9 100644 --- a/client/app/(tabs)/challenges.tsx +++ b/client/app/(tabs)/challenges.tsx @@ -7,15 +7,17 @@ import { useChallenges } from '@/hooks/useChallenges' import { useGame } from '@/hooks/useGame' import { FontAwesome6 } from '@expo/vector-icons' import { useQueryClient } from '@tanstack/react-query' +import { useRouter } from 'expo-router' import { useEffect, useMemo, useState } from 'react' import { View } from 'react-native' import { ActivityIndicator, Appbar, Banner, FAB, MD3Colors, Snackbar, Surface, Text, TouchableRipple } from 'react-native-paper' function ChallengeScreenHeader() { + const router = useRouter() return <> - - + + router.navigate('/challenges-list')} /> @@ -85,7 +87,8 @@ function ChallengeScreenBody() { { setLoading(true); endChallenge.mutate({ success: true }) }} - onFail={() => endChallenge.mutate({ success: false })} />} + onFail={() => endChallenge.mutate({ success: false })} + style={{ flex: 1, margin: 20 }} />} {!loading && !game.penaltyEnd && !currentChallenge && game.currentRunner && <> + diff --git a/client/app/challenges-list.tsx b/client/app/challenges-list.tsx new file mode 100644 index 0000000..1ba2afa --- /dev/null +++ b/client/app/challenges-list.tsx @@ -0,0 +1,151 @@ +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, + } +}) diff --git a/client/components/ChallengeCard.tsx b/client/components/ChallengeCard.tsx index 6d951be..7ee8af2 100644 --- a/client/components/ChallengeCard.tsx +++ b/client/components/ChallengeCard.tsx @@ -1,29 +1,30 @@ import { Challenge } from "@/utils/features/challenges/challengesSlice" import { FontAwesome6 } from "@expo/vector-icons" -import { View } from "react-native" +import { View, ViewStyle } from "react-native" import { Button, Card, IconButton, MD3Colors, Surface, Text } from "react-native-paper" export type ChallengeCardProps = { - challenge: Challenge, + challenge: Challenge | null, onSuccess?: () => void, onFail?: () => void, onDelete?: () => void, onEdit?: () => void, + style?: ViewStyle, } -export default function ChallengeCard({ challenge, onSuccess, onFail, onDelete, onEdit }: ChallengeCardProps) { +export default function ChallengeCard({ challenge, onSuccess, onFail, onDelete, onEdit, style }: ChallengeCardProps) { return ( - + onEdit ? onEdit()} /> : <>} /> - {challenge.description} + {challenge?.description} - Récompense : {challenge.reward} + Récompense : {challenge?.reward} @@ -34,7 +35,7 @@ export default function ChallengeCard({ challenge, onSuccess, onFail, onDelete, {onSuccess && } - {onDelete && }