polished and finalised onboarding flow

This commit is contained in:
Chris Sanden
2026-05-05 17:36:34 +02:00
parent 2bb2ac63a0
commit 9bb3bb1163
10 changed files with 310 additions and 57 deletions

View File

@@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import type { SessionType } from '@/lib/types';
const notificationKey = (aId: string) => `assignment_notification_${aId}`;
const setupSprintDemoKey = (userId: string) => `setup_sprint_demo_${userId}`;
const activeSprintKey = 'active_sprint';
const studyCycleKey = 'study_cycle';
@@ -68,3 +69,12 @@ export async function GetStudyCycle() {
export async function RemoveStudyCycle() {
await AsyncStorage.removeItem(studyCycleKey);
}
export async function GetSetupSprintDemoUsed(userId: string) {
const value = await AsyncStorage.getItem(setupSprintDemoKey(userId));
return value === 'true';
}
export async function SaveSetupSprintDemoUsed(userId: string) {
await AsyncStorage.setItem(setupSprintDemoKey(userId), 'true');
}

84
lib/setupStatus.ts Normal file
View File

@@ -0,0 +1,84 @@
import { supabase } from '@/lib/supabase';
export type SetupStepKey = 'subject' | 'assignment' | 'task' | 'sprint';
export type SetupStatus = {
subjectId: string | null;
assignmentId: string | null;
taskId: string | null;
completedFocusSessions: number;
currentStep: SetupStepKey;
isSetupComplete: boolean;
};
export async function getSetupStatus(userId: string): Promise<SetupStatus> {
const [subjectResult, assignmentResult, taskResult, focusSessionResult] = await Promise.all([
supabase
.from('subjects')
.select('sId')
.eq('uId', userId)
.order('lastChanged', { ascending: false })
.limit(1)
.maybeSingle(),
supabase
.from('assignments')
.select('aId')
.eq('uId', userId)
.order('lastChanged', { ascending: false })
.limit(1)
.maybeSingle(),
supabase
.from('tasks')
.select('tId')
.eq('uId', userId)
.order('lastChanged', { ascending: false })
.limit(1)
.maybeSingle(),
supabase
.from('sprint_sessions')
.select('sessionId', { count: 'exact', head: true })
.eq('userId', userId)
.eq('sessionType', 'focus')
.eq('status', 'completed'),
]);
if (subjectResult.error) {
throw subjectResult.error;
}
if (assignmentResult.error) {
throw assignmentResult.error;
}
if (taskResult.error) {
throw taskResult.error;
}
if (focusSessionResult.error) {
throw focusSessionResult.error;
}
const subjectId = subjectResult.data?.sId ?? null;
const assignmentId = assignmentResult.data?.aId ?? null;
const taskId = taskResult.data?.tId ?? null;
const completedFocusSessions = focusSessionResult.count ?? 0;
let currentStep: SetupStepKey = 'sprint';
if (!subjectId) {
currentStep = 'subject';
} else if (!assignmentId) {
currentStep = 'assignment';
} else if (!taskId) {
currentStep = 'task';
}
return {
subjectId,
assignmentId,
taskId,
completedFocusSessions,
currentStep,
isSetupComplete: taskId !== null && completedFocusSessions > 0,
};
}