big refacto change all flows
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import FontAwesome from "@expo/vector-icons/FontAwesome";
|
||||
import { BlurView } from "expo-blur";
|
||||
import React, { useMemo } from "react";
|
||||
import React from "react";
|
||||
import { Image, Platform, Pressable, Text, View } from "react-native";
|
||||
import { ai, background } from "../assets";
|
||||
import Page from "../layouts/Page";
|
||||
@@ -42,69 +42,62 @@ const CREATE_DATA = [
|
||||
},
|
||||
];
|
||||
|
||||
const NewMusicOptions = ({ route }) => {
|
||||
const { userProjects } = useUserData();
|
||||
const { projectId = null } = route?.params || {};
|
||||
|
||||
const currentProjet = useMemo(() => {
|
||||
if (!projectId) {
|
||||
return null;
|
||||
}
|
||||
return userProjects?.find((p) => p.id === projectId) || null;
|
||||
}, [projectId, userProjects]);
|
||||
|
||||
const hasProject = !!currentProjet;
|
||||
const hasLyrics = Array.isArray(currentProjet?.lyrics)
|
||||
? currentProjet.lyrics.length > 0
|
||||
: !!currentProjet?.lyrics;
|
||||
const hasCover = !!currentProjet?.coverUrl;
|
||||
console.log("current projet cover", currentProjet?.coverUrl);
|
||||
const NewMusicOptions = () => {
|
||||
const { selectedProject } = useUserData();
|
||||
|
||||
// Lock rules per option index:
|
||||
// 0 (Songwriter): allowed if no project OR no songUrl
|
||||
// 1 (Beatmaker): allowed only if lyrics exist and no songUrl
|
||||
// 2 (Designer): allowed only if songUrl exists and no coverUrl
|
||||
// 3 (Director): allowed only if coverUrl exists
|
||||
const isLocked = (index) => {
|
||||
// 0: Songwriter, 1: Beatmaker, 2: Producer, 3: Director
|
||||
// Rules:
|
||||
// - If no project: only Songwriter (0) is available.
|
||||
// - If project exists: Songwriter (0) is always available.
|
||||
// - If lyrics exist: Beatmaker (1) becomes available.
|
||||
// - If cover exists: Producer (2) and Director (3) become available.
|
||||
if (!hasProject) return index !== 0;
|
||||
const songUrl = selectedProject?.songUrl || null;
|
||||
const coverUrl = selectedProject?.coverUrl || null;
|
||||
const playbackUrl = selectedProject?.songUrl || null;
|
||||
const lyricsLen = Array.isArray(selectedProject?.lyrics)
|
||||
? selectedProject.lyrics.length
|
||||
: 0;
|
||||
|
||||
const allowed = new Set([0]); // songwriter always allowed when project exists
|
||||
if (hasLyrics) {
|
||||
allowed.add(1);
|
||||
switch (index) {
|
||||
case 0: // Songwriter
|
||||
return !!songUrl; // locked if a song already exists
|
||||
case 1: // Beatmaker
|
||||
return !(lyricsLen > 0 && !songUrl);
|
||||
case 2: // Designer
|
||||
return !(!!songUrl && !!playbackUrl);
|
||||
case 3: // Director
|
||||
return !!!coverUrl;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
if (hasCover) {
|
||||
allowed.add(2);
|
||||
allowed.add(3);
|
||||
}
|
||||
|
||||
return !allowed.has(index);
|
||||
};
|
||||
|
||||
const onPressOption = (index, item) => {
|
||||
if (isLocked(index)) return;
|
||||
switch (index) {
|
||||
case 0:
|
||||
navigate(Routes.WritingLyrics, {
|
||||
projectId: currentProjet?.id || null,
|
||||
});
|
||||
if (selectedProject?.lyrics?.length) {
|
||||
navigate(Routes.Lyrics);
|
||||
} else {
|
||||
navigate(Routes.WritingLyrics);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (currentProjet?.musicStatus === "GENERATING") {
|
||||
navigate(Routes.GeneratingSong, { projectId: currentProjet.id });
|
||||
} else if (currentProjet?.musicStatus === "GENERATED") {
|
||||
navigate(Routes.SongReady, { projectId: currentProjet.id });
|
||||
if (selectedProject?.musicStatus === "GENERATING") {
|
||||
navigate(Routes.GeneratingSong);
|
||||
} else if (selectedProject?.musicStatus === "GENERATED") {
|
||||
navigate(Routes.SongReady);
|
||||
} else {
|
||||
navigate(Routes.Compose, { projectId: currentProjet.id });
|
||||
navigate(Routes.Compose);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
navigate(Routes.PouchReady, { projectId: currentProjet.id });
|
||||
navigate(Routes.ChooseCoverType);
|
||||
break;
|
||||
case 3:
|
||||
console.log("test");
|
||||
navigate(Routes.Playback, {
|
||||
project: currentProjet,
|
||||
project: selectedProject,
|
||||
});
|
||||
default:
|
||||
break;
|
||||
@@ -115,7 +108,7 @@ const NewMusicOptions = ({ route }) => {
|
||||
<Page
|
||||
backgroundImg={background.homeBG}
|
||||
headerType="NAVIGATION"
|
||||
title={!!currentProjet ? "Continuer la création" : "Nouvelle musique"}
|
||||
title={!!selectedProject ? "Continuer la création" : "Nouvelle musique"}
|
||||
scrollEnabled={true}
|
||||
>
|
||||
<View style={{ gap: 10 }}>
|
||||
|
||||
Reference in New Issue
Block a user