Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / applications / drive / src / app / store / _views / useInvitationsView.ts
blob43f14dc164f6fb0215ef899b5c3d4d36d95f796c
1 import { useEffect, useMemo } from 'react';
3 import useLoading from '@proton/hooks/useLoading';
5 import type { SharedWithMeItem } from '../../components/sections/SharedWithMe/SharedWithMe';
6 import { sendErrorReport } from '../../utils/errorHandling';
7 import { useDriveEventManager } from '../_events';
8 import { useInvitationsListing } from '../_invitations/useInvitationsListing';
10 export const useInvitationsView = () => {
11     const [isLoading, withLoading] = useLoading(true);
12     const { getCachedInvitations, loadInvitations } = useInvitationsListing();
13     const driveEventManager = useDriveEventManager();
15     const cachedInvitations = getCachedInvitations();
17     const invitationsBrowserItems: SharedWithMeItem[] = useMemo(
18         () =>
19             cachedInvitations.reduce<SharedWithMeItem[]>((acc, item) => {
20                 acc.push({
21                     isFile: item.link.isFile,
22                     trashed: null,
23                     mimeType: item.link.mimeType,
24                     rootShareId: item.share.shareId,
25                     id: item.share.shareId,
26                     // DecrypptedLinkName will always be defined as it's retrieve in the listing
27                     name: item.decryptedLinkName || '',
28                     invitationDetails: item,
29                     sharedBy: item.invitation.inviterEmail,
30                     isInvitation: true,
31                     size: 0,
32                     isLocked: item.isLocked,
33                     linkId: item.link.linkId,
34                     parentLinkId: '',
35                     volumeId: item.share.volumeId,
36                 });
37                 return acc;
38             }, []),
39         [cachedInvitations]
40     );
42     useEffect(() => {
43         const abortController = new AbortController();
44         const unsubscribe = driveEventManager.eventHandlers.subscribeToCore((event) => {
45             if (event.DriveShareRefresh?.Action === 2) {
46                 loadInvitations(abortController.signal).catch(sendErrorReport);
47             }
48         });
49         return () => {
50             unsubscribe();
51             abortController.abort();
52         };
53     }, [driveEventManager.eventHandlers.subscribeToCore]);
55     useEffect(() => {
56         const abortController = new AbortController();
57         void withLoading(loadInvitations(abortController.signal).catch(sendErrorReport));
59         return () => {
60             abortController.abort();
61         };
62     }, []);
64     return { invitations: cachedInvitations, invitationsBrowserItems, isLoading };