fix(folder): keep current folder view on refresh
This commit is contained in:
+13
-2
@@ -540,8 +540,15 @@ function initApp() {
|
||||
grants.fetchIncomingGrants();
|
||||
grants.fetchOutgoingGrants();
|
||||
|
||||
switchSectionTo(hashContext.section);
|
||||
if (hashContext.section === 'files') {
|
||||
// Capture the URL-derived path BEFORE the section switch.
|
||||
// `switchToFilesSection` resets `app.currentPath` to home
|
||||
// by default and kicks off its own `loadFiles()` — if we
|
||||
// wrote the hash-derived path AFTER the switch, our write
|
||||
// would race the load-already-in-flight and lose, taking
|
||||
// the user back to root on every other refresh. Setting
|
||||
// first + `preservePath: true` makes the switch's load
|
||||
// start with the correct path.
|
||||
if (hashContext.path) {
|
||||
console.log(`init: reusing folder from hash URL: ${hashContext.path}`);
|
||||
app.currentPath = hashContext.path;
|
||||
@@ -551,7 +558,11 @@ function initApp() {
|
||||
app.viewFile = hashContext.file;
|
||||
}
|
||||
|
||||
loadFiles();
|
||||
switchToFilesSection({ preservePath: true });
|
||||
// `switchToFilesSection` already calls `loadFiles()` — do
|
||||
// not call it again here, that would race itself.
|
||||
} else {
|
||||
switchSectionTo(hashContext.section);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -270,7 +270,20 @@ function switchToSharedWithMeSection() {
|
||||
sharedWithMeView.init();
|
||||
}
|
||||
|
||||
function switchToFilesSection() {
|
||||
/**
|
||||
* Switch the UI into the Files section.
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {boolean} [options.preservePath=false]
|
||||
* When true, keep the current `app.currentPath` instead of resetting
|
||||
* to the home folder. Used on initial page load with a hash-driven
|
||||
* path (e.g. `#/files/folder/<uuid>`) so the section switch doesn't
|
||||
* clobber the path the caller has just set from the URL. Without
|
||||
* this flag, the unconditional reset races with `loadFiles()`
|
||||
* (which is also kicked off from here) and the home-folder URL
|
||||
* wins, redirecting the user back to root on every other refresh.
|
||||
*/
|
||||
function switchToFilesSection({ preservePath = false } = {}) {
|
||||
if (!setCurrentSection('files')) return;
|
||||
|
||||
// Set actions bar mode
|
||||
@@ -299,12 +312,13 @@ function switchToFilesSection() {
|
||||
//reset files view + remove any error
|
||||
ui.resetFilesList();
|
||||
|
||||
// Reset to home folder and update breadcrumb. External users have no
|
||||
// home — leave `currentPath` as the caller set it (e.g. the magic-link
|
||||
// Reset to home folder unless the caller has pre-set a path (the
|
||||
// `preservePath` opt-in). External users have no home — leave
|
||||
// `currentPath` as the caller set it (e.g. the magic-link
|
||||
// landing's hash context) so loadFiles() doesn't fall through to
|
||||
// `/api/folders//resources`. If `currentPath` is still empty by the
|
||||
// time loadFiles() runs, it self-redirects to /#/sharedwithme.
|
||||
if (!app.isExternalUser) {
|
||||
// `/api/folders//resources`. If `currentPath` is still empty by
|
||||
// the time loadFiles() runs, it self-redirects to /#/sharedwithme.
|
||||
if (!app.isExternalUser && !preservePath) {
|
||||
app.currentPath = app.userHomeFolderId || '';
|
||||
app.breadcrumbPath = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user