From 6b73712a56b2c8b70fca84adec20fc0a501e94e8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 11 Dec 2022 22:03:17 -0600 Subject: animate 'get directory' button, toast errors --- src/web/src/components/Search/Response.js | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/web') 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={} /> )} -- cgit v1.2.3