36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { useQuery } from "convex/react"
|
|
import * as AppIntents from "expo-app-intents"
|
|
import { useMemo, useSyncExternalStore } from "react"
|
|
|
|
import { useMusicCatalogSync } from "@/components/app-intents/catalog-sync"
|
|
import { useIntentDispatch } from "@/components/app-intents/dispatch"
|
|
import { useNowPlayingCatalog } from "@/components/app-intents/now-playing"
|
|
import {
|
|
ANONYMOUS_CACHE_SCOPE,
|
|
useCacheScope,
|
|
} from "@/contexts/persistent-cache"
|
|
import { getPlaybackStore } from "@otunes/convex/client/playback-store"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
|
|
/**
|
|
* Siri and Shortcuts integration: the on-device entity catalog, the current
|
|
* song, and intent dispatch. Must render inside `FavoritesProvider`.
|
|
*/
|
|
export function AppIntentBridge() {
|
|
const scope = useCacheScope()
|
|
const store = useMemo(
|
|
() => getPlaybackStore(scope === ANONYMOUS_CACHE_SCOPE ? null : scope),
|
|
[scope]
|
|
)
|
|
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot)
|
|
const user = useQuery(api.auth.currentUser)
|
|
return user && snapshot.hydrated ? <ReadyAppIntentBridge key={scope} /> : null
|
|
}
|
|
|
|
function ReadyAppIntentBridge() {
|
|
useMusicCatalogSync()
|
|
useNowPlayingCatalog()
|
|
useIntentDispatch()
|
|
return null
|
|
}
|