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

Function usePrompt

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

Source from the content-addressed store, hash-verified

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

Callers 15

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

Calls 1

closeWithFunction · 0.85

Tested by 1

TestComponentFunction · 0.72