diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-05-19 08:51:35 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-19 08:51:35 -0500 |
| commit | 2a941bd6848bd902552d53e6bcf07f9e77194043 (patch) | |
| tree | d46876f6f02ec23c414a6e4cb0f8639c6ef7ce1e /src/web | |
| parent | a643f46dc0b3892079e290279cd28b50b3cabdfd (diff) | |
| parent | 26c8d9951cac5231fae5aa90b1df5cd3bbe511a3 (diff) | |
| download | slskd-2a941bd6848bd902552d53e6bcf07f9e77194043.tar.gz | |
Merge pull request #471 from slskd/disable-search-disconnected
Disable search and download controls if disconnected from the server
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/App.js | 33 | ||||
| -rw-r--r-- | src/web/src/components/AppContext.js | 5 | ||||
| -rw-r--r-- | src/web/src/components/Search/Detail/SearchDetail.js | 4 | ||||
| -rw-r--r-- | src/web/src/components/Search/Detail/SearchDetailHeader.js | 4 | ||||
| -rw-r--r-- | src/web/src/components/Search/Response.js | 2 | ||||
| -rw-r--r-- | src/web/src/components/Search/Searches.js | 11 |
6 files changed, 39 insertions, 20 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index a5bf936a..5e5ed10f 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -19,6 +19,8 @@ import Chat from './Chat/Chat'; import System from './System/System'; import LoginForm from './LoginForm'; +import AppContext from './AppContext'; + import { Sidebar, Segment, @@ -246,17 +248,26 @@ class App extends Component { </Menu> </Sidebar> <Sidebar.Pusher className='app-content'> - <Switch> - <Route path={`${urlBase}/searches/:id?`} render={(props) => this.withTokenCheck(<div className='search-container'><Searches {...props}/></div>)}/> - <Route path={`${urlBase}/browse`} render={(props) => this.withTokenCheck(<Browse {...props}/>)}/> - <Route path={`${urlBase}/users`} render={(props) => this.withTokenCheck(<Users {...props}/>)}/> - <Route path={`${urlBase}/chat`} render={(props) => this.withTokenCheck(<Chat {...props}/>)}/> - <Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> - <Route path={`${urlBase}/uploads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/> - <Route path={`${urlBase}/downloads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/> - <Route path={`${urlBase}/system/:tab?`} render={(props) => this.withTokenCheck(<System {...props} state={applicationState} options={applicationOptions}/>)}/> - <Redirect from='*' to={`${urlBase}/searches`}/> - </Switch> + <AppContext.Provider value={{ state: applicationState, options: applicationOptions }}> + <Switch> + <Route path={`${urlBase}/searches/:id?`} render={(props) => + this.withTokenCheck(<div className='search-container'> + <Searches + server={applicationState.server} + {...props} + /> + </div>)} + /> + <Route path={`${urlBase}/browse`} render={(props) => this.withTokenCheck(<Browse {...props}/>)}/> + <Route path={`${urlBase}/users`} render={(props) => this.withTokenCheck(<Users {...props}/>)}/> + <Route path={`${urlBase}/chat`} render={(props) => this.withTokenCheck(<Chat {...props}/>)}/> + <Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> + <Route path={`${urlBase}/uploads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/> + <Route path={`${urlBase}/downloads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/> + <Route path={`${urlBase}/system/:tab?`} render={(props) => this.withTokenCheck(<System {...props} state={applicationState} options={applicationOptions}/>)}/> + <Redirect from='*' to={`${urlBase}/searches`}/> + </Switch> + </AppContext.Provider> </Sidebar.Pusher> </Sidebar.Pushable> <ToastContainer diff --git a/src/web/src/components/AppContext.js b/src/web/src/components/AppContext.js new file mode 100644 index 00000000..2095b2ab --- /dev/null +++ b/src/web/src/components/AppContext.js @@ -0,0 +1,5 @@ +import React from 'react'; + +const AppContext = React.createContext(); + +export default AppContext;
\ No newline at end of file diff --git a/src/web/src/components/Search/Detail/SearchDetail.js b/src/web/src/components/Search/Detail/SearchDetail.js index 880d5cd0..9c66d4e0 100644 --- a/src/web/src/components/Search/Detail/SearchDetail.js +++ b/src/web/src/components/Search/Detail/SearchDetail.js @@ -21,7 +21,7 @@ const sortDropdownOptions = [ { key: 'queueLength', text: 'Queue Depth (Least to Most)', value: 'queueLength' } ]; -const SearchDetail = ({ search, creating, stopping, removing, onCreate, onStop, onRemove }) => { +const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate, onStop, onRemove }) => { const { id, state, isComplete, fileCount, lockedFileCount, responseCount } = search; const [loading, setLoading] = useState(false); @@ -132,6 +132,7 @@ const SearchDetail = ({ search, creating, stopping, removing, onCreate, onStop, removing={removing} stopping={stopping} creating={creating} + disabled={disabled} search={search} onCreate={create} onStop={onStop} @@ -195,6 +196,7 @@ const SearchDetail = ({ search, creating, stopping, removing, onCreate, onStop, <Response key={i} response={r} + disabled={disabled} onHide={() => setHiddenResults([...hiddenResults, r.username])} isInitiallyFolded={foldResults} /> diff --git a/src/web/src/components/Search/Detail/SearchDetailHeader.js b/src/web/src/components/Search/Detail/SearchDetailHeader.js index d31f8a49..8eaf111c 100644 --- a/src/web/src/components/Search/Detail/SearchDetailHeader.js +++ b/src/web/src/components/Search/Detail/SearchDetailHeader.js @@ -9,7 +9,7 @@ import { } from 'semantic-ui-react'; import SearchStatusIcon from '../SearchStatusIcon'; -const SearchDetailHeader = ({ search, loading, loaded, creating, removing, stopping, onCreate, onStop, onRemove }) => { +const SearchDetailHeader = ({ search, loading, loaded, creating, removing, stopping, disabled, onCreate, onStop, onRemove }) => { const isSmallScreen = useMediaQuery({ query: '(max-width: 899px)' }); const isTinyScreen = useMediaQuery({ query: '(max-width: 684px)'}); @@ -26,7 +26,7 @@ const SearchDetailHeader = ({ search, loading, loaded, creating, removing, stopp const RefreshButton = () => loaded && <Button - disabled={working} + disabled={disabled || working} icon={isSmallScreen && !isTinyScreen} onClick={() => onCreate({ search: searchText, navigate: true })} loading={creating} diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 7ffb70d4..4e389288 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -121,7 +121,7 @@ class Response extends Component { }} labelPosition='right' onClick={() => this.download(response.username, selectedFiles)} - disabled={downloadRequest === 'inProgress'} + disabled={this.props.disabled || downloadRequest === 'inProgress'} /> {downloadRequest === 'inProgress' && <Icon loading name='circle notch' size='large'/>} {downloadRequest === 'complete' && <Icon name='checkmark' color='green' size='large'/>} diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js index c1a3a893..9cc717ad 100644 --- a/src/web/src/components/Search/Searches.js +++ b/src/web/src/components/Search/Searches.js @@ -20,7 +20,7 @@ import { import SearchDetail from './Detail/SearchDetail'; import ErrorSegment from '../Shared/ErrorSegment'; -const Searches = () => { +const Searches = ({ server }) => { const [connecting, setConnecting] = useState(true); const [error, setError] = useState(undefined); const [searches, setSearches] = useState({}); @@ -170,6 +170,7 @@ const Searches = () => { creating={creating} stopping={stopping} removing={removing} + disabled={!server.isConnected} onCreate={create} onStop={stop} onRemove={remove} @@ -186,16 +187,16 @@ const Searches = () => { <> <Segment className='search-segment' raised> <Input - input={<input placeholder="Search phrase" type="search" data-lpignore="true"></input>} + input={<input placeholder={server.isConnected ? 'Search phrase' : 'Connect to server to perform a search'} type="search" data-lpignore="true"></input>} size='big' ref={inputRef} loading={creating} - disabled={creating} + disabled={creating || !server.isConnected} className='search-input' placeholder="Search phrase" action={<> - <Button icon='plus' onClick={create}/> - <Button icon='search' onClick={() => create({ navigate: true })}/> + <Button icon='plus' disabled={creating || !server.isConnected} onClick={create}/> + <Button icon='search' disabled={creating || !server.isConnected} onClick={() => create({ navigate: true })}/> </>} onKeyUp={(e) => e.key === 'Enter' ? create() : ''} /> |
