1 import { useEffect, useMemo } from 'react';
3 import { useLoading } from '@proton/hooks';
4 import { SORT_DIRECTION } from '@proton/shared/lib/constants';
5 import { LayoutSetting } from '@proton/shared/lib/interfaces/drive/userSettings';
7 import { useSelectionControls } from '../../components/FileBrowser';
8 import { sendErrorReport } from '../../utils/errorHandling';
9 import { usePublicLinksListing } from '../_links';
10 import { useAbortSignal, useLinkName, useMemoArrayNoMatterTheOrder, useSortingWithDefault } from './utils';
11 import { SortField } from './utils/useSorting';
13 export const DEFAULT_SORT = {
14 sortField: SortField.name,
15 sortOrder: SORT_DIRECTION.ASC,
19 * usePublicFolderView provides data for folder view (file browser of folder).
20 * It is very similar to useFolderView for private app, this is just for the
21 * publicly shared folder.
23 export default function usePublicFolderView(token: string, linkId: string) {
24 const folderName = useLinkName(token, linkId);
26 const abortSignal = useAbortSignal([token, linkId]);
28 const [isLoading, withLoading] = useLoading(true);
30 const linksListing = usePublicLinksListing();
31 const { links: children, isDecrypting } = linksListing.getCachedChildren(abortSignal, token, linkId);
32 const cachedChildren = useMemoArrayNoMatterTheOrder(children);
34 const { sortedList, sortParams, setSorting } = useSortingWithDefault(cachedChildren, DEFAULT_SORT);
36 const sortedListForSelection = useMemo(() => {
37 return sortedList.map((item) => ({
39 disabled: item.isLocked,
44 const selectionControls = useSelectionControls({ itemIds: sortedListForSelection.map((item) => item.id) });
47 const ac = new AbortController();
48 void withLoading(linksListing.loadChildren(ac.signal, token, linkId).catch(sendErrorReport));
55 layout: LayoutSetting.List,
61 isLoading: isLoading || isDecrypting,