import { SUBJECT_COLORS } from '@/lib/subjectColors'; import { getSetupStatus } from '@/lib/setupStatus'; import { supabase } from '@/lib/supabase'; import { Subject } from '@/lib/types'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import { Session } from '@supabase/supabase-js'; import { Redirect, router, Stack, useFocusEffect } from 'expo-router'; import { useCallback, useEffect, useState } from 'react'; import { Alert, Modal, Pressable, ScrollView, Text, View } from 'react-native'; import type { SubjectColor } from '@/lib/subjectColors'; const FLOW_STEPS = [ { label: '1', title: 'Subject', description: 'Start with the broad area you are studying, like one course or one exam you are preparing for.', }, { label: '2', title: 'Assignment', description: 'Inside that, add the bigger piece of work you want to move forward, like a project, a problem set, or revision block.', }, { label: '3', title: 'Task', description: 'Then break it down into one task that feels concrete enough to begin without overthinking it.', }, { label: '4', title: 'Sprint', description: 'That task is what you bring into a focus session. After a sprint, you take a short pause, then come back to the same kind of focused work. After a few rounds, the app gives you a longer pause so the rhythm still feels sustainable.', }, ] as const; export default function Subjects() { const [subjects, SetSubjects] = useState([]); const [session, SetSession] = useState(null); const [isFlowInfoVisible, setIsFlowInfoVisible] = useState(false); const [needsSetup, setNeedsSetup] = useState(null); useEffect(() => { supabase.auth.getSession().then(({ data }) => { SetSession(data.session ?? null); }); const { data: sub } = supabase.auth.onAuthStateChange( (_event, newSession) => { SetSession(newSession); } ); return () => sub.subscription.unsubscribe(); }, []); useEffect(() => { const loadSetupGate = async () => { if (!session?.user.id) { setNeedsSetup(false); return; } try { const setupStatus = await getSetupStatus(session.user.id); setNeedsSetup(!setupStatus.isSetupComplete); } catch { setNeedsSetup(true); } }; setNeedsSetup(null); void loadSetupGate(); }, [session?.user.id]); const GetSubjects = useCallback(async () => { if (!session?.user.id) return; const { data, error } = await supabase .from('subjects') .select('*') .eq('uId', session.user.id) .order('lastChanged', { ascending: false }); if (error) { Alert.alert('Subjects could not be fetched, please try again'); return; } SetSubjects((data as Subject[]) ?? []); }, [session?.user.id]); useFocusEffect( useCallback(() => { if (session) { void GetSubjects(); } }, [GetSubjects, session]) ); if (session && needsSetup === null) { return null; } if (needsSetup) { return ; } return ( ( setIsFlowInfoVisible(true)} > ), headerRight: () => ( await supabase.auth.signOut()} > Logout ), }} /> setIsFlowInfoVisible(false)} > setIsFlowInfoVisible(false)} /> How work is organized Study flow setIsFlowInfoVisible(false)} > The idea is to make getting started feel lighter. You decide what you are studying, narrow it down to one clear task, and then let the app carry you through a simple rhythm of focus and recovery. {FLOW_STEPS.map((step, index) => ( {step.label} {index < FLOW_STEPS.length - 1 ? ( ) : null} {step.title} {step.description} ))} Quick map {'Subject -> Assignment -> Task -> Sprint'} In practice, that usually becomes focus session, short pause, focus session again, and eventually a longer pause when you have done a few solid rounds. setIsFlowInfoVisible(false)} > Close Guide Subjects Pick a subject to manage assignments and tasks. {subjects.length === 0 ? ( No subjects yet Start with one subject so the rest of your study path has a clear place to live. router.push('/setup')} > Start Guided Setup ) : ( {subjects.map((subject) => { const colorKey: SubjectColor = subject.color ?? 'slate'; const colorSet = SUBJECT_COLORS[colorKey]; const firstLetter = subject.title?.trim().charAt(0).toUpperCase() || '?'; return ( router.push({ pathname: '/subject/viewDetailsSubject', params: { sId: subject.sId }, }) } > {firstLetter} {subject.title} {subject.description || 'No description added.'} {subject.isActive ? 'Active' : 'Inactive'} ); })} )} {subjects.length > 0 ? ( router.push('/subject/upsertSubject')} > Create Subject ) : null} ); }