diff options
| author | JP Dillingham <jp@dillingham.me> | 2023-08-06 21:21:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-06 21:21:28 -0500 |
| commit | 26b23d5be9f6586d5f1b62dccdfd7abce89dad8c (patch) | |
| tree | 51534daa20743bb2fa41f87396625315f453eb88 /src | |
| parent | aa21cc6ec38316c9d32a798243c4e492d501c498 (diff) | |
| parent | 969b43ce4c30f6a94c0b889bea35c6111f70f7c5 (diff) | |
| download | slskd-26b23d5be9f6586d5f1b62dccdfd7abce89dad8c.tar.gz | |
Merge pull request #951 from slskd/dl-button
Preserve file selection when fetching directory contents
Diffstat (limited to 'src')
| -rw-r--r-- | src/web/src/components/Search/Response.js | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 620900f9..babfc22b 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -66,15 +66,22 @@ class Response extends Component { this.setState({ fetchingDirectoryContents: true }); try { + const oldTree = { ...this.state.tree }; + const oldFiles = oldTree[directory]; + const { name, files } = await getDirectoryContents({ username, directory }); - files.forEach((file, index) => { - const newFilename = `${directory}\\${file.filename}`; - files[index] = { ...files[index], filename: newFilename }; - }); - - const newTree = this.state.tree; - newTree[name] = files; - this.setState({ tree: { ...newTree } }); + + // the api returns file names only, so we need to prepend the directory + // to make it look like a search result. we also need to preserve + // any file selections, so check the old files and assign accordingly + const fixedFiles = files.map(file => ({ + ...file, + filename: `${directory}\\${file.filename}`, + selected: oldFiles.find(f => f.filename === `${directory}\\${file.filename}`)?.selected ?? false, + })); + + oldTree[name] = fixedFiles; + this.setState({ tree: { ...oldTree } }); } catch (error) { console.error(error); toast.error(error?.response?.data ?? error?.message ?? error); |
