aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-09-25 14:22:01 -0500
committerJP Dillingham <jp@dillingham.me>2022-09-25 14:22:01 -0500
commit374df66d4cc4f9f55a2a0a3e69b50260525060ce (patch)
tree5df7389cab68bc7b0051235411d39be63ea9727c /src/web
parent2150d2dd4df17767533f4298c9a9368dba500c25 (diff)
downloadslskd-374df66d4cc4f9f55a2a0a3e69b50260525060ce.tar.gz
add a button to cancel a scan, show files and folder counts
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/System/Shares/index.js81
-rw-r--r--src/web/src/components/System/System.css5
2 files changed, 69 insertions, 17 deletions
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 = () => <ShrinkableButton
+ primary={!scanPending}
+ color={scanPending ? 'yellow' : undefined}
+ icon='refresh'
+ loading={working}
+ disabled={working}
+ mediaQuery={'(max-width: 516px)'}
+ onClick={() => rescan()}
+ >Rescan Shares</ShrinkableButton>;
+
+ const CancelButton = () => <ShrinkableButton
+ color='red'
+ icon='x'
+ disabled={working}
+ mediaQuery={'(max-width: 516px)'}
+ onClick={() => cancel()}
+ >Cancel Scan</ShrinkableButton>;
+
const shared = shares.filter(share => !share.isExcluded);
const excluded = shares.filter(share => share.isExcluded);
return (
<>
- <div className="header-buttons">
- <ShrinkableButton
- primary={!scanPending}
- color={scanPending ? 'yellow' : undefined}
- icon='refresh'
- loading={scanning}
- disabled={scanning || loading}
- mediaQuery={'(max-width: 516px)'}
- onClick={() => sharesLib.rescan()}
- >{scanning ? 'Scanning shares' : 'Rescan Shares'}</ShrinkableButton>
- </div>
- <Divider/>
<Switch
- filling={(loading || scanning) && <LoaderSegment>{Math.round(scanProgress * 100)}%</LoaderSegment>}
+ loading={loading && <LoaderSegment/>}
>
- <ShareTable shares={shared} onClick={setModal}/>
- <ExclusionTable exclusions={excluded}/>
+ <div className="header-buttons">
+ <Switch
+ scanning={scanning && <CancelButton/>}
+ >
+ <ScanButton/>
+ </Switch>
+ </div>
+ <Divider/>
+ <Switch
+ filling={scanning && <LoaderSegment>
+ <div>
+ <div>{Math.round(scanProgress * 100)}%</div>
+ <div className='share-scan-detail'>Found {files} files in {directories} directories</div>
+ </div></LoaderSegment>}
+ >
+ <ShareTable shares={shared} onClick={setModal}/>
+ <ExclusionTable exclusions={excluded}/>
+ </Switch>
+ <ContentsModal share={modal} onClose={() => setModal(false)}/>
</Switch>
- <ContentsModal share={modal} onClose={() => 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