alerts web

This commit is contained in:
2025-10-03 16:46:52 +02:00
parent da5e648158
commit abf5ade2f9
2 changed files with 51 additions and 25 deletions
+51 -22
View File
@@ -1,19 +1,19 @@
import React, { useCallback, useMemo, useRef, useState } from "react";
import { Alert, ScrollView, View } from "react-native";
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
import { background } from "../../assets";
import BorderGradientButton from "../../components/BorderGradientButton";
import GradientButton from "../../components/GradientButton";
import ItemContainer from "../../components/ItemContainer/ItemContainer";
import MusicLandHeader from "../../components/MusicLandHeader";
import firebase, { projectsRef } from "../../config/firebase";
import { isWeb } from "../../hooks/useLayoutType";
import Page from "../../layouts/Page";
import { Routes } from "../../navigation";
import { navigate } from "../../navigation/NavigationService";
import { useUser } from "../../providers/UserDataProvider";
import { gutters } from "../../styles";
import CustomInput from "./components/CustomInput";
import { background } from "../../assets";
import { isWeb } from "../../hooks/useLayoutType";
const Lyrics = ({ navigation }) => {
const scrollRef = useRef(null);
@@ -96,17 +96,53 @@ const Lyrics = ({ navigation }) => {
return obj;
};
const alertMessage = useCallback(
(title, message) => {
const text = [title, message].filter(Boolean).join("\n\n");
if (isWeb && typeof window !== "undefined") {
window.alert(text);
return;
}
Alert.alert(title, message);
},
[isWeb]
);
const confirmSensitiveContent = useCallback(
async (title, message) => {
const text = [title, message].filter(Boolean).join("\n\n");
if (isWeb && typeof window !== "undefined") {
return window.confirm(text);
}
return new Promise((resolve) => {
Alert.alert(title, message, [
{
text: "Annuler",
style: "cancel",
onPress: () => resolve(false),
},
{
text: "Continuer",
style: "destructive",
onPress: () => resolve(true),
},
]);
});
},
[isWeb]
);
const onValidate = useCallback(async () => {
try {
await setIsLoading(true);
const titleTrimmed = (titleValue || "").trim();
if (!titleTrimmed) {
Alert.alert("Titre manquant", "Veuillez renseigner un titre.");
alertMessage("Titre manquant", "Veuillez renseigner un titre.");
return;
}
const invalid = (sections || []).some((s) => !(s?.lyrics || "").trim());
if (invalid) {
Alert.alert(
alertMessage(
"Champs incomplets",
"Chaque couplet et refrain doit contenir du texte."
);
@@ -151,7 +187,7 @@ const Lyrics = ({ navigation }) => {
.map((e) => `${e.quote}`)
.join("\n")
: null;
Alert.alert(
alertMessage(
"Contenu interdit",
[data?.message, quotes].filter(Boolean).join("\n\n")
);
@@ -159,7 +195,7 @@ const Lyrics = ({ navigation }) => {
}
// Erreur d'analyse: informer et arrêter
if (data?.errorCode === "ANALYSE_FAILED") {
Alert.alert(
alertMessage(
"Analyse indisponible",
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
);
@@ -177,20 +213,10 @@ const Lyrics = ({ navigation }) => {
: null;
const msg = [data?.message, quotes].filter(Boolean).join("\n\n");
const proceed = await new Promise((resolve) => {
Alert.alert("Contenu potentiellement sensible", msg, [
{
text: "Annuler",
style: "cancel",
onPress: () => resolve(false),
},
{
text: "Continuer",
style: "destructive",
onPress: () => resolve(true),
},
]);
});
const proceed = await confirmSensitiveContent(
"Contenu potentiellement sensible",
msg
);
if (!proceed) return;
}
} catch (moderationError) {
@@ -198,7 +224,7 @@ const Lyrics = ({ navigation }) => {
"Moderation call failed",
moderationError?.message || moderationError
);
Alert.alert(
alertMessage(
"Analyse indisponible",
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
);
@@ -225,7 +251,7 @@ const Lyrics = ({ navigation }) => {
navigate(Routes.Home);
} catch (e) {
console.log(e);
Alert.alert("Erreur", "Échec de l'enregistrement dans le projet.");
alertMessage("Erreur", "Échec de l'enregistrement dans le projet.");
} finally {
await setIsLoading(false);
}
@@ -234,6 +260,9 @@ const Lyrics = ({ navigation }) => {
sections,
projectConfig,
projectSelections,
alertMessage,
confirmSensitiveContent,
sanitize,
setIsLoading,
selectedProjectId,
projectHasLyrics,