aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-27 08:06:09 -0500
committerJP Dillingham <jp@dillingham.me>2022-05-27 08:06:09 -0500
commitaaaf2053a016a664124f7208ba981af8fa181687 (patch)
tree46c9d1262ba83a647659dfcc8de4951321b0b9b5 /src
parentadcc26ed221085f0cabd827fbd6b06a85fdef12d (diff)
downloadslskd-aaaf2053a016a664124f7208ba981af8fa181687.tar.gz
move contents modal to a separate file
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/System/Shares/ContentsModal.js80
-rw-r--r--src/web/src/components/System/Shares/index.js85
2 files changed, 102 insertions, 63 deletions
diff --git a/src/web/src/components/System/Shares/ContentsModal.js b/src/web/src/components/System/Shares/ContentsModal.js
new file mode 100644
index 00000000..b9f0d86d
--- /dev/null
+++ b/src/web/src/components/System/Shares/ContentsModal.js
@@ -0,0 +1,80 @@
+import React, { useEffect, useState } from 'react';
+import { orderBy } from 'lodash';
+
+import { browse } from '../../../lib/shares';
+
+import {
+ Modal,
+ Button,
+ Icon,
+} from 'semantic-ui-react';
+
+import {
+ CodeEditor, LoaderSegment, Switch,
+} from '../../Shared';
+
+const ContentsModal = ({ share, onClose }) => {
+ const [loading, setLoading] = useState(true);
+ const [contents, setContents] = useState();
+
+ const { id, localPath, remotePath } = share || {};
+
+ useEffect(() => {
+ const fetch = async () => {
+ setLoading(true);
+
+ const contents = await browse({ id });
+
+ var directories = contents.map(directory => {
+ const lines = [directory.name.replace(remotePath, localPath)];
+
+ orderBy(directory.files, 'filename').forEach(file => {
+ lines.push('\t' + file.filename.replace(remotePath, ''));
+ });
+
+ lines.push('');
+
+ return lines.join('\n');
+ });
+
+ setContents(directories.join('\n'));
+ setLoading(false);
+ };
+
+ if (id) {
+ fetch();
+ } else {
+ setLoading(true);
+ setContents();
+ }
+ }, [id]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ return (
+ <Modal
+ size='large'
+ open={share}
+ onClose={onClose}
+ >
+ <Modal.Header><Icon name='folder'/>{localPath}</Modal.Header>
+ <Modal.Content scrolling className='share-ls-content'>
+ <Switch
+ loading={loading && <LoaderSegment className="modal-loader"/>}
+ >
+ <CodeEditor
+ style={{minHeight: 500}}
+ value={contents || ''}
+ basicSetup={false}
+ editable={false}
+ />
+ </Switch>
+ </Modal.Content>
+ <Modal.Actions>
+ <Button onClick={onClose}>
+ Close
+ </Button>
+ </Modal.Actions>
+ </Modal>
+ );
+};
+
+export default ContentsModal; \ No newline at end of file
diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js
index 6ede4cbc..8da95034 100644
--- a/src/web/src/components/System/Shares/index.js
+++ b/src/web/src/components/System/Shares/index.js
@@ -1,33 +1,29 @@
import React, { useState, useEffect } from 'react';
import { toast } from 'react-toastify';
-import { orderBy } from 'lodash';
import * as sharesLib from '../../../lib/shares';
import {
- CodeEditor,
- LoaderSegment,
- PlaceholderSegment,
+ LoaderSegment,
ShrinkableButton,
Switch,
+ Div,
} from '../../Shared';
-import Share from './Share';
+import ContentsModal from './ContentsModal';
import {
- Modal,
- Button,
Divider,
Table,
Icon,
} from 'semantic-ui-react';
import { Link } from 'react-router-dom';
-const Index = ({ state }) => {
+const Index = ({ state = {} } = {}) => {
const [loading, setLoading] = useState(true);
const [shares, setShares] = useState([]);
const [modal, setModal] = useState(false);
- const { filling, filled, faulted, fillProgress, directories, files, excludedDirectories } = state;
+ const { filling, filled, fillProgress } = state;
useEffect(() => {
getAll();
@@ -51,26 +47,6 @@ const Index = ({ state }) => {
}
};
- const browse = async (share) => {
- const { id, localPath, remotePath } = share;
- const contents = await sharesLib.browse({ id });
-
- var directories = contents.map(directory => {
- const lines = [directory.name.replace(remotePath, localPath)];
-
- orderBy(directory.files, 'filename').forEach(file => {
- console.log(file);
- lines.push('\t' + file.filename.replace(remotePath, ''));
- });
-
- 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);
@@ -81,7 +57,7 @@ const Index = ({ state }) => {
primary
icon='refresh'
loading={filling}
- disabled={filling}
+ disabled={filling || loading}
mediaQuery={'(max-width: 516px)'}
onClick={() => sharesLib.rescan()}
>{filling ? 'Scanning shares' : 'Rescan Shares'}</ShrinkableButton>
@@ -102,7 +78,7 @@ const Index = ({ state }) => {
</Table.Header>
<Table.Body>
{shared.map((share, index) => (<Table.Row key={index}>
- <Table.Cell onClick={() => browse(share)}>
+ <Table.Cell onClick={() => setModal(share)}>
<Icon name='folder'/>
<Link to='#'>{share.localPath}</Link>
</Table.Cell>
@@ -113,39 +89,22 @@ const Index = ({ state }) => {
</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>
+ <Div hidden={!excluded || excluded.length === 0}>
+ <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>
+ </Div>
</Switch>
- <Modal
- size='large'
- open={modal}
- onClose={() => setModal(false)}
- >
- <Modal.Header><Icon name='folder'/>{modal.localPath}</Modal.Header>
- <Modal.Content scrolling className='share-ls-content'>
- <CodeEditor
- style={{minHeight: 500}}
- value={modal.contents}
- basicSetup={false}
- editable={false}
- />
- </Modal.Content>
- <Modal.Actions>
- <Button onClick={() => setModal(false)}>
- Close
- </Button>
- </Modal.Actions>
- </Modal>
+ <ContentsModal share={modal} onClose={() => setModal(false)}/>
</>
);
};