diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-04-26 18:02:17 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-04-26 18:02:17 -0500 |
| commit | 0247358ad4067ba68b758d875e4bf1a1b2fb604c (patch) | |
| tree | 42c4effe156a76846b5e654438e9e60f9983b9e4 /src/web | |
| parent | 976fcca2e6dfa0b5f5c8872ac3c6ec8f24b54a29 (diff) | |
| download | slskd-0247358ad4067ba68b758d875e4bf1a1b2fb604c.tar.gz | |
wip searches UI
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/App.js | 2 | ||||
| -rw-r--r-- | src/web/src/components/Search/Search.css | 6 | ||||
| -rw-r--r-- | src/web/src/components/Search/SearchIcon.js | 35 | ||||
| -rw-r--r-- | src/web/src/components/Search/Searches.js | 131 | ||||
| -rw-r--r-- | src/web/src/lib/search.js | 4 |
5 files changed, 178 insertions, 0 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 3a22e0c8..8fa6bcaa 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -8,6 +8,7 @@ import { createApplicationHubConnection } from '../lib/hubFactory'; import './App.css'; import Search from './Search/Search'; +import Searches from './Search/Searches'; import Browse from './Browse/Browse'; import Users from './Users/Users'; import Transfers from './Transfers/Transfers'; @@ -242,6 +243,7 @@ class App extends Component { </Sidebar> <Sidebar.Pusher className='app-content'> <Switch> + <Route path='*/searches' render={(props) => this.withTokenCheck(<Searches {...props}/>)}/> <Route path='*/browse' render={(props) => this.withTokenCheck(<Browse {...props}/>)}/> <Route path='*/users' render={(props) => this.withTokenCheck(<Users {...props}/>)}/> <Route path='*/chat' render={(props) => this.withTokenCheck(<Chat {...props}/>)}/> diff --git a/src/web/src/components/Search/Search.css b/src/web/src/components/Search/Search.css index 7c91a08b..3fe76b80 100644 --- a/src/web/src/components/Search/Search.css +++ b/src/web/src/components/Search/Search.css @@ -15,6 +15,12 @@ height: 78px !important; } +.search-card { + width: 1200px !important; + margin-left: auto !important; + margin-right: auto !important; +} + @media only screen and (min-width: 851px) { .search-options-hide-no-slots, .search-options-hide-locked { margin-left: 1rem; diff --git a/src/web/src/components/Search/SearchIcon.js b/src/web/src/components/Search/SearchIcon.js new file mode 100644 index 00000000..b31bd860 --- /dev/null +++ b/src/web/src/components/Search/SearchIcon.js @@ -0,0 +1,35 @@ +import React from 'react'; + +import { Icon, Popup } from 'semantic-ui-react'; + +// as of 4.5.2, states are: +// transient: +// None, Requested, InProgress +// terminal: +// good: Completed, [TimedOut | ResponseLimitReached | FileLimitReached] +// bad: Completed, [Errored | Cancelled] + +const getIcon = (state) => { + switch (state) { + case 'None': + case 'Requested': + return <Icon name='time'/> + case 'InProgress': + return <Icon name='spinner' loading color='green'/> + case 'Completed, TimedOut': + case 'Completed, ResponseLimitReached': + case 'Completed, FileLimitReached': + return <Icon name='check' color='green'/> + case 'Completed, Cancelled': + return <Icon name='stop circle' color='green'/> + case 'Completed, Errored': + return <Icon name='x' color='red'/> + default: + return <Icon name='question circle' color='yellow'/> + } +} + +const SearchIcon = ({ state, ...props }) => + <Popup content={state} trigger={getIcon(state)} {...props}/> + +export default SearchIcon;
\ No newline at end of file diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js new file mode 100644 index 00000000..f6dd3ee2 --- /dev/null +++ b/src/web/src/components/Search/Searches.js @@ -0,0 +1,131 @@ +import React, { useState, useEffect, useRef } from 'react'; +import { v4 as uuidv4 } from 'uuid'; + +import * as search from '../../lib/search'; + +import './Search.css'; + +import { + Input, + Segment, + Card, + Table, + Icon +} from 'semantic-ui-react'; +import SearchIcon from './SearchIcon'; + +const Searches = () => { + const [{ loading, loadError }, setLoading] = useState({ loading: true, loadError: false }); + const [{ creating, createError }, setCreating] = useState({ creating: false, createError: false }) + const [searches, setSearches] = useState([]); + const inputRef = useRef(); + + useEffect(() => { + get(); + }, []); + + const create = async () => { + const searchText = inputRef.current.inputRef.current.value; + const id = uuidv4(); + + try { + setCreating({ creating: true, createError: false }) + await search.search({ id, searchText }) + setCreating({ creating: false, createError: false }) + inputRef.current.inputRef.current.value = ''; + window.location.reload(); + } catch (error) { + setCreating({ creating: false, createError: error.message }) + } + } + + const get = async () => { + setLoading({ loading: true, error: false }); + + try { + const searches = await search.getAll(); + + console.log(searches) + + setSearches(searches); + setLoading({ loading: false, error: false }) + } catch (error) { + setLoading({ loading: false, error: error.message }) + } + } + + const cancelAndDeleteAll = () => { + // todo + } + + return ( + <div className='search-container'> + <Segment className='search-segment' raised> + <Input + input={<input placeholder="Search phrase" type="search" data-lpignore="true"></input>} + size='big' + ref={inputRef} + loading={creating} + disabled={creating} + className='search-input' + placeholder="Search phrase" + action={{ icon: 'search', onClick: create }} + onKeyUp={(e) => e.key === 'Enter' ? create() : ''} + /> + </Segment> + <Card className='search-card' raised> + <Card.Content> + <Card.Header> + <Icon name='search'/> + Searches + <Icon.Group className='close-button' style={{ marginLeft: 10 }}> + <Icon + name='trash alternate' + color='red' + link + onClick={() => cancelAndDeleteAll()} + /> + <Icon corner name='asterisk'/> + </Icon.Group> + <Icon.Group className='close-button' > + <Icon + name='stop circle' + color='black' + link + onClick={() => cancelAndDeleteAll()} + /> + <Icon corner name='asterisk'/> + </Icon.Group> + </Card.Header> + <Table selectable> + <Table.Header> + <Table.Row> + <Table.HeaderCell></Table.HeaderCell> + <Table.HeaderCell>Started</Table.HeaderCell> + <Table.HeaderCell>Search Phrase</Table.HeaderCell> + <Table.HeaderCell>Responses</Table.HeaderCell> + <Table.HeaderCell>Files (Locked)</Table.HeaderCell> + <Table.HeaderCell></Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + {searches.map((search, index) => <Table.Row style={{ cursor: 'pointer'}} key={index}> + <Table.Cell><SearchIcon state={search.state} alt={search.state}/></Table.Cell> + <Table.Cell>{search.startedAt}</Table.Cell> + <Table.Cell>{search.searchText}</Table.Cell> + <Table.Cell>{search.responseCount}</Table.Cell> + <Table.Cell>{search.fileCount} ({search.lockedFileCount})</Table.Cell> + <Table.Cell>{search.state.includes('Completed') ? + <Icon name="trash alternate" color='red'/> : + <Icon name="stop circle" color="red"/>} + </Table.Cell> + </Table.Row>)} + </Table.Body> + </Table> + </Card.Content> + </Card> + </div> + ) +}; + +export default Searches;
\ No newline at end of file diff --git a/src/web/src/lib/search.js b/src/web/src/lib/search.js index 306c7041..362487bf 100644 --- a/src/web/src/lib/search.js +++ b/src/web/src/lib/search.js @@ -1,5 +1,9 @@ import api from './api'; +export const getAll = async () => { + return (await api.get('/searches')).data; +} + export const search = ({ id, searchText }) => { return api.post(`/searches`, { id, searchText }); }; |
