From 0247358ad4067ba68b758d875e4bf1a1b2fb604c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 26 Apr 2022 18:02:17 -0500 Subject: wip searches UI --- src/web/src/components/App.js | 2 + src/web/src/components/Search/Search.css | 6 ++ src/web/src/components/Search/SearchIcon.js | 35 ++++++++ src/web/src/components/Search/Searches.js | 131 ++++++++++++++++++++++++++++ src/web/src/lib/search.js | 4 + 5 files changed, 178 insertions(+) create mode 100644 src/web/src/components/Search/SearchIcon.js create mode 100644 src/web/src/components/Search/Searches.js (limited to 'src/web') 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 { + this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> 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 + case 'InProgress': + return + case 'Completed, TimedOut': + case 'Completed, ResponseLimitReached': + case 'Completed, FileLimitReached': + return + case 'Completed, Cancelled': + return + case 'Completed, Errored': + return + default: + return + } +} + +const SearchIcon = ({ 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 ( +
+ + } + 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() : ''} + /> + + + + + + Searches + + cancelAndDeleteAll()} + /> + + + + cancelAndDeleteAll()} + /> + + + + + + + + Started + Search Phrase + Responses + Files (Locked) + + + + + {searches.map((search, index) => + + {search.startedAt} + {search.searchText} + {search.responseCount} + {search.fileCount} ({search.lockedFileCount}) + {search.state.includes('Completed') ? + : + } + + )} + +
+
+
+
+ ) +}; + +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 }); }; -- cgit v1.2.3