0.0.0.4
This commit is contained in:
@@ -6,6 +6,7 @@ import type { FamilyMember, FamilyTreeData } from "@/types/family"
|
||||
import { mockFamilyData } from "@/lib/mock-data"
|
||||
import { db } from "@/lib/db"
|
||||
import { useLiveQuery } from "dexie-react-hooks"
|
||||
import { setupDailyNotificationCheck } from "@/lib/notifications"
|
||||
|
||||
interface FamilyContextType {
|
||||
treeData: FamilyTreeData
|
||||
@@ -18,6 +19,8 @@ interface FamilyContextType {
|
||||
loadData: (data: FamilyTreeData) => Promise<void>
|
||||
resetData: () => Promise<void>
|
||||
isLoading: boolean
|
||||
highlightedMemberId: string | null
|
||||
setHighlightedMemberId: (id: string | null) => void
|
||||
}
|
||||
|
||||
const FamilyContext = createContext<FamilyContextType | undefined>(undefined)
|
||||
@@ -25,6 +28,7 @@ const FamilyContext = createContext<FamilyContextType | undefined>(undefined)
|
||||
export function FamilyProvider({ children }: { children: React.ReactNode }) {
|
||||
const [searchResults, setSearchResults] = useState<FamilyMember[]>([])
|
||||
const [isInitialized, setIsInitialized] = useState(false)
|
||||
const [highlightedMemberId, setHighlightedMemberId] = useState<string | null>(null)
|
||||
|
||||
// Live query to get all members
|
||||
const members = useLiveQuery(() => db.members.toArray())
|
||||
@@ -46,6 +50,16 @@ export function FamilyProvider({ children }: { children: React.ReactNode }) {
|
||||
initDb()
|
||||
}, [])
|
||||
|
||||
// 设置通知检查
|
||||
useEffect(() => {
|
||||
if (isInitialized && members && members.length > 0) {
|
||||
// 检查通知权限并设置每日检查
|
||||
if ("Notification" in window && Notification.permission === "granted") {
|
||||
setupDailyNotificationCheck(members)
|
||||
}
|
||||
}
|
||||
}, [isInitialized, members])
|
||||
|
||||
// Construct treeData from DB results
|
||||
const treeData: FamilyTreeData = {
|
||||
rootId: rootIdSetting?.value || "",
|
||||
@@ -180,6 +194,8 @@ export function FamilyProvider({ children }: { children: React.ReactNode }) {
|
||||
loadData,
|
||||
resetData,
|
||||
isLoading: !isInitialized || !members,
|
||||
highlightedMemberId,
|
||||
setHighlightedMemberId,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user