1 import { useEffect, useRef } from 'react';
3 import { useLoading } from '@proton/hooks';
4 import { SORT_DIRECTION } from '@proton/shared/lib/constants';
6 import { sendErrorReport } from '../../utils/errorHandling';
7 import { useLinksListing } from '../_links';
8 import { useUserSettings } from '../_settings';
9 import { useDefaultShare } from '../_shares';
10 import { useAbortSignal, useMemoArrayNoMatterTheOrder, useSortingWithDefault } from './utils';
11 import type { SortField } from './utils/useSorting';
13 const DEFAULT_SORT = {
14 sortField: 'name' as SortField,
15 sortOrder: SORT_DIRECTION.ASC,
19 * useTrashView provides data for trash view (file browser of trash).
21 export default function useTrashView() {
22 const abortSignal = useAbortSignal();
23 const { getDefaultShare } = useDefaultShare();
24 const [isLoading, withLoading] = useLoading(true);
25 const volumeId = useRef<string>();
27 const linksListing = useLinksListing();
28 const { links: trashedLinks, isDecrypting } = linksListing.getCachedTrashed(abortSignal, volumeId.current);
29 const cachedTrashedLinks = useMemoArrayNoMatterTheOrder(trashedLinks);
31 const { layout } = useUserSettings();
32 const { sortedList, sortParams, setSorting } = useSortingWithDefault(cachedTrashedLinks, DEFAULT_SORT);
34 const loadTrashListing = async (signal: AbortSignal) => {
35 const defaultShare = await getDefaultShare(signal);
36 volumeId.current = defaultShare.volumeId;
37 await linksListing.loadTrashedLinks(signal, defaultShare.volumeId);
41 const ac = new AbortController();
42 void withLoading(loadTrashListing(ac.signal)).catch(sendErrorReport);
53 isLoading: isLoading || isDecrypting,