mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-04 21:15:50 +00:00
fix(dashboard): keep filtering Shared when it can't be listed again
A chip click lists Shared again so its rows are current. When that request failed, the listing was replaced with "This folder couldn't be opened" and the chips disappeared, though only a filter had changed. A filter change now applies to the rows already loaded when the listing can't be fetched.
This commit is contained in:
1 parent
e4888592c7
commit
3486f20543
2 files changed
+38
-3
No files matched your search
@@ -2799,7 +2799,7 @@ const TabFiles = {
|
||||
this.classList.toggle('active', pressed);
|
||||
this.setAttribute('aria-pressed', String(pressed));
|
||||
});
|
||||
await this.renderDirectory(window.shared_path);
|
||||
await this.renderDirectory(window.shared_path, { filterChange: true });
|
||||
if ( this.currentPath === window.shared_path ) {
|
||||
this.$el_window.find('.files-tab .files').scrollTop(0);
|
||||
}
|
||||
@@ -2816,6 +2816,7 @@ const TabFiles = {
|
||||
* @param {boolean} [options.skipUrlUpdate] - If true, don't update browser URL
|
||||
* @param {boolean} [options.skipNavHistory] - If true, don't add to navigation history
|
||||
* @param {boolean} [options.force] - Supersede a navigation that is still loading
|
||||
* @param {boolean} [options.filterChange] - A people filter change: if Shared can't be listed, filter the rows already loaded
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async renderDirectory (target, options = {}) {
|
||||
@@ -2880,10 +2881,17 @@ const TabFiles = {
|
||||
directoryContents = isSharedView
|
||||
? await this.listSharedView()
|
||||
: await window.puter.fs.readdir(readdirArg);
|
||||
if ( isSharedView ) this.sharedRows = directoryContents;
|
||||
} catch ( err ) {
|
||||
console.error('Failed to read directory:', err);
|
||||
readFailed = true;
|
||||
directoryContents = [];
|
||||
// Filtering needs no server: a filter change still applies to
|
||||
// the rows already loaded.
|
||||
if ( isSharedView && options.filterChange && this.sharedRows ) {
|
||||
directoryContents = this.sharedRows;
|
||||
} else {
|
||||
readFailed = true;
|
||||
directoryContents = [];
|
||||
}
|
||||
}
|
||||
if ( seq !== this.renderSeq ) return;
|
||||
if ( ! directoryContents ) {
|
||||
|
||||
@@ -663,6 +663,33 @@ describe('TabFiles people filter across navigation', () => {
|
||||
expect(listed()).toEqual(['a', 'b']);
|
||||
});
|
||||
|
||||
it('still filters when Shared fails to list again', async () => {
|
||||
await TabFiles.renderDirectory(SHARED);
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
TabFiles.listSharedView.mockImplementation(async () => {
|
||||
throw new Error('offline');
|
||||
});
|
||||
|
||||
await TabFiles.setSharerFilter('bob');
|
||||
|
||||
expect(listed()).toEqual(['b']);
|
||||
expect($('.sharer-chip.active').attr('data-sharer')).toBe('bob');
|
||||
expect($('.files').text()).not.toContain("couldn't be opened");
|
||||
});
|
||||
|
||||
it('still says a Shared it was asked to open could not be listed', async () => {
|
||||
await TabFiles.renderDirectory(SHARED);
|
||||
await TabFiles.renderDirectory('/alice/Documents');
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
TabFiles.listSharedView.mockImplementation(async () => {
|
||||
throw new Error('offline');
|
||||
});
|
||||
|
||||
await TabFiles.renderDirectory(SHARED);
|
||||
|
||||
expect($('.files').text()).toContain("couldn't be opened");
|
||||
});
|
||||
|
||||
it("clears once the user goes back to their own files", async () => {
|
||||
await TabFiles.renderDirectory(SHARED);
|
||||
await TabFiles.setSharerFilter('bob');
|
||||
|
||||
Reference in new issue
Block a user