alerts web
This commit is contained in:
@@ -10,7 +10,6 @@ import useDataFromArrayDocId from "../../hooks/useDataFromArrayId";
|
|||||||
import useDataFromRef from "../../hooks/useDataFromRef";
|
import useDataFromRef from "../../hooks/useDataFromRef";
|
||||||
import useNavigateToMusicDetails from "../../hooks/useNavigateToMusicDetails";
|
import useNavigateToMusicDetails from "../../hooks/useNavigateToMusicDetails";
|
||||||
import Page from "../../layouts/Page";
|
import Page from "../../layouts/Page";
|
||||||
import { goBack } from "../../navigation/NavigationService";
|
|
||||||
import { useUser } from "../../providers/UserDataProvider";
|
import { useUser } from "../../providers/UserDataProvider";
|
||||||
import { gutters, Palette, Style } from "../../styles";
|
import { gutters, Palette, Style } from "../../styles";
|
||||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||||
@@ -62,8 +61,6 @@ const AllMyPlaylist = ({ route }) => {
|
|||||||
type: "error",
|
type: "error",
|
||||||
text: e?.message || "Suppression impossible",
|
text: e?.message || "Suppression impossible",
|
||||||
});
|
});
|
||||||
} finally {
|
|
||||||
goBack();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import React, { useCallback, useMemo, useRef, useState } from "react";
|
import React, { useCallback, useMemo, useRef, useState } from "react";
|
||||||
import { Alert, ScrollView, View } from "react-native";
|
import { Alert, ScrollView, View } from "react-native";
|
||||||
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
|
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
|
||||||
|
import { background } from "../../assets";
|
||||||
import BorderGradientButton from "../../components/BorderGradientButton";
|
import BorderGradientButton from "../../components/BorderGradientButton";
|
||||||
import GradientButton from "../../components/GradientButton";
|
import GradientButton from "../../components/GradientButton";
|
||||||
import ItemContainer from "../../components/ItemContainer/ItemContainer";
|
import ItemContainer from "../../components/ItemContainer/ItemContainer";
|
||||||
import MusicLandHeader from "../../components/MusicLandHeader";
|
import MusicLandHeader from "../../components/MusicLandHeader";
|
||||||
import firebase, { projectsRef } from "../../config/firebase";
|
import firebase, { projectsRef } from "../../config/firebase";
|
||||||
|
import { isWeb } from "../../hooks/useLayoutType";
|
||||||
import Page from "../../layouts/Page";
|
import Page from "../../layouts/Page";
|
||||||
import { Routes } from "../../navigation";
|
import { Routes } from "../../navigation";
|
||||||
import { navigate } from "../../navigation/NavigationService";
|
import { navigate } from "../../navigation/NavigationService";
|
||||||
import { useUser } from "../../providers/UserDataProvider";
|
import { useUser } from "../../providers/UserDataProvider";
|
||||||
import { gutters } from "../../styles";
|
import { gutters } from "../../styles";
|
||||||
import CustomInput from "./components/CustomInput";
|
import CustomInput from "./components/CustomInput";
|
||||||
import { background } from "../../assets";
|
|
||||||
import { isWeb } from "../../hooks/useLayoutType";
|
|
||||||
|
|
||||||
const Lyrics = ({ navigation }) => {
|
const Lyrics = ({ navigation }) => {
|
||||||
const scrollRef = useRef(null);
|
const scrollRef = useRef(null);
|
||||||
@@ -96,17 +96,53 @@ const Lyrics = ({ navigation }) => {
|
|||||||
return obj;
|
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 () => {
|
const onValidate = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
await setIsLoading(true);
|
await setIsLoading(true);
|
||||||
const titleTrimmed = (titleValue || "").trim();
|
const titleTrimmed = (titleValue || "").trim();
|
||||||
if (!titleTrimmed) {
|
if (!titleTrimmed) {
|
||||||
Alert.alert("Titre manquant", "Veuillez renseigner un titre.");
|
alertMessage("Titre manquant", "Veuillez renseigner un titre.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const invalid = (sections || []).some((s) => !(s?.lyrics || "").trim());
|
const invalid = (sections || []).some((s) => !(s?.lyrics || "").trim());
|
||||||
if (invalid) {
|
if (invalid) {
|
||||||
Alert.alert(
|
alertMessage(
|
||||||
"Champs incomplets",
|
"Champs incomplets",
|
||||||
"Chaque couplet et refrain doit contenir du texte."
|
"Chaque couplet et refrain doit contenir du texte."
|
||||||
);
|
);
|
||||||
@@ -151,7 +187,7 @@ const Lyrics = ({ navigation }) => {
|
|||||||
.map((e) => `• ${e.quote}`)
|
.map((e) => `• ${e.quote}`)
|
||||||
.join("\n")
|
.join("\n")
|
||||||
: null;
|
: null;
|
||||||
Alert.alert(
|
alertMessage(
|
||||||
"Contenu interdit",
|
"Contenu interdit",
|
||||||
[data?.message, quotes].filter(Boolean).join("\n\n")
|
[data?.message, quotes].filter(Boolean).join("\n\n")
|
||||||
);
|
);
|
||||||
@@ -159,7 +195,7 @@ const Lyrics = ({ navigation }) => {
|
|||||||
}
|
}
|
||||||
// Erreur d'analyse: informer et arrêter
|
// Erreur d'analyse: informer et arrêter
|
||||||
if (data?.errorCode === "ANALYSE_FAILED") {
|
if (data?.errorCode === "ANALYSE_FAILED") {
|
||||||
Alert.alert(
|
alertMessage(
|
||||||
"Analyse indisponible",
|
"Analyse indisponible",
|
||||||
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
|
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
|
||||||
);
|
);
|
||||||
@@ -177,20 +213,10 @@ const Lyrics = ({ navigation }) => {
|
|||||||
: null;
|
: null;
|
||||||
const msg = [data?.message, quotes].filter(Boolean).join("\n\n");
|
const msg = [data?.message, quotes].filter(Boolean).join("\n\n");
|
||||||
|
|
||||||
const proceed = await new Promise((resolve) => {
|
const proceed = await confirmSensitiveContent(
|
||||||
Alert.alert("Contenu potentiellement sensible", msg, [
|
"Contenu potentiellement sensible",
|
||||||
{
|
msg
|
||||||
text: "Annuler",
|
);
|
||||||
style: "cancel",
|
|
||||||
onPress: () => resolve(false),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: "Continuer",
|
|
||||||
style: "destructive",
|
|
||||||
onPress: () => resolve(true),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
if (!proceed) return;
|
if (!proceed) return;
|
||||||
}
|
}
|
||||||
} catch (moderationError) {
|
} catch (moderationError) {
|
||||||
@@ -198,7 +224,7 @@ const Lyrics = ({ navigation }) => {
|
|||||||
"Moderation call failed",
|
"Moderation call failed",
|
||||||
moderationError?.message || moderationError
|
moderationError?.message || moderationError
|
||||||
);
|
);
|
||||||
Alert.alert(
|
alertMessage(
|
||||||
"Analyse indisponible",
|
"Analyse indisponible",
|
||||||
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
|
"Impossible de vérifier la toxicité pour le moment. Réessayez plus tard."
|
||||||
);
|
);
|
||||||
@@ -225,7 +251,7 @@ const Lyrics = ({ navigation }) => {
|
|||||||
navigate(Routes.Home);
|
navigate(Routes.Home);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
Alert.alert("Erreur", "Échec de l'enregistrement dans le projet.");
|
alertMessage("Erreur", "Échec de l'enregistrement dans le projet.");
|
||||||
} finally {
|
} finally {
|
||||||
await setIsLoading(false);
|
await setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -234,6 +260,9 @@ const Lyrics = ({ navigation }) => {
|
|||||||
sections,
|
sections,
|
||||||
projectConfig,
|
projectConfig,
|
||||||
projectSelections,
|
projectSelections,
|
||||||
|
alertMessage,
|
||||||
|
confirmSensitiveContent,
|
||||||
|
sanitize,
|
||||||
setIsLoading,
|
setIsLoading,
|
||||||
selectedProjectId,
|
selectedProjectId,
|
||||||
projectHasLyrics,
|
projectHasLyrics,
|
||||||
|
|||||||
Reference in New Issue
Block a user