1 import { useCallback } from 'react';
3 import { getPublicLinks } from '@proton/shared/lib/api/calendars';
4 import createCache from '@proton/shared/lib/helpers/cache';
5 import type { CalendarUrlsResponse } from '@proton/shared/lib/interfaces/calendar';
7 import useApi from './useApi';
8 import useCache from './useCache';
9 import { getPromiseValue } from './useCachedModelResult';
11 export const KEY = 'CALENDAR_PUBLIC_LINKS';
13 export const useGetCalendarPublicLinks = () => {
15 const cache = useCache();
16 const miss = useCallback(
17 (calendarID: string): Promise<CalendarUrlsResponse> => {
18 return api<CalendarUrlsResponse>(getPublicLinks(calendarID));
24 (calendarID: string) => {
25 if (!cache.has(KEY)) {
26 cache.set(KEY, createCache());
28 return getPromiseValue(cache.get(KEY), calendarID, miss);