mirror of
https://github.com/projectsend/projectsend.git
synced 2026-10-07 22:01:21 +00:00
Keep the open folder and the chosen sort while browsing My files
Changing the sort (or search, category, owner) inside a folder on the client portal navigated to the top of My files, because the list query was built without the folder. And opening a folder, or following a breadcrumb, dropped the chosen sort, because folderUrl() carried only the folder id. Every portal theme shares the hook, so all four were affected. The list query now carries the open folder, and folderUrl() carries the sort when it is not the default (newest first), so default addresses stay clean. Search and the filters still show a flat list across every folder, as MyFilesController intends; clearing them returns to the folder. The staff library is unchanged: there, dropping the folder for a search is documented intent. Checked in a browser on a client account: sorting by name inside a folder stays in it and reorders it, and a folder link from a sorted list keeps the sort. Reported by @cookiebaker (#1806)
This commit is contained in:
@@ -52,17 +52,26 @@ export function usePortalFiles({ folder, search, category, owner, sort, directio
|
||||
};
|
||||
const downloadSelectionAsZip = () => zip.start({ file_ids: [...selectedFileIds], folder_ids: [...selectedFolderIds] });
|
||||
|
||||
// The open folder goes along with every change, or re-sorting inside a
|
||||
// folder navigated back to the top of My files. Search and the filters
|
||||
// still show a flat list across every folder (MyFilesController), and
|
||||
// clearing them comes back to the folder.
|
||||
const { values, set, setMany, reset } = useListQuery(
|
||||
'my-files.index',
|
||||
{ search, category: category === null ? ALL : String(category), owner: owner ?? ALL, sort, direction },
|
||||
{ search: '', category: ALL, owner: ALL, sort: 'date', direction: 'desc' },
|
||||
folder !== null ? { folder: folder.id } : undefined,
|
||||
);
|
||||
// Sort/direction always have a concrete value (there's no "unset" sort),
|
||||
// so they're excluded here — only search/category/owner count as active
|
||||
// filters worth surfacing a "Clear" button for.
|
||||
const hasFilters = values.search !== '' || values.category !== ALL || values.owner !== ALL;
|
||||
|
||||
const folderUrl = (id: number | null) => (id === null ? route('my-files.index') : route('my-files.index', { folder: id }));
|
||||
// Opening a folder keeps the chosen sort. Only the sort: opening a folder
|
||||
// means leaving a search, so the filters are not carried. The default
|
||||
// (newest first) is left out to keep the address clean.
|
||||
const sortParams = values.sort === 'date' && values.direction === 'desc' ? {} : { sort: values.sort, direction: values.direction };
|
||||
const folderUrl = (id: number | null) => route('my-files.index', id === null ? sortParams : { folder: id, ...sortParams });
|
||||
|
||||
return {
|
||||
zip,
|
||||
|
||||
Reference in New Issue
Block a user