aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-12-11 22:03:17 -0600
committerJP Dillingham <jp@dillingham.me>2022-12-11 22:03:17 -0600
commit6b73712a56b2c8b70fca84adec20fc0a501e94e8 (patch)
tree9f504c84cb6eea8da0d3f1501e005f67c82d9a9f /src/web
parentd10248b81126916733cc2a5a8e58b9e5d090bc1c (diff)
downloadslskd-6b73712a56b2c8b70fca84adec20fc0a501e94e8.tar.gz
animate 'get directory' button, toast errors
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Search/Response.js36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js
index fc3cb400..620900f9 100644
--- a/src/web/src/components/Search/Response.js
+++ b/src/web/src/components/Search/Response.js
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import * as transfers from '../../lib/transfers';
+import { toast } from 'react-toastify';
import { formatBytes, getDirectoryName } from '../../lib/util';
@@ -30,6 +31,7 @@ class Response extends Component {
tree: buildTree(this.props.response),
downloadRequest: undefined,
downloadError: '',
+ fetchingDirectoryContents: false,
isFolded: this.props.isInitiallyFolded,
};
@@ -61,15 +63,24 @@ class Response extends Component {
};
getFullDirectory = async (username, 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 } });
+ this.setState({ fetchingDirectoryContents: true });
+
+ try {
+ 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 } });
+ } catch (error) {
+ console.error(error);
+ toast.error(error?.response?.data ?? error?.message ?? error);
+ } finally {
+ this.setState({ fetchingDirectoryContents: false });
+ }
};
toggleFolded = () => {
@@ -80,7 +91,7 @@ class Response extends Component {
let {response} = this.props;
let free = response.hasFreeUploadSlot;
- let { tree, downloadRequest, downloadError, isFolded } = this.state;
+ let { tree, downloadRequest, downloadError, isFolded, fetchingDirectoryContents } = this.state;
let selectedFiles = Object.keys(tree)
.reduce((list, dict) => list.concat(tree[dict]), [])
@@ -121,9 +132,12 @@ class Response extends Component {
disabled={downloadRequest === 'inProgress'}
onSelectionChange={this.onFileSelectionChange}
footer={<button
+ disabled={fetchingDirectoryContents}
onClick={() => this.getFullDirectory(response.username, dir)}
style={{ cursor: 'pointer', width: '100%', backgroundColor: 'transparent', border: 'none' }}>
- <Icon name='folder'/>Get Full Directory Contents
+ <Icon
+ name={fetchingDirectoryContents ? 'circle notch' : 'folder'}
+ loading={fetchingDirectoryContents}/>Get Full Directory Contents
</button>}
/>
)}