Personal-first lists/tasks/reminders/recurrence, plus an admin-editable status pipeline, shared categories, project containers, and a three-tier permission model for cross-user work: assign (hand off your own tasks), reallocate (dispatcher — move anyone's tasks), admin (reserved, full manage-all).
32 lines
895 B
TypeScript
32 lines
895 B
TypeScript
import { createContext, useContext, useEffect, useState, useCallback } from 'react'
|
|
import type { List } from '../types'
|
|
import { fetchLists } from '../api'
|
|
|
|
interface ListsCtx {
|
|
lists: List[]
|
|
loading: boolean
|
|
reload: () => Promise<void>
|
|
}
|
|
|
|
const Ctx = createContext<ListsCtx | null>(null)
|
|
|
|
export function useLists() {
|
|
const ctx = useContext(Ctx)
|
|
if (!ctx) throw new Error('useLists must be used inside ListsProvider')
|
|
return ctx
|
|
}
|
|
|
|
export function ListsProvider({ children }: { children: React.ReactNode }) {
|
|
const [lists, setLists] = useState<List[]>([])
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
const reload = useCallback(async () => {
|
|
const data = await fetchLists().catch(() => [])
|
|
setLists(data)
|
|
setLoading(false)
|
|
}, [])
|
|
|
|
useEffect(() => { reload() }, [reload])
|
|
|
|
return <Ctx.Provider value={{ lists, loading, reload }}>{children}</Ctx.Provider>
|
|
}
|