From aaaf2053a016a664124f7208ba981af8fa181687 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 27 May 2022 08:06:09 -0500 Subject: move contents modal to a separate file --- .../src/components/System/Shares/ContentsModal.js | 80 ++++++++++++++++++++ src/web/src/components/System/Shares/index.js | 85 ++++++---------------- 2 files changed, 102 insertions(+), 63 deletions(-) create mode 100644 src/web/src/components/System/Shares/ContentsModal.js (limited to 'src') 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 ( + + {localPath} + + } + > + + + + + + + + ); +}; + +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'} @@ -102,7 +78,7 @@ const Index = ({ state }) => { {shared.map((share, index) => ( - browse(share)}> + setModal(share)}> {share.localPath} @@ -113,39 +89,22 @@ const Index = ({ state }) => { ))} - - - - Excluded Paths - - - - {excluded.map((share, index) => ( - {share.localPath} - ))} - -
+ - setModal(false)} - > - {modal.localPath} - - - - - - - + setModal(false)}/> ); }; -- cgit v1.2.3