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

Function useLazyModal

packages/shared/src/hooks/useLazyModal.ts:18–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16let feedbackScrollPosition = 0;
17
18export function useLazyModal<
19 K extends keyof ModalsType,
20 T extends LazyModalType<K> = LazyModalType<K>,
21>(): UseLazyModal<K, T> {
22 const client = useQueryClient();
23 const { data: modal } = useQuery({
24 queryKey: MODAL_KEY,
25 queryFn: () => client.getQueryData<T>(MODAL_KEY),
26 enabled: false,
27 });
28 const openModal = useCallback(
29 (data: T) => {
30 if (data.type === LazyModal.Feedback) {
31 feedbackScrollPosition = window.scrollY;
32 client.setQueryData(FEEDBACK_MODAL_KEY, data);
33 return;
34 }
35
36 scrollPosition = window.scrollY;
37
38 client.setQueryData(MODAL_KEY, data);
39 },
40 [client],
41 );
42 const closeModal = useCallback(() => {
43 window.scrollTo(0, scrollPosition);
44 scrollPosition = 0;
45
46 client.setQueryData(MODAL_KEY, null);
47 }, [client]);
48
49 return useMemo(
50 () => ({
51 openModal,
52 closeModal,
53 modal: modal as T,
54 }),
55 [openModal, closeModal, modal],
56 );
57}
58
59type UseFeedbackModal = {
60 closeModal: () => void;

Callers 15

ActionBarFunction · 0.90
FocusColumnFunction · 0.90
CustomFeedOptionsMenuFunction · 0.90
ShareBarFunction · 0.90
PlusInfoFunction · 0.90
PlusMarketingModalFunction · 0.90
BookmarkButtonFunction · 0.90
BookmarkButtonFunction · 0.90
PersonalizedDigestFunction · 0.90
InAppNotificationsTabFunction · 0.90
AwardButtonFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected