Skip to content

Commit 150fdf3

Browse files
committed
fix(ReelGallery): Ajout de vérifications de sécurité pour les images et les reels valides
1 parent e398642 commit 150fdf3

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/components/Settings/ReelGallery.tsx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useCallback, useState } from "react";
22
import {
33
ScrollView,
44
View,
@@ -36,6 +36,26 @@ const SubjectBadge = ({ emoji, color }: { emoji: string; color: string }) => (
3636
const ReelThumbnail = ({ reel, onPress, width }: { reel: Reel; onPress: () => void; width: number }) => {
3737
const { colors } = useTheme();
3838

39+
// Vérification de sécurité pour l'image
40+
const imageSource = reel.imagewithouteffect
41+
? { uri: `data:image/jpeg;base64,${reel.imagewithouteffect}` }
42+
: null; // Vous pouvez aussi mettre une image par défaut ici
43+
44+
if (!imageSource) {
45+
return (
46+
<View style={[styles.item, {
47+
backgroundColor: colors.card,
48+
width: width,
49+
height: width * 1.5,
50+
margin: 4,
51+
justifyContent: "center",
52+
alignItems: "center"
53+
}]}>
54+
<Text style={{color: colors.text}}>Image non disponible</Text>
55+
</View>
56+
);
57+
}
58+
3959
return (
4060
<TouchableOpacity
4161
style={[
@@ -50,9 +70,10 @@ const ReelThumbnail = ({ reel, onPress, width }: { reel: Reel; onPress: () => vo
5070
onPress={onPress}
5171
>
5272
<Image
53-
source={{ uri: `data:image/jpeg;base64,${reel.imagewithouteffect}` }}
73+
source={imageSource}
5474
style={styles.thumbnail}
5575
resizeMode="cover"
76+
defaultSource={require("@/../assets/images/service_unknown.png")} // Ajoutez une image par défaut
5677
/>
5778
<View style={[styles.infoContainer, { backgroundColor: colors.card }]}>
5879
<SubjectBadge
@@ -73,29 +94,38 @@ interface ReelGalleryProps {
7394
reels: Reel[];
7495
}
7596

97+
// Sécurisation du composant principal
7698
const ReelGallery = ({ reels }: ReelGalleryProps) => {
7799
const [selectedReel, setSelectedReel] = useState<Reel | null>(null);
78100
const windowWidth = Dimensions.get("window").width;
79101
const padding = 40;
80102
const gap = 8;
81103
const numColumns = 2;
82104

105+
// Vérification des reels valides
106+
const validReels = reels.filter(reel =>
107+
reel &&
108+
typeof reel.id === "string" &&
109+
reel.grade &&
110+
reel.subjectdata
111+
);
112+
83113
const itemWidth = (Math.min(500, windowWidth) - (padding * 2) - (gap * (numColumns - 1))) / numColumns;
84114

85-
const deleteReel = (reelId: string) => {
115+
const deleteReel = useCallback((reelId: string) => {
86116
useGradesStore.setState((store) => {
87117
const updatedReels = { ...store.reels };
88118
delete updatedReels[reelId];
89119
return { reels: updatedReels };
90120
});
91121
setSelectedReel(null);
92-
};
122+
}, []);
93123

94124
return (
95125
<ScrollView showsVerticalScrollIndicator={false}>
96126
<View style={styles.container}>
97127
<View style={[styles.galleryContent, { gap }]}>
98-
{reels.map((reel) => (
128+
{validReels.map((reel) => (
99129
<ReelThumbnail
100130
key={reel.id}
101131
reel={reel}
@@ -109,9 +139,9 @@ const ReelGallery = ({ reels }: ReelGalleryProps) => {
109139
{selectedReel && (
110140
<GradeModal
111141
isVisible={!!selectedReel}
112-
imageBase64={selectedReel.image}
142+
imageBase64={selectedReel.image || ""}
113143
onClose={() => setSelectedReel(null)}
114-
DeleteGrade={() => deleteReel(selectedReel.id)}
144+
DeleteGrade={() => selectedReel.id && deleteReel(selectedReel.id)}
115145
/>
116146
)}
117147
</ScrollView>

0 commit comments

Comments
 (0)