File
Blob: src/client/components/workspace/share-dialog/context.ts
| 1 | import { createContext, use } from "react"; |
| 2 | |
| 3 | import type { ShareDialogShellValue, ShareLinkValue, SharePeopleValue, SitePublishValue } from "./types"; |
| 4 | |
| 5 | export const ShareDialogShellContext = createContext<ShareDialogShellValue | null>(null); |
| 6 | export const SharePeopleContext = createContext<SharePeopleValue | null>(null); |
| 7 | export const ShareLinkContext = createContext<ShareLinkValue | null>(null); |
| 8 | export const SitePublishContext = createContext<SitePublishValue | null>(null); |
| 9 | |
| 10 | export function useShareDialogShell(): ShareDialogShellValue { |
| 11 | const ctx = use(ShareDialogShellContext); |
| 12 | if (!ctx) throw new Error("useShareDialogShell must be used inside ShareDialog"); |
| 13 | return ctx; |
| 14 | } |
| 15 | |
| 16 | export function useSharePeople(): SharePeopleValue { |
| 17 | const ctx = use(SharePeopleContext); |
| 18 | if (!ctx) throw new Error("useSharePeople must be used inside ShareDialog"); |
| 19 | return ctx; |
| 20 | } |
| 21 | |
| 22 | export function useShareLink(): ShareLinkValue { |
| 23 | const ctx = use(ShareLinkContext); |
| 24 | if (!ctx) throw new Error("useShareLink must be used inside ShareDialog"); |
| 25 | return ctx; |
| 26 | } |
| 27 | |
| 28 | export function useSitePublish(): SitePublishValue { |
| 29 | const ctx = use(SitePublishContext); |
| 30 | if (!ctx) throw new Error("useSitePublish must be used inside ShareDialog"); |
| 31 | return ctx; |
| 32 | } |