From 2150d2dd4df17767533f4298c9a9368dba500c25 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Sep 2022 13:57:40 -0500 Subject: add cancel function --- src/web/src/lib/shares.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/web') diff --git a/src/web/src/lib/shares.js b/src/web/src/lib/shares.js index 03fac7d6..c400e08e 100644 --- a/src/web/src/lib/shares.js +++ b/src/web/src/lib/shares.js @@ -20,4 +20,8 @@ export const browse = async ({ id } = {}) => { export const rescan = async () => { return (await api.put('/shares')).data; +}; + +export const cancel = async () => { + return (await api.delete('/shares')).data; }; \ No newline at end of file -- cgit v1.2.3 From 374df66d4cc4f9f55a2a0a3e69b50260525060ce Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Sep 2022 14:22:01 -0500 Subject: add a button to cancel a scan, show files and folder counts --- src/web/src/components/System/Shares/index.js | 81 +++++++++++++++++++++------ src/web/src/components/System/System.css | 5 ++ 2 files changed, 69 insertions(+), 17 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js index ceb5746c..6759ad6f 100644 --- a/src/web/src/components/System/Shares/index.js +++ b/src/web/src/components/System/Shares/index.js @@ -19,10 +19,11 @@ import ShareTable from './ShareTable'; const Index = ({ state = {} } = {}) => { const [loading, setLoading] = useState(true); + const [working, setWorking] = useState(false); const [shares, setShares] = useState([]); const [modal, setModal] = useState(false); - const { scanning, scanProgress, scanPending } = state; + const { scanning, scanProgress, scanPending, directories, files } = state; const scanned = !scanning; useEffect(() => { @@ -47,30 +48,76 @@ const Index = ({ state = {} } = {}) => { } }; + const rescan = async () => { + try { + setWorking(true); + await sharesLib.rescan(); + } catch (error) { + console.error(error); + toast.error(error?.response?.data ?? error?.message ?? error); + } finally { + setWorking(false); + } + }; + + const cancel = async () => { + try { + setWorking(true); + await sharesLib.cancel(); + } catch (error) { + console.error(error); + toast.error(error?.response?.data ?? error?.message ?? error ?? 'Failed to cancel the scan'); + } finally { + setWorking(false); + } + }; + + const ScanButton = () => rescan()} + >Rescan Shares; + + const CancelButton = () => cancel()} + >Cancel Scan; + const shared = shares.filter(share => !share.isExcluded); const excluded = shares.filter(share => share.isExcluded); return ( <> -
- sharesLib.rescan()} - >{scanning ? 'Scanning shares' : 'Rescan Shares'} -
- {Math.round(scanProgress * 100)}%} + loading={loading && } > - - +
+ } + > + + +
+ + +
+
{Math.round(scanProgress * 100)}%
+
Found {files} files in {directories} directories
+
} + > + + +
+ setModal(false)}/> - setModal(false)}/> ); }; diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index a8e9cb8e..a463ab08 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -62,4 +62,9 @@ .share-count-column { width: 110px; +} + +.share-scan-detail { + margin-top: 10px; + font-size: 14px; } \ No newline at end of file -- cgit v1.2.3