aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-17 08:14:50 -0500
committerJP Dillingham <jp@dillingham.me>2022-05-17 08:14:50 -0500
commit12ccc35465336ab76cbea4b8e86e637c26d6c04e (patch)
tree5b3e33389f59736a015c13af8743a9f4d43b0777 /src
parentac1ca6e5d11adfd13d0917b3776cb75e9a20574c (diff)
downloadslskd-12ccc35465336ab76cbea4b8e86e637c26d6c04e.tar.gz
media queries, ability to re-search
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/Search/Detail/SearchDetail.js5
-rw-r--r--src/web/src/components/Search/Detail/SearchDetailHeader.js57
-rw-r--r--src/web/src/components/Search/Searches.js15
3 files changed, 55 insertions, 22 deletions
diff --git a/src/web/src/components/Search/Detail/SearchDetail.js b/src/web/src/components/Search/Detail/SearchDetail.js
index 5cadd941..19cc1b84 100644
--- a/src/web/src/components/Search/Detail/SearchDetail.js
+++ b/src/web/src/components/Search/Detail/SearchDetail.js
@@ -20,7 +20,7 @@ const sortDropdownOptions = [
{ key: 'queueLength', text: 'Queue Depth (Least to Most)', value: 'queueLength' }
];
-const SearchDetail = ({ search, onStop, onRemove }) => {
+const SearchDetail = ({ search, onCreate, onStop, onRemove }) => {
const { id, state, isComplete, fileCount, lockedFileCount, responseCount } = search;
const [loading, setLoading] = useState(false);
@@ -96,7 +96,8 @@ const SearchDetail = ({ search, onStop, onRemove }) => {
<>
<SearchDetailHeader
loading={loading}
- search={search}
+ search={search}
+ onCreate={onCreate}
onStop={onStop}
onRemove={onRemove}
/>
diff --git a/src/web/src/components/Search/Detail/SearchDetailHeader.js b/src/web/src/components/Search/Detail/SearchDetailHeader.js
index 0768d963..7b78d134 100644
--- a/src/web/src/components/Search/Detail/SearchDetailHeader.js
+++ b/src/web/src/components/Search/Detail/SearchDetailHeader.js
@@ -1,4 +1,5 @@
import React from 'react';
+import { useMediaQuery } from 'react-responsive';
import {
Segment,
@@ -8,7 +9,10 @@ import {
} from 'semantic-ui-react';
import SearchStatusIcon from '../SearchStatusIcon';
-const SearchDetailHeader = ({ search, loading, onStop, onRemove }) => {
+const SearchDetailHeader = ({ search, loading, onCreate, onStop, onRemove }) => {
+ const isSmallScreen = useMediaQuery({ query: '(max-width: 899px)' });
+ const isTinyScreen = useMediaQuery({ query: '(max-width: 684px)'});
+
const { searchText, isComplete, state } = search;
const stopOrRemove = () => {
@@ -19,22 +23,43 @@ const SearchDetailHeader = ({ search, loading, onStop, onRemove }) => {
}
}
+ const RefreshButton = ({ ...props }) =>
+ <Button
+ disabled={loading}
+ icon={isSmallScreen && !isTinyScreen}
+ onClick={() => onCreate({ search: searchText, navigate: true })}
+ >
+ <Icon name='refresh'/>{(!isSmallScreen || isTinyScreen) && 'Search Again'}
+ </Button>
+
+ const StopOrDeleteButton = ({ ...props }) =>
+ <Button
+ negative
+ disabled={loading}
+ onClick={stopOrRemove}
+ floated={isTinyScreen ? 'right' : ''}
+ icon={isSmallScreen && !isTinyScreen}
+ >
+ <Icon name={isComplete ? 'trash alternate' : 'stop circle'}/>
+ {(!isSmallScreen || isTinyScreen) && (isComplete ? 'Delete' : 'Stop')}
+ </Button>
+
return (
- <Segment className='search-segment' raised>
- <Header className='search-detail-header'>
- <SearchStatusIcon state={state}/>
- {searchText}
- </Header>
- <Button
- className='search-detail-action-button'
- negative
- disabled={loading}
- onClick={stopOrRemove}
- >
- <Icon name={isComplete ? 'trash alternate' : 'stop circle'}/>
- {isComplete ? 'Delete' : 'Stop'} Search
- </Button>
- </Segment>
+ <>
+ <Segment className='search-segment' raised>
+ <Header className='search-detail-header'>
+ <SearchStatusIcon state={state}/>{searchText}
+ </Header>
+ {!isTinyScreen && <div className='search-detail-action-button'>
+ <RefreshButton/>
+ <StopOrDeleteButton/>
+ </div>}
+ </Segment>
+ {isTinyScreen && <Segment>
+ <RefreshButton/>
+ <StopOrDeleteButton/>
+ </Segment>}
+ </>
)
};
diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js
index 31e77e08..32496bf9 100644
--- a/src/web/src/components/Search/Searches.js
+++ b/src/web/src/components/Search/Searches.js
@@ -93,20 +93,26 @@ const Searches = () => {
}
}, []);
- const create = async ({ navigate = false } = {}) => {
- const searchText = inputRef.current.inputRef.current.value;
+ const create = async ({ search, navigate = false } = {}) => {
+ const searchText = search || inputRef.current.inputRef.current.value;
const id = uuidv4();
try {
setCreating({ creating: true, createError: false })
await lib.create({ id, searchText })
setCreating({ creating: false, createError: false })
- inputRef.current.inputRef.current.value = '';
+
+ try {
+ inputRef.current.inputRef.current.value = '';
+ } catch {
+ // no-op
+ }
if (navigate) {
- history.push(`${match.url}/${id}`)
+ history.push(`/searches/${id}`)
}
} catch (error) {
+ console.error(error)
setCreating({ creating: false, createError: error.message })
}
}
@@ -140,6 +146,7 @@ const Searches = () => {
return (
<SearchDetail
search={searches[searchId]}
+ onCreate={create}
onStop={stop}
onRemove={remove}
/>