diff options
Diffstat (limited to 'src/web')
26 files changed, 718 insertions, 232 deletions
diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css index e0935163..78b029b8 100644 --- a/src/web/src/components/App.css +++ b/src/web/src/components/App.css @@ -101,10 +101,23 @@ body { line-height: 1.15 !important; } -.placeholder-segment { +.placeholder-segment, .placeholder-segment-small { opacity: .25; } +.placeholder-segment-small { + min-height: 6rem !important; +} + +.placeholder-segment-small > .ui.icon.header { + font-size: 1em !important; +} + +.placeholder-segment-small > .ui.icon.header > i { + font-size: 2em !important; +} + + .menu-icon-group { font-size: 1.71428571em !important; margin: 0 auto .5rem !important; @@ -120,7 +133,7 @@ body { background-color: transparent !important; } -.page { +.view { padding-left: 15px; padding-right: 15px; max-width: 1200px !important; @@ -128,6 +141,15 @@ body { margin-right: auto !important; } -.page:last-child { +.view:last-child { margin-bottom: 17px; +} + +/* https://github.com/Semantic-Org/Semantic-UI-React/issues/3133#issuecomment-418766748 */ +.ui.dimmer .ui.modal-loader.loader:before { + border-color: rgba(0,0,0,.1); +} + +.ui.dimmer .ui.modal-loader.loader:after { + border-color: #767676 transparent transparent; }
\ No newline at end of file diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 09039442..206cea34 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -116,8 +116,9 @@ class App extends Component { render = () => { const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state; - const { version = {}, server } = applicationState; + const { version = {}, server, pendingReconnect, pendingRestart, shares = {} } = applicationState; const { isUpdateAvailable, current, latest } = version; + const { scanPending: pendingShareRescan } = shares; if (!initialized) { return <Loader active size='big'/>; @@ -202,7 +203,7 @@ class App extends Component { {server?.isConnected && <Menu.Item onClick={() => disconnect()} > - <Icon name='plug' color='green'/>Connected + <Icon name='plug' color={pendingReconnect ? 'yellow' : 'green'}/>Connected </Menu.Item>} {(!server?.isConnected) && <Menu.Item onClick={() => connect()} @@ -212,6 +213,13 @@ class App extends Component { <Icon name='close' color='red' corner='bottom right' className='menu-icon-no-shadow'/> </Icon.Group>Disconnected </Menu.Item>} + {(pendingReconnect || pendingRestart || pendingShareRescan) && <Menu.Item position='right'> + <Icon.Group className='menu-icon-group'> + <Link to={`${urlBase}/system/info`}> + <Icon name='exclamation circle' color='yellow'/> + </Link> + </Icon.Group>Pending Action + </Menu.Item>} {isUpdateAvailable && <Modal trigger={<Menu.Item position='right'> <Icon.Group className='menu-icon-group'> @@ -260,7 +268,7 @@ class App extends Component { <AppContext.Provider value={{ state: applicationState, options: applicationOptions }}> <Switch> <Route path={`${urlBase}/searches/:id?`} render={(props) => - this.withTokenCheck(<div className='page'> + this.withTokenCheck(<div className='view'> <Searches server={applicationState.server} {...props} @@ -273,11 +281,11 @@ class App extends Component { <Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> <Route path={`${urlBase}/uploads`} render={ (props) => - this.withTokenCheck(<div className='page'><Transfers {...props} direction='upload'/></div>) + this.withTokenCheck(<div className='view'><Transfers {...props} direction='upload'/></div>) }/> <Route path={`${urlBase}/downloads`} render={ (props) => - this.withTokenCheck(<div className='page'> + this.withTokenCheck(<div className='view'> <Transfers {...props} direction='download' server={applicationState.server}/> </div>) }/> diff --git a/src/web/src/components/Browse/Browse.js b/src/web/src/components/Browse/Browse.js index e1a3c7f0..93cf31f0 100644 --- a/src/web/src/components/Browse/Browse.js +++ b/src/web/src/components/Browse/Browse.js @@ -90,7 +90,7 @@ class Browse extends Component { try { localStorage.setItem('soulseek-example-browse-state', lzString.compress(JSON.stringify(this.state))); } catch (error) { - console.log(error); + console.error(error); } }; diff --git a/src/web/src/components/Search/Detail/SearchDetailHeader.js b/src/web/src/components/Search/Detail/SearchDetailHeader.js index ac613249..2071540f 100644 --- a/src/web/src/components/Search/Detail/SearchDetailHeader.js +++ b/src/web/src/components/Search/Detail/SearchDetailHeader.js @@ -63,11 +63,11 @@ const SearchDetailHeader = ({ // if the screen is less than 684 pixels, display the action buttons in a new segment, with full text. return ( <> - <Segment className='search-segment' raised> - <Header className='search-detail-header'> + <Segment className='search-detail-header-segment' raised> + <Header> <SearchStatusIcon state={state}/>{searchText} </Header> - {!isTinyScreen && <div className='search-detail-action-button'> + {!isTinyScreen && <div className='search-detail-header-buttons'> <RefreshButton/> <StopOrDeleteButton/> </div>} diff --git a/src/web/src/components/Search/List/SearchList.js b/src/web/src/components/Search/List/SearchList.js index db16fa71..11cfcb22 100644 --- a/src/web/src/components/Search/List/SearchList.js +++ b/src/web/src/components/Search/List/SearchList.js @@ -9,7 +9,6 @@ import { Table, Icon, Loader, - List, } from 'semantic-ui-react'; const SearchList = ({ @@ -27,33 +26,29 @@ const SearchList = ({ connecting={connecting && <Loader active inline='centered' size='small'/>} error={error && <ErrorSegment caption={error} />} > - <List> - <List.Item> - <Table size='large'> - <Table.Header> - <Table.Row> - <Table.HeaderCell className="search-list-action"><Icon name="info circle"/></Table.HeaderCell> - <Table.HeaderCell className="search-list-phrase">Search</Table.HeaderCell> - <Table.HeaderCell className="search-list-files">Files</Table.HeaderCell> - <Table.HeaderCell className="search-list-locked">Locked</Table.HeaderCell> - <Table.HeaderCell className="search-list-responses">Responses</Table.HeaderCell> - <Table.HeaderCell className="search-list-started">Ended</Table.HeaderCell> - <Table.HeaderCell className="search-list-action"></Table.HeaderCell> - </Table.Row> - </Table.Header> - <Table.Body> - {Object.values(searches) - .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt))) - .map((search, index) => <SearchListRow - search={search} - key={index} - onRemove={onRemove} - onStop={onStop} - />)} - </Table.Body> - </Table> - </List.Item> - </List> + <Table size='large'> + <Table.Header> + <Table.Row> + <Table.HeaderCell className="search-list-action"><Icon name="info circle"/></Table.HeaderCell> + <Table.HeaderCell className="search-list-phrase">Search</Table.HeaderCell> + <Table.HeaderCell className="search-list-files">Files</Table.HeaderCell> + <Table.HeaderCell className="search-list-locked">Locked</Table.HeaderCell> + <Table.HeaderCell className="search-list-responses">Responses</Table.HeaderCell> + <Table.HeaderCell className="search-list-started">Ended</Table.HeaderCell> + <Table.HeaderCell className="search-list-action"></Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + {Object.values(searches) + .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt))) + .map((search, index) => <SearchListRow + search={search} + key={index} + onRemove={onRemove} + onStop={onStop} + />)} + </Table.Body> + </Table> </Switch> </div> </Card.Content> diff --git a/src/web/src/components/Search/Search.css b/src/web/src/components/Search/Search.css index f66a3bc7..ca31d308 100644 --- a/src/web/src/components/Search/Search.css +++ b/src/web/src/components/Search/Search.css @@ -105,12 +105,19 @@ width: 5px !important; } -.search-detail-header { +.search-detail-header-segment { + margin-top: 15px !important; + height: 78px !important; + padding-top: 20px !important; + display: flex; +} + +.search-detail-header-segment > .header { font-weight: normal !important; - margin-top: 12px !important; + margin-top: 8px !important; } -.search-detail-action-button { - float: right; - margin-top: -48px !important; +.search-detail-header-buttons { + display: inline; + margin-left: auto; }
\ No newline at end of file diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js index fdcda3ac..fb0ce027 100644 --- a/src/web/src/components/Search/Searches.js +++ b/src/web/src/components/Search/Searches.js @@ -91,8 +91,7 @@ const Searches = ({ server }) => { return () => { searchHub.stop(); }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, []); // eslint-disable-line react-hooks/exhaustive-deps // create a new search, and optionally navigate to it to display the details // we do this if the user clicks the search icon, or repeats an existing search diff --git a/src/web/src/components/Shared/PlaceholderSegment.js b/src/web/src/components/Shared/PlaceholderSegment.js index 0307b9e0..31ac8e9e 100644 --- a/src/web/src/components/Shared/PlaceholderSegment.js +++ b/src/web/src/components/Shared/PlaceholderSegment.js @@ -2,13 +2,16 @@ import React from 'react'; import { Segment, Header, Icon } from 'semantic-ui-react'; -const PlaceholderSegment = ({ icon, caption, ...rest }) => ( - <Segment className='placeholder-segment' placeholder basic {...rest}> - <Header icon> - <Icon name={icon}/> - {caption} - </Header> - </Segment> -); +const PlaceholderSegment = ({ icon, caption, size, ...rest }) => { + const className = size === 'small' ? 'placeholder-segment-small' : 'placeholder-segment'; + + return ( + <Segment className={className} placeholder basic {...rest}> + <Header icon> + <Icon name={icon}/> + {caption} + </Header> + </Segment>); +}; export default PlaceholderSegment;
\ No newline at end of file diff --git a/src/web/src/components/Shared/ShrinkableButton.js b/src/web/src/components/Shared/ShrinkableButton.js index 2f736ade..67c9f660 100644 --- a/src/web/src/components/Shared/ShrinkableButton.js +++ b/src/web/src/components/Shared/ShrinkableButton.js @@ -3,13 +3,13 @@ import React from 'react'; import { useMediaQuery } from 'react-responsive'; import { Button, Icon, Popup } from 'semantic-ui-react'; -const ShrinkableButton = ({ icon, mediaQuery, children, ...rest }) => { +const ShrinkableButton = ({ icon, loading, mediaQuery, children, ...rest }) => { const shouldShrink = useMediaQuery({ query: mediaQuery }); if (!shouldShrink) { return ( <Button {...rest}> - <Icon name={icon}/> + <Icon name={icon} loading={loading}/> {children} </Button> ); @@ -20,7 +20,7 @@ const ShrinkableButton = ({ icon, mediaQuery, children, ...rest }) => { content={children} trigger={ <Button icon {...rest}> - <Icon name={icon}/> + <Icon name={icon} loading={loading}/> </Button> } /> diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info/index.js index d9ce8813..7068e047 100644 --- a/src/web/src/components/System/Info.js +++ b/src/web/src/components/System/Info/index.js @@ -1,30 +1,37 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import YAML from 'yaml'; -import { restart, shutdown, getVersion } from '../../lib/application'; +import { restart, shutdown, getVersion } from '../../../lib/application'; -import { Modal, Header } from 'semantic-ui-react'; -import CodeEditor from '../Shared/CodeEditor'; -import ShrinkableButton from '../Shared/ShrinkableButton'; +import { Modal, Header, Divider } from 'semantic-ui-react'; + +import { + CodeEditor, + LoaderSegment, + ShrinkableButton, + Switch, +} from '../../Shared'; const Info = ({ state }) => { - const stateAsYaml = YAML.stringify(state, { simpleKeys: true, sortMapEntries: true }); + const [contents, setContents] = useState(); + + useEffect(() => { + setTimeout(() => { + setContents(YAML.stringify(state, { simpleKeys: true, sortMapEntries: true })); + }, 250); + }, [state]); + + const { pendingRestart } = state; return ( <> - <div className='view-code-container'> - <CodeEditor - value={stateAsYaml} - basicSetup={false} - editable={false} - /> - </div> - <div className='footer-buttons'> + <div className='header-buttons'> <div style={{float: 'left'}}> <ShrinkableButton icon='refresh' mediaQuery='(max-width: 516px)' primary + disabled={!contents} onClick={() => getVersion({ forceCheck: true })} > Check for Updates @@ -36,6 +43,7 @@ const Info = ({ state }) => { icon='shutdown' mediaQuery='(max-width: 516px)' negative + disabled={!contents} > Shut Down </ShrinkableButton> @@ -51,7 +59,9 @@ const Info = ({ state }) => { <ShrinkableButton icon='redo' mediaQuery='(max-width: 516px)' - negative + negative={!pendingRestart} + color={pendingRestart ? 'yellow' : undefined} + disabled={!contents} > Restart </ShrinkableButton> @@ -63,6 +73,16 @@ const Info = ({ state }) => { actions={['Cancel', { key: 'done', content: 'Restart', negative: true, onClick: restart }]} /> </div> + <Divider/> + <Switch + loading={!contents && <LoaderSegment/>} + > + <CodeEditor + value={contents} + basicSetup={false} + editable={false} + /> + </Switch> </> ); }; diff --git a/src/web/src/components/System/Logs.js b/src/web/src/components/System/Logs/index.js index 4a118414..b30b0a43 100644 --- a/src/web/src/components/System/Logs.js +++ b/src/web/src/components/System/Logs/index.js @@ -1,9 +1,10 @@ import React, { Component } from 'react'; -import { Table, Loader, Dimmer } from 'semantic-ui-react'; +import { Table } from 'semantic-ui-react'; -import { createLogsHubConnection } from '../../lib/hubFactory'; +import { createLogsHubConnection } from '../../../lib/hubFactory'; +import { LoaderSegment } from '../../Shared'; -import './System.css'; +import '../System.css'; const initialState = { logs: [], @@ -50,7 +51,7 @@ class Logs extends Component { return ( <div className='logs'> - {!connected && <Dimmer active inverted><Loader inverted/></Dimmer>} + {!connected && <LoaderSegment/>} {connected && <Table compact='very' className='logs-table'> <Table.Header> diff --git a/src/web/src/components/System/Options/DebugModal.js b/src/web/src/components/System/Options/DebugModal.js new file mode 100644 index 00000000..21514c57 --- /dev/null +++ b/src/web/src/components/System/Options/DebugModal.js @@ -0,0 +1,66 @@ +import React, { useState, useEffect } from 'react'; +import { toast } from 'react-toastify'; + +import { + Modal, + Button, + Icon, +} from 'semantic-ui-react'; + +import { getCurrentDebugView } from '../../../lib/options'; +import { CodeEditor, PlaceholderSegment, Switch } from '../../Shared'; + +const DebugModal = ({ open, onClose }) => { + const [loading, setLoading] = useState(true); + const [debugView, setDebugView] = useState(); + + useEffect(() => { + if (open) { + get(); + } + }, [open]); + + const get = async () => { + setLoading(true); + + try { + setDebugView(await getCurrentDebugView()); + } catch (error) { + console.error(error); + toast.error(error?.response?.data ?? error?.message ?? error); + } finally { + setLoading(false); + } + }; + + return ( + <Modal + size='large' + open={open} + onClose={onClose} + > + <Modal.Header> + <Icon name='bug'/> + Options (Debug View) + </Modal.Header> + <Modal.Content className='debug-view-content' scrolling> + <Switch + loading={loading && <PlaceholderSegment loading={true} />} + > + <CodeEditor + style={{minHeight: 500}} + value={debugView} + basicSetup={false} + editable={false} + /> + </Switch> + </Modal.Content> + <Modal.Actions> + <Button onClick={onClose}> + Close + </Button> + </Modal.Actions> + </Modal>); +}; + +export default DebugModal;
\ No newline at end of file diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js deleted file mode 100644 index f9657022..00000000 --- a/src/web/src/components/System/Options/Edit.js +++ /dev/null @@ -1,87 +0,0 @@ -import React, { useState, useEffect } from 'react'; - -import { Button, Icon, Message } from 'semantic-ui-react'; -import CodeEditor from '../../Shared/CodeEditor'; - -import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options'; -import PlaceholderSegment from '../../Shared/PlaceholderSegment'; - -const Edit = ({ cancelAction }) => { - const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); - const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); - const [yamlError, setYamlError] = useState(); - const [updateError, setUpdateError] = useState(); - - useEffect(() => { - get(); - }, []); - - const get = async () => { - setLoading({ loading: true, error: false }); - - try { - const [location, yaml] = await Promise.all([getYamlLocation(), getYaml()]); - - setYaml({ location, yaml, isDirty: false }); - setLoading({ loading: false, error: false }); - } catch (error) { - setLoading({ loading: false, error: error.message }); - } - }; - - const update = async (yaml) => { - setYaml({ location, yaml, isDirty: true }); - validate(yaml); - }; - - const validate = async (yaml) => { - const response = await validateYaml({ yaml }); - setYamlError(response); - }; - - const save = async (yaml) => { - await validate(yaml); - - if (!yamlError) { - try { - await updateYaml({ yaml }); - cancelAction(); - } - catch (error) { - setUpdateError(error.response.data); - } - } - }; - - if (loading) { - return <PlaceholderSegment loading={true}/>; - } - - if (error) { - return <PlaceholderSegment icon='close'/>; - } - - return ( - <> - <Message className='no-grow' warning> - <Icon name='warning sign'/>Editing {location} - </Message> - <div - {...{ className: (yamlError || updateError) ? 'edit-code-container-error' : 'edit-code-container' }} - > - <CodeEditor - value={yaml} - onChange={(value) => update(value)} - /> - </div> - {(yamlError || updateError) && - <Message className='no-grow' negative><Icon name='x' />{(yamlError ?? '') + (updateError ?? '')}</Message>} - <div className='footer-buttons'> - <Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button> - <Button negative onClick={() => cancelAction()}><Icon name='close'/>Cancel</Button> - </div> - </> - ); -}; - -export default Edit;
\ No newline at end of file diff --git a/src/web/src/components/System/Options/EditModal.js b/src/web/src/components/System/Options/EditModal.js new file mode 100644 index 00000000..d435bfd8 --- /dev/null +++ b/src/web/src/components/System/Options/EditModal.js @@ -0,0 +1,105 @@ +import React, { useState, useEffect } from 'react'; + +import { Button, Icon, Message, Modal } from 'semantic-ui-react'; +import CodeEditor from '../../Shared/CodeEditor'; + +import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options'; +import { + PlaceholderSegment, + Switch, + Div, +} from '../../Shared'; + +const EditModal = ({ open, onClose }) => { + const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); + const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); + const [yamlError, setYamlError] = useState(); + const [updateError, setUpdateError] = useState(); + + useEffect(() => { + if (open) { + get(); + } + }, [open]); + + const get = async () => { + setLoading({ loading: true, error: false }); + + try { + const [location, yaml] = await Promise.all([getYamlLocation(), getYaml()]); + + setYaml({ location, yaml, isDirty: false }); + setLoading({ loading: false, error: false }); + } catch (error) { + setLoading({ loading: false, error: error.message }); + } + }; + + const update = async (yaml) => { + setYaml({ location, yaml, isDirty: true }); + validate(yaml); + }; + + const validate = async (yaml) => { + const response = await validateYaml({ yaml }); + setYamlError(response); + }; + + const save = async (yaml) => { + await validate(yaml); + + if (!yamlError) { + try { + await updateYaml({ yaml }); + onClose(); + } + catch (error) { + setUpdateError(error.response.data); + } + } + }; + + return ( + <Modal + size='large' + open={open} + onClose={onClose} + > + <Modal.Header> + <Icon name='edit'/> + Edit Options + <Div hidden={loading}> + <Message className='no-grow edit-code-header' warning> + <Icon name='warning sign'/>Editing {location} + </Message> + </Div> + </Modal.Header> + <Modal.Content className='edit-code-content' scrolling> + <Switch + loading={loading && <PlaceholderSegment loading={true}/>} + error={error && <PlaceholderSegment icon='close'/>} + > + <div + {...{ className: (yamlError || updateError) ? 'edit-code-container-error' : 'edit-code-container' }} + > + <CodeEditor + style={{minHeight: 500}} + value={yaml} + onChange={(value) => update(value)} + /> + </div> + </Switch> + </Modal.Content> + <Modal.Actions> + {(yamlError || updateError) && + <Message className='no-grow left-align' negative> + <Icon name='x' />{(yamlError ?? '') + (updateError ?? '')} + </Message>} + <Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button> + <Button negative onClick={onClose}><Icon name='close'/>Cancel</Button> + </Modal.Actions> + </Modal> + ); +}; + +export default EditModal;
\ No newline at end of file diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js deleted file mode 100644 index 9d4d7635..00000000 --- a/src/web/src/components/System/Options/View.js +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import YAML from 'yaml'; - -import { Icon, Button } from 'semantic-ui-react'; -import CodeEditor from '../../Shared/CodeEditor'; - -const View = ({ options, editAction }) => { - const { remoteConfiguration } = options; - - const optionsAsYaml = YAML.stringify(options, { simpleKeys: true, sortMapEntries: true }); - - return ( - <> - <div className='view-code-container'> - <CodeEditor - value={optionsAsYaml} - basicSetup={false} - editable={false} - /> - </div> - <div className='footer-buttons'> - {remoteConfiguration ? - <Button primary onClick={() => editAction()}><Icon name='edit'/>Edit</Button> : - <Button disabled icon='x'><Icon name='lock'/>Remote Configuration Disabled</Button>} - </div> - </> - ); -}; - -export default View;
\ No newline at end of file diff --git a/src/web/src/components/System/Options/index.js b/src/web/src/components/System/Options/index.js index 92535b95..16928a29 100644 --- a/src/web/src/components/System/Options/index.js +++ b/src/web/src/components/System/Options/index.js @@ -1,16 +1,87 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; +import YAML from 'yaml'; -import Edit from './Edit'; -import View from './View'; +import DebugModal from './DebugModal'; +import EditModal from './EditModal'; + +import { Divider } from 'semantic-ui-react'; +import { + CodeEditor, + LoaderSegment, + ShrinkableButton, + Switch, +} from '../../Shared'; const Index = ({ options }) => { - const [mode, setMode] = useState('view'); + const [debugModal, setDebugModal] = useState(false); + const [editModal, setEditModal] = useState(false); + const [contents, setContents] = useState(); + + useEffect(() => { + setTimeout(() => { + setContents(YAML.stringify(options, { simpleKeys: true, sortMapEntries: true })); + }, 250); + }, [options]); + + const { remoteConfiguration, debug } = options; + + const DebugButton = ({ ...props }) => { + if (!debug) return <></>; + + return <ShrinkableButton + icon='bug' + mediaQuery='(max-width: 516px)' + onClick={() => setDebugModal(true)} + {...props} + > + Debug View + </ShrinkableButton>; + }; + + const EditButton = ({ ...props }) => { + if (!remoteConfiguration) { + return <ShrinkableButton + disabled + icon='lock' + mediaQuery='(max-width: 516px)' + >Remote Configuration Disabled</ShrinkableButton>; + } - if (mode === 'edit') { - return <Edit cancelAction={() => setMode('view')}/>; - } + return <ShrinkableButton + primary + icon='edit' + mediaQuery='(max-width: 516px)' + onClick={() => setEditModal(true)} + {...props} + >Edit</ShrinkableButton>; + }; - return <View options={options} editAction={() => setMode('edit')}/>; + return ( + <> + <div className='header-buttons'> + <DebugButton disabled={!contents}/> + <EditButton disabled={!contents}/> + </div> + <Divider/> + <Switch + loading={!contents && <LoaderSegment/>} + > + <CodeEditor + value={contents} + basicSetup={false} + editable={false} + /> + </Switch> + <DebugModal + open={debugModal} + onClose={() => setDebugModal(false)} + /> + <EditModal + open={editModal} + onClose={() => setEditModal(false)} + /> + </> + ); }; export default Index;
\ No newline at end of file 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/ExclusionTable.js b/src/web/src/components/System/Shares/ExclusionTable.js new file mode 100644 index 00000000..5e010e30 --- /dev/null +++ b/src/web/src/components/System/Shares/ExclusionTable.js @@ -0,0 +1,35 @@ +import React from 'react'; + +import { + Table, + Icon, +} from 'semantic-ui-react'; + +import { Switch } from '../../Shared'; + +const ExclusionTable = ({ exclusions = [] } = {}) => { + return ( + <Table> + <Table.Header> + <Table.Row> + <Table.HeaderCell>Excluded Paths</Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + <Switch + empty={exclusions.length === 0 && <Table.Row> + <Table.Cell style={{ opacity: .5, padding: '10px !important', textAlign: 'center' }}> + No exclusions configured + </Table.Cell> + </Table.Row>} + > + {exclusions.map((share, index) => (<Table.Row key={index}> + <Table.Cell><Icon name='x' color='red'/>{share.localPath}</Table.Cell> + </Table.Row>))} + </Switch> + </Table.Body> + </Table> + ); +}; + +export default ExclusionTable;
\ No newline at end of file diff --git a/src/web/src/components/System/Shares/ShareTable.js b/src/web/src/components/System/Shares/ShareTable.js new file mode 100644 index 00000000..d264fc8f --- /dev/null +++ b/src/web/src/components/System/Shares/ShareTable.js @@ -0,0 +1,47 @@ +import React from 'react'; + +import { + Table, + Icon, +} from 'semantic-ui-react'; + +import { Link } from 'react-router-dom'; +import { Switch } from '../../Shared'; + +const ShareTable = ({ shares, onClick }) => { + return ( + <Table> + <Table.Header> + <Table.Row> + <Table.HeaderCell>Local Path</Table.HeaderCell> + <Table.HeaderCell className='share-count-column'>Directories</Table.HeaderCell> + <Table.HeaderCell className='share-count-column'>Files</Table.HeaderCell> + <Table.HeaderCell>Alias</Table.HeaderCell> + <Table.HeaderCell>Remote Path</Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + <Switch + empty={shares.length === 0 && <Table.Row> + <Table.Cell colSpan={5} style={{ opacity: .5, padding: '10px !important', textAlign: 'center' }}> + No shares configured + </Table.Cell> + </Table.Row>} + > + {shares.map((share, index) => (<Table.Row key={index}> + <Table.Cell onClick={() => onClick(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>))} + </Switch> + </Table.Body> + </Table> + ); +}; + +export default ShareTable;
\ 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 new file mode 100644 index 00000000..ceb5746c --- /dev/null +++ b/src/web/src/components/System/Shares/index.js @@ -0,0 +1,78 @@ +import React, { useState, useEffect } from 'react'; +import { toast } from 'react-toastify'; + +import * as sharesLib from '../../../lib/shares'; +import { + LoaderSegment, + ShrinkableButton, + Switch, +} from '../../Shared'; + +import ContentsModal from './ContentsModal'; + +import { + Divider, +} from 'semantic-ui-react'; + +import ExclusionTable from './ExclusionTable'; +import ShareTable from './ShareTable'; + +const Index = ({ state = {} } = {}) => { + const [loading, setLoading] = useState(true); + const [shares, setShares] = useState([]); + const [modal, setModal] = useState(false); + + const { scanning, scanProgress, scanPending } = state; + const scanned = !scanning; + + useEffect(() => { + getAll(); + }, []); + + useEffect(() => { + if (scanned) { + getAll(); + } + }, [scanned]); + + const getAll = async () => { + try { + setLoading(true); + setShares(await sharesLib.getAll()); + } catch (error) { + console.error(error); + toast.error(error?.response?.data ?? error?.message ?? error); + } finally { + setLoading(false); + } + }; + + 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>} + > + <ShareTable shares={shared} onClick={setModal}/> + <ExclusionTable exclusions={excluded}/> + </Switch> + <ContentsModal share={modal} onClose={() => setModal(false)}/> + </> + ); +}; + +export default Index;
\ No newline at end of file diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index 560cc21a..a8e9cb8e 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -24,15 +24,28 @@ min-height: 100px; } -.full-height { - height: calc(100vh - 175px); -} - .no-grow { white-space: nowrap; overflow: overlay; } +.edit-code-header { + margin-top: 1em !important; + font-size: initial !important; +} + +.edit-code-content { + padding: 0px !important; +} + +.debug-view-content, .share-ls-content { + padding: 5px !important; +} + +.left-align { + text-align: left; +} + .footer-buttons { margin-top: 14px; text-align: right; @@ -43,23 +56,10 @@ text-align: right; } -.state-code-editor, .view-code-container, .edit-code-container, .edit-code-container-error { - border: 1px solid #d4d4d5; +.edit-code-container, .edit-code-container-error { overflow: auto; } -.state-code-container { - height: calc(100vh - 204px); -} - -.view-code-container { - height: calc(100vh - 254px); -} - -.edit-code-container { - height: calc(100vh - 316px); -} - -.edit-code-container-error { - height: calc(100vh - 378px); +.share-count-column { + width: 110px; }
\ No newline at end of file diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 9310777f..2be10f81 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,25 +1,64 @@ import React from 'react'; import { useRouteMatch, useHistory, Redirect } from 'react-router-dom'; -import { Segment, Tab } from 'semantic-ui-react'; +import { Segment, Tab, Menu, Icon } from 'semantic-ui-react'; import './System.css'; import Info from './Info'; import Logs from './Logs'; import Options from './Options'; +import Shares from './Shares'; +import { Switch } from '../Shared'; const System = ({ state = {}, options = {} }) => { const { params: { tab }, ...route } = useRouteMatch(); const history = useHistory(); const panes = [ - { route: 'info', menuItem: 'Info', render: () => <Tab.Pane><Info state={state}/></Tab.Pane> }, + { + route: 'info', + menuItem: (<Menu.Item key='info'> + <Switch + pending={((state?.pendingRestart ?? false) || (state?.pendingReconnect ?? false)) + && <Icon name='exclamation circle' color='yellow'/>} + > + <Icon name='info circle'/> + </Switch> + Info + </Menu.Item>), + render: () => <Tab.Pane><Info state={state}/></Tab.Pane>, + }, + { + route: 'options', + menuItem: { + key: 'options', + icon: 'options', + content: 'Options', + }, + render: () => <Tab.Pane className='full-height'><Options options={options} /></Tab.Pane>, + }, { - route: 'options', menuItem: 'Options', render: () => - <Tab.Pane className='full-height'><Options options={options} /></Tab.Pane>, + route: 'shares', + menuItem: (<Menu.Item key='shares'> + <Switch + scanPending={(state?.shares?.scanPending ?? false) && <Icon name='exclamation circle' color='yellow'/>} + > + <Icon name='share external'/> + </Switch> + Shares + </Menu.Item>), + render: () => <Tab.Pane><Shares state={state.shares}/></Tab.Pane>, + }, + { + route: 'logs', + menuItem: { + key: 'logs', + icon: 'file outline', + content: 'Logs', + }, + render: () => <Tab.Pane><Logs/></Tab.Pane>, }, - { route: 'logs', menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> }, ]; const activeIndex = panes.findIndex(pane => pane.route === tab); diff --git a/src/web/src/components/Transfers/TransferGroup.js b/src/web/src/components/Transfers/TransferGroup.js index 023c18a0..ad4ab969 100644 --- a/src/web/src/components/Transfers/TransferGroup.js +++ b/src/web/src/components/Transfers/TransferGroup.js @@ -70,7 +70,7 @@ class TransferGroup extends Component { try { await transfers.download({username, files: [{filename, size }] }); } catch (error) { - console.log(error); + console.error(error); } }; @@ -80,7 +80,7 @@ class TransferGroup extends Component { try { await transfers.getPlaceInQueue({ username, id }); } catch (error) { - console.log(error); + console.error(error); } }; diff --git a/src/web/src/components/Transfers/Transfers.js b/src/web/src/components/Transfers/Transfers.js index 638c0d67..7820400e 100644 --- a/src/web/src/components/Transfers/Transfers.js +++ b/src/web/src/components/Transfers/Transfers.js @@ -64,7 +64,7 @@ const Transfers = ({ direction, server }) => { await transfersLib.download({username, files: [{filename, size }] }); if (!suppressStateChange) setRetrying(false); } catch (error) { - console.log(error); + console.error(error); toast.error(error?.response?.data ?? error?.message ?? error); if (!suppressStateChange) setRetrying(false); } @@ -84,7 +84,7 @@ const Transfers = ({ direction, server }) => { await transfersLib.cancel({ direction, username, id }); if (!suppressStateChange) setCancelling(false); } catch (error) { - console.log(error); + console.error(error); toast.error(error?.response?.data ?? error?.message ?? error); if (!suppressStateChange) setCancelling(false); } @@ -104,7 +104,7 @@ const Transfers = ({ direction, server }) => { await transfersLib.cancel({ direction, username, id, remove: true }); if (!suppressStateChange) setRemoving(false); } catch (error) { - console.log(error); + console.error(error); toast.error(error?.response?.data ?? error?.message ?? error); if (!suppressStateChange) setRemoving(false); } diff --git a/src/web/src/lib/options.js b/src/web/src/lib/options.js index 20f8dd0a..32e48534 100644 --- a/src/web/src/lib/options.js +++ b/src/web/src/lib/options.js @@ -4,6 +4,10 @@ export const getCurrent = async () => { return (await api.get('/options')).data; }; +export const getCurrentDebugView = async () => { + return (await api.get('/options/debug')).data; +}; + export const getYaml = async () => { return (await api.get('/options/yaml')).data; }; diff --git a/src/web/src/lib/shares.js b/src/web/src/lib/shares.js new file mode 100644 index 00000000..f1d0373c --- /dev/null +++ b/src/web/src/lib/shares.js @@ -0,0 +1,23 @@ +import api from './api'; + +export const getAll = async () => { + return (await api.get('/shares')).data; +}; + +export const get = async ({ id } = {}) => { + if (!id) throw new Error('unable to get share: id is missing'); + return (await api.get(`/shares/${id}`)).data; +}; + +export const browseAll = async () => { + return (await api.get('/shares/contents')).data; +}; + +export const browse = async ({ id } = {}) => { + if (!id) throw new Error('unable to get share contents: id is missing'); + return (await api.get(`/shares/${id}/contents`)).data; +}; + +export const rescan = async () => { + return (await api.put('/shares')).data; +};
\ No newline at end of file |
