UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

52 lines (50 loc) • 1.97 kB
import "@tanstack/react-start"; //#region src/push.d.ts /** What the builder wrote in Studio for the prompt. Any of it may be missing. */ type PushPrompt = { title: string | null; message: string | null; enableButtonLabel: string | null; }; type PushNotifications = /** Loading, signed out, push off for this app or device, or a browser without push. */ { status: "unavailable"; } /** iPhone and iPad offer push only inside the installed app. */ | { status: "install-first"; prompt: PushPrompt; } | { status: "ask"; prompt: PushPrompt; /** The visitor skipped the prompt recently, within the builder's skip days. Hide the prompt. */ dismissed: boolean; /** Asks the browser for permission and subscribes. Call it from a click. */ subscribe: () => Promise<void>; /** Hides the prompt for as long as the builder set in Studio. */ dismiss: () => void; } | { status: "subscribed"; unsubscribe: () => Promise<void>; } /** The visitor blocked notifications in the browser. Only they can undo it, in the browser's settings. */ | { status: "blocked"; }; /** * Push notifications for the signed-in visitor. Call it once, in the one * component that shows the prompt, rendered once in the root route's * `RootDocument`, so this browser stays registered. Each call keeps state of * its own, so a second call does not see a subscribe made through the first. * Show a prompt only while `status` is `ask` * and the prompt is not `dismissed`. * * @example * function EnableNotifications() { * const push = usePushNotifications() * if (push.status !== "ask" || push.dismissed) return null * const turnOn = () => push.subscribe().catch(() => toast.error("Notifications could not be turned on.")) * return <button onClick={turnOn}>{push.prompt.enableButtonLabel ?? "Turn on"}</button> * } */ declare function usePushNotifications(): PushNotifications; //#endregion export { PushNotifications, PushPrompt, usePushNotifications };