selected project slide and create

This commit is contained in:
Thomas Demirdjian
2025-10-01 11:12:59 +02:00
parent 167e62fcfc
commit 75375942b7
4 changed files with 105 additions and 39 deletions
+37 -12
View File
@@ -15,6 +15,7 @@ import ShareBtn from "../../components/ShareBtn/ShareBtn";
import {
getCreationStageStates,
getStageAction,
findFirstUnlockedStageIndex,
} from "../../utils/projectStages";
const Home = () => {
@@ -33,6 +34,9 @@ const Home = () => {
const currentProject = useMemo(() => {
if (!projects.length) return null;
if (selectedProjectId === null) {
return null;
}
const activeId = selectedProject?.id || selectedProjectId;
if (!activeId) {
return projects[0];
@@ -59,16 +63,13 @@ const Home = () => {
const handleSelectProject = (project) => {
if (!project?.id) return;
selectProject(project.id);
setActiveStageIndex(findFirstUnlockedStageIndex(project));
};
const handleModifyProject = (project) => {
if (!project?.id) return;
selectProject(project.id);
navigate(Routes.FlowSelection);
};
const handleCreateNew = () => {
resetSelectedProject();
setActiveStageIndex(findFirstUnlockedStageIndex(project));
navigate(Routes.FlowSelection);
};
@@ -111,6 +112,8 @@ const Home = () => {
const stageParams = stageAction?.params;
const stageLocked = activeStage?.isLocked ?? true;
const hasActiveProject = !!currentProject;
const ensureProjectSelected = useCallback(() => {
if (!currentProject?.id) {
return;
@@ -121,14 +124,34 @@ const Home = () => {
}, [currentProject?.id, selectProject, selectedProject?.id]);
const handleStageAction = useCallback(() => {
if (stageLocked || !stageRoute) {
if (!hasActiveProject || stageLocked || !stageRoute) {
return;
}
ensureProjectSelected();
navigate(stageRoute, stageParams);
}, [ensureProjectSelected, stageLocked, stageParams, stageRoute]);
}, [
ensureProjectSelected,
hasActiveProject,
stageLocked,
stageParams,
stageRoute,
]);
const primaryDisabled = stageLocked || !stageRoute;
const songwriterAction = useMemo(
() => getStageAction("songwriter", null),
[],
);
const handleStartNew = useCallback(() => {
resetSelectedProject();
setActiveStageIndex(0);
if (songwriterAction?.route) {
navigate(songwriterAction.route, songwriterAction.params);
}
}, [resetSelectedProject, songwriterAction]);
const continueDisabled = !hasActiveProject || stageLocked || !stageRoute;
const startDisabled = !songwriterAction?.route;
return (
<Page shareBtn backgroundImg={background.homeBGWeb} headerType="NONE">
<View style={styles.root}>
@@ -149,9 +172,10 @@ const Home = () => {
style={[isWeb ? { width: "100%" } : { flex: 1 }]}
projects={projects}
selectedProject={currentProject}
allowEmptySelection
onSelectProject={handleSelectProject}
onModifyProject={handleModifyProject}
onCreateProject={handleCreateNew}
onCreateProject={handleStartNew}
formatDate={formatDate}
/>
{!isWeb && <ShareBtn />}
@@ -159,6 +183,7 @@ const Home = () => {
<View style={styles.carouselSection}>
<FeatureCarousel
selectedProject={currentProject}
stageStates={stageStates}
activeIndex={activeStageIndex}
onActiveIndexChange={setActiveStageIndex}
/>
@@ -175,14 +200,14 @@ const Home = () => {
<GradientButton
containerStyle={{ width: Platform.OS === "web" ? 250 : "100%" }}
title={"Commencer à créer"}
onPress={handleStageAction}
disabled={primaryDisabled}
onPress={handleStartNew}
disabled={startDisabled}
/>
<BorderGradientButton
containerStyle={{ width: Platform.OS === "web" ? 250 : "100%" }}
title={"Continuer la création"}
onPress={handleStageAction}
disabled={primaryDisabled}
disabled={continueDisabled}
/>
</View>
</View>