Skip to content

Commit 9118ae8

Browse files
author
Dobromir Hristov
committed
fix: scrollToElement when persisted, and fix filtered persistence
1 parent 53b1359 commit 9118ae8

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/components/Navigator/NavigatorCard.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ export default {
218218
* Initiates a watcher, that reacts to filtering and page navigation.
219219
*/
220220
trackOpenNodes(
221-
[filteredChildren, activePathChildren],
222-
[, activePathChildrenBefore] = [],
221+
[filteredChildren, activePathChildren, filter],
222+
[, activePathChildrenBefore, filterBefore] = [],
223223
) {
224+
// skip in case this is a first mount and we are syncing the `filter`.
225+
if (filter !== filterBefore && !filterBefore && sessionStorage.get(STORAGE_KEYS.filter)) {
226+
return;
227+
}
224228
// decide which items to filter
225229
const nodes = !this.filterPattern
226230
? activePathChildren
@@ -345,18 +349,7 @@ export default {
345349
// check if we want to scroll to the element
346350
if (!scrollToElement) return;
347351
// wait a frame, so the scroller is ready, `nextTick` is not enough.
348-
await waitFrames(1);
349-
// if we are filtering, it makes more sense to scroll to top of list
350-
const index = filterPattern
351-
? 0
352-
// find the index of the current active UID in the newly added nodes
353-
: this.nodesToRender.findIndex(child => child.uid === this.activeUID);
354-
// if for some reason we cant find the active page, bail.
355-
// make sure the scroller is visible
356-
if (index !== -1 && this.$refs.scroller) {
357-
// call the scroll method on the `scroller` component.
358-
this.$refs.scroller.scrollToItem(index);
359-
}
352+
this.scrollToElement();
360353
},
361354
/**
362355
* Persists the current state, so its not lost if you refresh or navigate away
@@ -380,6 +373,21 @@ export default {
380373
const nodesToRender = sessionStorage.get(STORAGE_KEYS.nodesToRender, []);
381374
this.nodesToRender = nodesToRender.map(uid => this.childrenMap[uid]);
382375
this.filter = sessionStorage.get(STORAGE_KEYS.filter, '');
376+
this.scrollToElement();
377+
},
378+
async scrollToElement() {
379+
await waitFrames(1);
380+
// if we are filtering, it makes more sense to scroll to top of list
381+
const index = this.filterPattern
382+
? 0
383+
// find the index of the current active UID in the newly added nodes
384+
: this.nodesToRender.findIndex(child => child.uid === this.activeUID);
385+
// if for some reason we cant find the active page, bail.
386+
// make sure the scroller is visible
387+
if (index !== -1 && this.$refs.scroller) {
388+
// call the scroll method on the `scroller` component.
389+
this.$refs.scroller.scrollToItem(index);
390+
}
383391
},
384392
},
385393
};

0 commit comments

Comments
 (0)