import { SUBJECT_COLORS } from '@/lib/subjectColors'; import { supabase } from '@/lib/supabase'; import { Subject } from '@/lib/types'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import { Session } from '@supabase/supabase-js'; import { 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: 'A subject is the top-level container for one course or area you are studying.', }, { label: '2', title: 'Assignment', description: 'Each subject contains assignments like projects, exercises, or exam prep blocks.', }, { label: '3', title: 'Task', description: 'Assignments are broken down into tasks so you always have one concrete thing to work on.', }, { label: '4', title: 'Sprint', description: 'A sprint is one focused work session tied to a single task. After it ends, you can take a break, continue the same task, or return to the dashboard.', }, ] as const; export default function Subjects() { const [subjects, SetSubjects] = useState([]); const [session, SetSession] = useState(null); const [isFlowInfoVisible, setIsFlowInfoVisible] = useState(false); useEffect(() => { supabase.auth.getSession().then(({ data }) => { SetSession(data.session ?? null); }); const { data: sub } = supabase.auth.onAuthStateChange( (_event, newSession) => { SetSession(newSession); } ); return () => sub.subscription.unsubscribe(); }, []); 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]) ); return ( ( setIsFlowInfoVisible(true)} > ), headerRight: () => ( await supabase.auth.signOut()} > Logout ), }} /> setIsFlowInfoVisible(false)} > setIsFlowInfoVisible(false)} /> How work is organized Study flow setIsFlowInfoVisible(false)} > Build your work from the big container down to one concrete task, then use sprints and breaks to move that work forward. {FLOW_STEPS.map((step, index) => ( {step.label} {index < FLOW_STEPS.length - 1 ? ( ) : null} {step.title} {step.description} ))} Quick map {'Subject -> Assignment -> Task -> Sprint'} Subjects hold the study structure. The dashboard is where you resume active sessions, start the next sprint, and check recent progress. 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} ); }