aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/System/Shares/index.js122
1 files changed, 85 insertions, 37 deletions
diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js
index aa8db54a..ff054a97 100644
--- a/src/web/src/components/System/Shares/index.js
+++ b/src/web/src/components/System/Shares/index.js
@@ -1,31 +1,48 @@
import React, { useState, useEffect } from 'react';
import { toast } from 'react-toastify';
+import { orderBy } from 'lodash';
import * as sharesLib from '../../../lib/shares';
-import { LoaderSegment, PlaceholderSegment, ShrinkableButton, Switch } from '../../Shared';
+import {
+ CodeEditor,
+ LoaderSegment,
+ PlaceholderSegment,
+ ShrinkableButton,
+ Switch,
+} from '../../Shared';
+
import Share from './Share';
import {
Modal,
Button,
Divider,
+ Table,
+ Icon,
} from 'semantic-ui-react';
+import { Link } from 'react-router-dom';
const Index = ({ state }) => {
const [loading, setLoading] = useState(true);
const [shares, setShares] = useState([]);
- const [everything, setEverything] = useState();
const [modal, setModal] = useState(false);
+ const { filling, filled, faulted, fillProgress, directories, files, excludedDirectories } = state;
+
useEffect(() => {
getAll();
}, []);
+ useEffect(() => {
+ if (filled) {
+ getAll();
+ }
+ }, [filled]);
+
const getAll = async () => {
try {
setLoading(true);
setShares(await sharesLib.getAll());
- setLoading(false);
} catch (error) {
console.error(error);
toast.error(error?.response?.data ?? error?.message ?? error);
@@ -34,20 +51,28 @@ const Index = ({ state }) => {
}
};
- const browse = async ({ id }) => {
- setEverything(await sharesLib.browse({ id }));
- setModal(true);
- };
+ const browse = async (share) => {
+ const { id, localPath, remotePath } = share;
+ const contents = await sharesLib.browse({ id });
- const rescan = async () => {
- await sharesLib.rescan();
- };
+ var directories = contents.map(directory => {
+ const lines = [directory.name.replace(remotePath, localPath)];
- if (loading) {
- return LoaderSegment;
- }
+ orderBy(directory.files, 'filename').forEach(file => {
+ console.log(file);
+ lines.push('\t' + file.filename.replace(remotePath, ''));
+ });
- const { filling, filled, faulted, fillProgress, directories, files, excludedDirectories } = state;
+ lines.push('');
+
+ return lines.join('\n');
+ });
+
+ setModal({ id, localPath, remotePath, contents: directories.join('\n') });
+ };
+
+ const shared = shares.filter(share => !share.isExcluded);
+ const excluded = shares.filter(share => share.isExcluded);
return (
<>
@@ -58,42 +83,65 @@ const Index = ({ state }) => {
loading={filling}
disabled={filling}
mediaQuery={'(max-width: 516px)'}
- onClick={rescan}
+ onClick={() => sharesLib.rescan()}
>{filling ? 'Scanning shares' : 'Rescan Shares'}</ShrinkableButton>
</div>
<Divider/>
<Switch
- filling={filling && <PlaceholderSegment loading caption={fillProgress}/>}
+ filling={loading && <LoaderSegment caption={fillProgress}/>}
>
- <div className='view-code-container'>
- <ol>
- {shares.map(share => (
- <Share share={share} onBrowse={() => browse({ id: share.id })}/>
- ))}
- </ol>
- <pre>
- {JSON.stringify(state, null, 2)}
- </pre>
- </div>
+ <Table size='large'>
+ <Table.Header>
+ <Table.Row>
+ <Table.HeaderCell>Local Path</Table.HeaderCell>
+ <Table.HeaderCell style={{width: 110}}>Directories</Table.HeaderCell>
+ <Table.HeaderCell style={{width: 110}}>Files</Table.HeaderCell>
+ <Table.HeaderCell>Alias</Table.HeaderCell>
+ <Table.HeaderCell>Remote Path</Table.HeaderCell>
+ </Table.Row>
+ </Table.Header>
+ <Table.Body>
+ {shared.map((share, index) => (<Table.Row key={index}>
+ <Table.Cell onClick={() => browse(share)}>
+ <Icon name='folder'/>
+ <Link to='#'>{share.localPath}</Link>
+ </Table.Cell>
+ <Table.Cell>{share.directories}</Table.Cell>
+ <Table.Cell>{share.files}</Table.Cell>
+ <Table.Cell>{share.alias}</Table.Cell>
+ <Table.Cell>{share.remotePath}</Table.Cell>
+ </Table.Row>))}
+ </Table.Body>
+ </Table>
+ <Table size='large'>
+ <Table.Header>
+ <Table.Row>
+ <Table.HeaderCell>Excluded Paths</Table.HeaderCell>
+ </Table.Row>
+ </Table.Header>
+ <Table.Body>
+ {excluded.map((share, index) => (<Table.Row key={index}>
+ <Table.Cell><Icon name='x' color='red'/>{share.localPath}</Table.Cell>
+ </Table.Row>))}
+ </Table.Body>
+ </Table>
</Switch>
<Modal
size='large'
open={modal}
onClose={() => setModal(false)}
- style={{ color: 'red' }}
>
- <Modal.Header>Delete Your Account</Modal.Header>
- <Modal.Content scrolling>
- <pre>
- {JSON.stringify(everything, null, 2)}
- </pre>
+ <Modal.Header><Icon name='folder'/>{modal.localPath}</Modal.Header>
+ <Modal.Content scrolling className='share-ls-content'>
+ <CodeEditor
+ value={modal.contents}
+ basicSetup={false}
+ editable={false}
+ />
</Modal.Content>
<Modal.Actions>
- <Button negative onClick={() => setModal(false)}>
- No
- </Button>
- <Button positive onClick={() => setModal(false)}>
- Yes
+ <Button onClick={() => setModal(false)}>
+ Close
</Button>
</Modal.Actions>
</Modal>