firebase errors and continue profress

This commit is contained in:
2025-10-12 13:47:37 +02:00
parent 0a32a37681
commit 31e81ef83d
5 changed files with 117 additions and 26 deletions
+40 -10
View File
@@ -75,12 +75,31 @@ const Home = () => {
[currentProject]
);
const firstUnlockedIndex = useMemo(() => {
const index = stageStates.findIndex((stage) => !stage.isLocked);
return index === -1 ? 0 : index;
const preferredStageIndex = useMemo(() => {
if (!stageStates.length) {
return 0;
}
const actionableIndex = stageStates.findIndex(
(stage) => !stage.isCompleted && !stage.isLocked
);
if (actionableIndex !== -1) {
return actionableIndex;
}
const firstIncomplete = stageStates.findIndex(
(stage) => !stage.isCompleted
);
if (firstIncomplete !== -1) {
return firstIncomplete;
}
const firstUnlocked = stageStates.findIndex((stage) => !stage.isLocked);
if (firstUnlocked !== -1) {
return firstUnlocked;
}
return stageStates.length - 1;
}, [stageStates]);
const [activeStageIndex, setActiveStageIndex] = useState(firstUnlockedIndex);
const [activeStageIndex, setActiveStageIndex] =
useState(preferredStageIndex);
const [menuVisible, setMenuVisible] = useState(false);
const [menuAnchor, setMenuAnchor] = useState(null);
const [menuProject, setMenuProject] = useState(null);
@@ -89,17 +108,28 @@ const Home = () => {
useEffect(() => {
setActiveStageIndex((prev) => {
const fallbackIndex =
preferredStageIndex >= 0 && preferredStageIndex < stageStates.length
? preferredStageIndex
: 0;
if (prev == null || prev >= stageStates.length) {
return firstUnlockedIndex;
return fallbackIndex;
}
const current = stageStates[prev];
const fallback = stageStates[firstUnlockedIndex];
if (current?.isLocked && fallback && !fallback.isLocked) {
return firstUnlockedIndex;
if (!current) {
return fallbackIndex;
}
if (
(current.isLocked || current.isCompleted) &&
fallbackIndex !== prev &&
stageStates[fallbackIndex]
) {
return fallbackIndex;
}
return prev;
});
}, [stageStates, firstUnlockedIndex]);
}, [stageStates, preferredStageIndex]);
const handleSelectProject = useCallback(
(project) => {
@@ -182,7 +212,7 @@ const Home = () => {
}, [handleDeleteProject, menuProject?.id]);
const activeStage =
stageStates[activeStageIndex] || stageStates[firstUnlockedIndex];
stageStates[activeStageIndex] || stageStates[preferredStageIndex];
const stageAction = useMemo(() => {
if (!activeStage) {
return null;