feat: fixes and formatter
This commit is contained in:
+148
-174
@@ -1,70 +1,56 @@
|
||||
import { Routes } from "../navigation/Routes";
|
||||
import { Routes } from '../navigation/Routes'
|
||||
|
||||
export const CREATION_STAGE_KEYS = [
|
||||
"songwriter",
|
||||
"beatmaker",
|
||||
"director",
|
||||
"publisher",
|
||||
];
|
||||
export const CREATION_STAGE_KEYS = ['songwriter', 'beatmaker', 'director', 'publisher']
|
||||
|
||||
const getSectionLyrics = (section) => {
|
||||
if (typeof section === "string") {
|
||||
return section.trim();
|
||||
if (typeof section === 'string') {
|
||||
return section.trim()
|
||||
}
|
||||
if (section && typeof section === "object") {
|
||||
const value =
|
||||
typeof section.lyrics === "string" ? section.lyrics.trim() : "";
|
||||
return value;
|
||||
if (section && typeof section === 'object') {
|
||||
const value = typeof section.lyrics === 'string' ? section.lyrics.trim() : ''
|
||||
return value
|
||||
}
|
||||
return "";
|
||||
};
|
||||
return ''
|
||||
}
|
||||
|
||||
const getLyricsCount = (project) => {
|
||||
if (!project) return 0;
|
||||
const { lyrics } = project;
|
||||
if (!project) return 0
|
||||
const { lyrics } = project
|
||||
if (Array.isArray(lyrics)) {
|
||||
return lyrics.reduce(
|
||||
(count, section) => (getSectionLyrics(section) ? count + 1 : count),
|
||||
0,
|
||||
);
|
||||
return lyrics.reduce((count, section) => (getSectionLyrics(section) ? count + 1 : count), 0)
|
||||
}
|
||||
if (lyrics && typeof lyrics === "object") {
|
||||
if (lyrics && typeof lyrics === 'object') {
|
||||
return Object.values(lyrics).reduce(
|
||||
(count, value) => (getSectionLyrics(value) ? count + 1 : count),
|
||||
0,
|
||||
);
|
||||
0
|
||||
)
|
||||
}
|
||||
return getSectionLyrics(lyrics) ? 1 : 0;
|
||||
};
|
||||
return getSectionLyrics(lyrics) ? 1 : 0
|
||||
}
|
||||
|
||||
const getStageMetadata = (project) => {
|
||||
const lyricsCount = getLyricsCount(project);
|
||||
const hasLyrics = !!(project?.hasLyrics || lyricsCount > 0);
|
||||
const hasSongUrl = !!project?.songUrl;
|
||||
const cover = project?.cover || {};
|
||||
const hasCoverUrl = !!project?.coverUrl;
|
||||
const hasPlaybackAsset = !!project?.playbackUrl;
|
||||
const hasPlayback = hasPlaybackAsset || hasSongUrl;
|
||||
const youtubeUrl = project?.youtubeUrl ?? null;
|
||||
const youtubeStatus = project?.youtubeStatus ?? null;
|
||||
const youtubeError = project?.youtubeError ?? null;
|
||||
const hasYoutubePublication = !!youtubeUrl;
|
||||
const isYoutubePublishing = [
|
||||
"PUBLISHING",
|
||||
"UPLOADING",
|
||||
"PROCESSING",
|
||||
"QUEUED",
|
||||
].includes(youtubeStatus);
|
||||
const musicUrls = Array.isArray(project?.musicUrls)
|
||||
? project.musicUrls.filter(Boolean)
|
||||
: [];
|
||||
const musicStatus = project?.musicStatus || null;
|
||||
const coverStatus = project?.coverStatus || null;
|
||||
const playbackStatus = project?.playbackStatus || null;
|
||||
const lyricsCount = getLyricsCount(project)
|
||||
const hasLyrics = !!(project?.hasLyrics || lyricsCount > 0)
|
||||
const hasSongUrl = !!project?.songUrl
|
||||
const cover = project?.cover || {}
|
||||
const hasCoverUrl = !!project?.coverUrl
|
||||
const hasPlaybackAsset = !!project?.playbackUrl
|
||||
const hasPlayback = hasPlaybackAsset || hasSongUrl
|
||||
const youtubeUrl = project?.youtubeUrl ?? null
|
||||
const youtubeStatus = project?.youtubeStatus ?? null
|
||||
const youtubeError = project?.youtubeError ?? null
|
||||
const hasYoutubePublication = !!youtubeUrl
|
||||
const isYoutubePublishing = ['PUBLISHING', 'UPLOADING', 'PROCESSING', 'QUEUED'].includes(
|
||||
youtubeStatus
|
||||
)
|
||||
const musicUrls = Array.isArray(project?.musicUrls) ? project.musicUrls.filter(Boolean) : []
|
||||
const musicStatus = project?.musicStatus || null
|
||||
const coverStatus = project?.coverStatus || null
|
||||
const playbackStatus = project?.playbackStatus || null
|
||||
const isPlaybackGenerating =
|
||||
project?.playbackGenerating === true ||
|
||||
project?.isPlaybackGenerating === true ||
|
||||
playbackStatus === "GENERATING";
|
||||
playbackStatus === 'GENERATING'
|
||||
|
||||
return {
|
||||
lyricsCount,
|
||||
@@ -79,34 +65,34 @@ const getStageMetadata = (project) => {
|
||||
playbackStatus,
|
||||
youtubeStatus,
|
||||
youtubeError,
|
||||
isMusicGenerating: musicStatus === "GENERATING",
|
||||
isCoverGenerating: coverStatus === "GENERATING",
|
||||
isMusicGenerating: musicStatus === 'GENERATING',
|
||||
isCoverGenerating: coverStatus === 'GENERATING',
|
||||
isPlaybackGenerating,
|
||||
hasYoutubePublication,
|
||||
isYoutubePublishing,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const getStageLockState = (key, metadata) => {
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
return metadata.hasSongUrl;
|
||||
case "beatmaker":
|
||||
case 'songwriter':
|
||||
return metadata.hasSongUrl
|
||||
case 'beatmaker':
|
||||
if (metadata.hasCover) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return metadata.lyricsCount <= 0;
|
||||
case "director":
|
||||
return metadata.lyricsCount <= 0
|
||||
case 'director':
|
||||
if (metadata.hasPlaybackAsset) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return !metadata.hasCover;
|
||||
case "publisher":
|
||||
return !metadata.hasPlaybackAsset;
|
||||
return !metadata.hasCover
|
||||
case 'publisher':
|
||||
return !metadata.hasPlaybackAsset
|
||||
default:
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const getStageDescription = (key, metadata) => {
|
||||
const {
|
||||
@@ -117,220 +103,208 @@ const getStageDescription = (key, metadata) => {
|
||||
hasMusicDraft,
|
||||
isMusicGenerating,
|
||||
isPlaybackGenerating,
|
||||
} = metadata;
|
||||
} = metadata
|
||||
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
case 'songwriter':
|
||||
if (!hasLyrics) {
|
||||
return "Commencer à créer des paroles pour votre chanson";
|
||||
return 'Commencer à créer des paroles pour votre chanson'
|
||||
}
|
||||
if (!hasSongUrl) {
|
||||
return "Continuer la création de paroles";
|
||||
return 'Continuer la création de paroles'
|
||||
}
|
||||
return "Modifier les paroles créées";
|
||||
case "beatmaker":
|
||||
return 'Modifier les paroles créées'
|
||||
case 'beatmaker':
|
||||
if (metadata.hasCover) {
|
||||
return "Impossible de modifier la cover ou la production musicale";
|
||||
return 'Impossible de modifier la cover ou la production musicale'
|
||||
}
|
||||
if (!hasLyrics) {
|
||||
return "Écrivez vos paroles pour débloquer la musique";
|
||||
return 'Écrivez vos paroles pour débloquer la musique'
|
||||
}
|
||||
if (isMusicGenerating) {
|
||||
return "Votre morceau est en cours de création";
|
||||
return 'Votre morceau est en cours de création'
|
||||
}
|
||||
if (hasSongUrl) {
|
||||
if (!hasCover) {
|
||||
return "Créer ou modifier la cover de votre morceau";
|
||||
return 'Créer ou modifier la cover de votre morceau'
|
||||
}
|
||||
return "Modifier la cover ou la production musicale";
|
||||
return 'Modifier la cover ou la production musicale'
|
||||
}
|
||||
if (hasMusicDraft) {
|
||||
return "Modifier la production musicale";
|
||||
return 'Modifier la production musicale'
|
||||
}
|
||||
return "Commencer la création de votre morceau";
|
||||
case "director":
|
||||
return 'Commencer la création de votre morceau'
|
||||
case 'director':
|
||||
if (!hasCover) {
|
||||
return "Générez une cover pour débloquer le playback";
|
||||
return 'Générez une cover pour débloquer le playback'
|
||||
}
|
||||
if (isPlaybackGenerating) {
|
||||
return "Votre playback est en cours de préparation";
|
||||
return 'Votre playback est en cours de préparation'
|
||||
}
|
||||
if (hasPlaybackAsset) {
|
||||
return "Modifier le playback généré";
|
||||
return 'Modifier le playback généré'
|
||||
}
|
||||
return "Commencer la création de votre playback";
|
||||
case "publisher":
|
||||
return 'Commencer la création de votre playback'
|
||||
case 'publisher':
|
||||
if (!hasPlaybackAsset) {
|
||||
return "Créez un playback pour débloquer la publication";
|
||||
return 'Créez un playback pour débloquer la publication'
|
||||
}
|
||||
if (metadata.isYoutubePublishing) {
|
||||
return "Publication de votre vidéo en cours";
|
||||
return 'Publication de votre vidéo en cours'
|
||||
}
|
||||
if (metadata.youtubeError) {
|
||||
return "La publication a échoué, réessayez.";
|
||||
return 'La publication a échoué, réessayez.'
|
||||
}
|
||||
if (metadata.hasYoutubePublication) {
|
||||
return "Votre vidéo est en ligne et prête à être partagée";
|
||||
return 'Votre vidéo est en ligne et prête à être partagée'
|
||||
}
|
||||
return "Publier votre vidéo sur la chaîne YouTube MusicLand";
|
||||
return 'Publier votre vidéo sur la chaîne YouTube MusicLand'
|
||||
default:
|
||||
return "";
|
||||
return ''
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const getStageLockedDescription = (key, metadata) => {
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
return metadata.hasSongUrl
|
||||
? "Impossible de modifier les paroles"
|
||||
: undefined;
|
||||
case "beatmaker":
|
||||
case 'songwriter':
|
||||
return metadata.hasSongUrl ? 'Impossible de modifier les paroles' : undefined
|
||||
case 'beatmaker':
|
||||
if (metadata.hasCover) {
|
||||
return "Impossible de modifier la cover ou la production musicale";
|
||||
return 'Impossible de modifier la cover ou la production musicale'
|
||||
}
|
||||
return metadata.lyricsCount > 0
|
||||
? undefined
|
||||
: "Créez vos paroles pour débloquer le studio";
|
||||
case "director":
|
||||
return metadata.hasPlaybackAsset
|
||||
? "Impossible de modifier le playback"
|
||||
: undefined;
|
||||
case "publisher":
|
||||
return metadata.lyricsCount > 0 ? undefined : 'Créez vos paroles pour débloquer le studio'
|
||||
case 'director':
|
||||
return metadata.hasPlaybackAsset ? 'Impossible de modifier le playback' : undefined
|
||||
case 'publisher':
|
||||
if (!metadata.hasPlaybackAsset) {
|
||||
return "Générez un playback pour débloquer la publication";
|
||||
return 'Générez un playback pour débloquer la publication'
|
||||
}
|
||||
return metadata.hasYoutubePublication
|
||||
? "La vidéo est déjà publiée"
|
||||
: undefined;
|
||||
return metadata.hasYoutubePublication ? 'La vidéo est déjà publiée' : undefined
|
||||
default:
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const getStageCompletionState = (key, metadata) => {
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
return metadata.hasLyrics;
|
||||
case "beatmaker":
|
||||
return metadata.hasSongUrl || metadata.musicStatus === "GENERATED";
|
||||
case "director":
|
||||
return metadata.hasPlaybackAsset;
|
||||
case "publisher":
|
||||
return metadata.hasYoutubePublication;
|
||||
case 'songwriter':
|
||||
return metadata.hasLyrics
|
||||
case 'beatmaker':
|
||||
return metadata.hasSongUrl || metadata.musicStatus === 'GENERATED'
|
||||
case 'director':
|
||||
return metadata.hasPlaybackAsset
|
||||
case 'publisher':
|
||||
return metadata.hasYoutubePublication
|
||||
default:
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const getCreationStageStates = (project) => {
|
||||
const metadata = getStageMetadata(project);
|
||||
const metadata = getStageMetadata(project)
|
||||
return CREATION_STAGE_KEYS.map((key, index) => {
|
||||
const isLocked = getStageLockState(key, metadata);
|
||||
const description = getStageDescription(key, metadata);
|
||||
const lockedDescription = getStageLockedDescription(key, metadata);
|
||||
const isLocked = getStageLockState(key, metadata)
|
||||
const description = getStageDescription(key, metadata)
|
||||
const lockedDescription = getStageLockedDescription(key, metadata)
|
||||
|
||||
return {
|
||||
key,
|
||||
index,
|
||||
isLocked,
|
||||
isCompleted: getStageCompletionState(key, metadata),
|
||||
description:
|
||||
isLocked && lockedDescription ? lockedDescription : description,
|
||||
description: isLocked && lockedDescription ? lockedDescription : description,
|
||||
lockedDescription,
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const getStageAction = (key, project) => {
|
||||
switch (key) {
|
||||
case "songwriter":
|
||||
case 'songwriter':
|
||||
return {
|
||||
route:
|
||||
getLyricsCount(project) > 0 ? Routes.Lyrics : Routes.WritingLyrics,
|
||||
};
|
||||
case "beatmaker": {
|
||||
route: getLyricsCount(project) > 0 ? Routes.Lyrics : Routes.WritingLyrics,
|
||||
}
|
||||
case 'beatmaker': {
|
||||
if (!project) {
|
||||
return { route: Routes.Compose };
|
||||
return { route: Routes.Compose }
|
||||
}
|
||||
|
||||
const musicStatus = project?.musicStatus || null;
|
||||
const songUrl = project?.songUrl || null;
|
||||
const coverStatus = project?.coverStatus || null;
|
||||
const cover = project?.cover || {};
|
||||
const hasCoverBackground = !!cover?.generatedBackground;
|
||||
const hasCoverResult = !!cover?.result;
|
||||
const hasFinalCover = !!project?.coverUrl;
|
||||
const musicStatus = project?.musicStatus || null
|
||||
const songUrl = project?.songUrl || null
|
||||
const coverStatus = project?.coverStatus || null
|
||||
const cover = project?.cover || {}
|
||||
const hasCoverBackground = !!cover?.generatedBackground
|
||||
const hasCoverResult = !!cover?.result
|
||||
const hasFinalCover = !!project?.coverUrl
|
||||
|
||||
if (musicStatus === "GENERATING") {
|
||||
return { route: Routes.GeneratingSong };
|
||||
if (musicStatus === 'GENERATING') {
|
||||
return { route: Routes.GeneratingSong }
|
||||
}
|
||||
|
||||
if (!songUrl) {
|
||||
if (musicStatus === "GENERATED") {
|
||||
return { route: Routes.SongReady };
|
||||
if (musicStatus === 'GENERATED') {
|
||||
return { route: Routes.SongReady }
|
||||
}
|
||||
return { route: Routes.Compose };
|
||||
return { route: Routes.Compose }
|
||||
}
|
||||
|
||||
if (coverStatus === "GENERATING") {
|
||||
return { route: Routes.PouchReady };
|
||||
if (coverStatus === 'GENERATING') {
|
||||
return { route: Routes.PouchReady }
|
||||
}
|
||||
|
||||
if (!hasCoverBackground) {
|
||||
return { route: Routes.ChooseCoverType };
|
||||
return { route: Routes.ChooseCoverType }
|
||||
}
|
||||
|
||||
if (!hasCoverResult) {
|
||||
return { route: Routes.PouchReady };
|
||||
return { route: Routes.PouchReady }
|
||||
}
|
||||
|
||||
if (!hasFinalCover) {
|
||||
return { route: Routes.ValidateCover };
|
||||
return { route: Routes.ValidateCover }
|
||||
}
|
||||
|
||||
return { route: Routes.ChooseCoverType };
|
||||
return { route: Routes.ChooseCoverType }
|
||||
}
|
||||
case "director":
|
||||
case 'director':
|
||||
return {
|
||||
route: Routes.Playback,
|
||||
params: project ? { project } : undefined,
|
||||
};
|
||||
case "publisher": {
|
||||
}
|
||||
case 'publisher': {
|
||||
if (!project?.id) {
|
||||
return { route: Routes.PublishYoutube };
|
||||
return { route: Routes.PublishYoutube }
|
||||
}
|
||||
return {
|
||||
route: Routes.PublishYoutube,
|
||||
params: { projectId: project.id },
|
||||
};
|
||||
}
|
||||
}
|
||||
default:
|
||||
return {};
|
||||
return {}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const findFirstUnlockedStageIndex = (project) => {
|
||||
const stages = getCreationStageStates(project);
|
||||
const stages = getCreationStageStates(project)
|
||||
if (!stages.length) {
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
|
||||
const actionableIndex = stages.findIndex(
|
||||
(stage) => !stage.isCompleted && !stage.isLocked
|
||||
);
|
||||
const actionableIndex = stages.findIndex((stage) => !stage.isCompleted && !stage.isLocked)
|
||||
if (actionableIndex !== -1) {
|
||||
return actionableIndex;
|
||||
return actionableIndex
|
||||
}
|
||||
|
||||
const firstIncomplete = stages.findIndex((stage) => !stage.isCompleted);
|
||||
const firstIncomplete = stages.findIndex((stage) => !stage.isCompleted)
|
||||
if (firstIncomplete !== -1) {
|
||||
return firstIncomplete;
|
||||
return firstIncomplete
|
||||
}
|
||||
|
||||
const firstUnlocked = stages.findIndex((stage) => !stage.isLocked);
|
||||
const firstUnlocked = stages.findIndex((stage) => !stage.isLocked)
|
||||
if (firstUnlocked !== -1) {
|
||||
return firstUnlocked;
|
||||
return firstUnlocked
|
||||
}
|
||||
|
||||
return stages.length - 1;
|
||||
};
|
||||
return stages.length - 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user