MCPcopy Create free account
hub / github.com/dailydotdev/apps / usePrompt

Function usePrompt

packages/shared/src/hooks/usePrompt.ts:44–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42};
43
44export function usePrompt(): UsePromptRet {
45 const client = useQueryClient();
46 const { data: prompt } = useQuery({
47 queryKey: PROMPT_KEY,
48 queryFn: () => client.getQueryData<PromptState>(PROMPT_KEY) ?? null,
49 });
50
51 const setPrompt = useCallback(
52 (data: PromptState) => client.setQueryData(PROMPT_KEY, data),
53 [client],
54 );
55
56 const showPrompt = useCallback(
57 (promptOptions: PromptOptions): Promise<boolean> =>
58 new Promise((resolve) => {
59 const closeWith = (result: boolean) => {
60 resolve(result);
61 setPrompt(null);
62 };
63 const newPrompt: Prompt = {
64 options: promptOptions,
65 onFail: () => closeWith(false),
66 onSuccess: () => closeWith(true),
67 };
68 setPrompt(newPrompt);
69 }),
70 [setPrompt],
71 );
72
73 return { showPrompt, prompt: prompt ?? null };
74}

Callers 15

OpportunityEditInfoModalFunction · 0.90
OpportunityStepsFunction · 0.90
ReadingStreakPopupFunction · 0.90
IntroQuestModalFunction · 0.90
PromptElementFunction · 0.90
SmartComposerModalFunction · 0.90

Calls 1

closeWithFunction · 0.85

Tested by

no test coverage detected