end of home
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { Routes } from "../navigation/Routes";
|
||||
|
||||
export const CREATION_STAGE_KEYS = [
|
||||
"songwriter",
|
||||
"beatmaker",
|
||||
"designer",
|
||||
"director",
|
||||
];
|
||||
|
||||
const getLyricsCount = (project) => {
|
||||
if (!project) return 0;
|
||||
const { lyrics } = project;
|
||||
return Array.isArray(lyrics) ? lyrics.length : 0;
|
||||
};
|
||||
|
||||
const getStageLockState = (key, project) => {
|
||||
const hasSong = !!project?.songUrl;
|
||||
const hasCover = !!project?.coverUrl;
|
||||
const hasPlayback = !!(project?.playbackUrl || project?.songUrl);
|
||||
const lyricsCount = getLyricsCount(project);
|
||||
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
return hasSong;
|
||||
case "beatmaker":
|
||||
return !(lyricsCount > 0 && !hasSong);
|
||||
case "designer":
|
||||
return !(hasSong && hasPlayback);
|
||||
case "director":
|
||||
return !hasCover;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
export const getCreationStageStates = (project) =>
|
||||
CREATION_STAGE_KEYS.map((key, index) => ({
|
||||
key,
|
||||
index,
|
||||
isLocked: getStageLockState(key, project),
|
||||
}));
|
||||
|
||||
export const getStageAction = (key, project) => {
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
return {
|
||||
route:
|
||||
getLyricsCount(project) > 0 ? Routes.Lyrics : Routes.WritingLyrics,
|
||||
};
|
||||
case "beatmaker":
|
||||
if (project?.musicStatus === "GENERATING") {
|
||||
return { route: Routes.GeneratingSong };
|
||||
}
|
||||
if (project?.musicStatus === "GENERATED") {
|
||||
return { route: Routes.SongReady };
|
||||
}
|
||||
return { route: Routes.Compose };
|
||||
case "designer":
|
||||
return {
|
||||
route: project?.coverUrl
|
||||
? Routes.ValidateCover
|
||||
: Routes.ChooseCoverType,
|
||||
};
|
||||
case "director":
|
||||
return {
|
||||
route: Routes.Playback,
|
||||
params: project ? { project } : undefined,
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export const findFirstUnlockedStageIndex = (project) => {
|
||||
const stages = getCreationStageStates(project);
|
||||
const index = stages.findIndex((stage) => !stage.isLocked);
|
||||
return index === -1 ? 0 : index;
|
||||
};
|
||||
Reference in New Issue
Block a user