Adding name query param to Channel filter input so the search can survive a refresh.

This commit is contained in:
Roland 2023-11-02 10:45:35 -06:00
parent 97b214d387
commit 5b7aec59cc
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 40 additions and 21 deletions

View file

@ -3,7 +3,6 @@ import {
AccordionContent,
AccordionTitle,
Grid,
Input,
StatisticLabel,
StatisticValue,
TableCell,
@ -18,7 +17,9 @@ import {
frequencyOptions,
humanFileSize,
RequiredAsterisk,
secondsToFrequency, secondsToFullDuration,
SearchInput,
secondsToFrequency,
secondsToFullDuration,
Toggle,
useTitle,
WROLModeMessage
@ -26,7 +27,7 @@ import {
import {Link, useNavigate, useParams} from "react-router-dom";
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
import {useChannel, useChannels} from "../hooks/customHooks";
import {useChannel, useChannels, useOneQuery} from "../hooks/customHooks";
import _ from "lodash";
import {Accordion, Button, Form, FormField, FormGroup, FormInput, Header, Loader, Segment, Statistic} from "./Theme";
import Dropdown from "semantic-ui-react/dist/commonjs/modules/Dropdown";
@ -500,25 +501,20 @@ export function ChannelsPage() {
useTitle('Channels');
const {channels} = useChannels();
const [searchStr, setSearchStr] = useState('');
const [searchStr, setSearchStr] = useOneQuery('name');
const handleInputChange = (e, {value}) => {
e.preventDefault();
setSearchStr(value);
}
let header = <div style={{marginBottom: '1em'}}>
<Header as='h1'>Channels</Header>
const header = <div style={{marginBottom: '1em'}}>
<Grid stackable columns={2}>
<Grid.Row>
<Grid.Column>
<Input fluid
icon='search'
placeholder='Name filter...'
size="large"
name="filterStr"
value={searchStr}
onChange={handleInputChange}/>
<SearchInput clearable={true}
placeholder='Name filter...'
size="large"
actionIcon='search'
searchStr={searchStr}
disabled={!Array.isArray(channels) || channels.length === 0}
onClear={() => setSearchStr('')}
onChange={setSearchStr}/>
</Grid.Column>
<Grid.Column textAlign='right'>
<Link to='/videos/channel/new'>

View file

@ -406,15 +406,33 @@ export function SearchInput({
clearable,
autoFocus = false,
onClear = null,
onChange = null,
...props
}) {
let [value, setValue] = useState(searchStr || '');
const handleChange = (e) => {
if (e) {
e.preventDefault();
}
setValue(e.target.value);
if (onChange) {
// Try to call the remote function, don't let its failure break this.
try {
onChange(e.target.value);
} catch (e) {
console.error(`Call to ${onChange} failed`);
}
}
}
const handleClearSearch = (e) => {
e.preventDefault();
// Clear the input when the "clear" button is clicked, search again.
setValue('');
onSubmit('');
if (onSubmit) {
onSubmit('');
}
if (onClear) {
onClear();
}
@ -423,7 +441,11 @@ export function SearchInput({
const localOnSubmit = (e) => {
// Send the value up when submitting.
e.preventDefault();
onSubmit(value);
if (onSubmit) {
onSubmit(value);
} else {
console.debug('No onSubmit defined');
}
}
if ((action || actionIcon) && searchStr && searchStr === value && clearable) {
@ -438,7 +460,7 @@ export function SearchInput({
<Input fluid
placeholder={placeholder}
type='text'
onChange={(e) => setValue(e.target.value)}
onChange={handleChange}
value={value}
size={size}
action={action}

View file

@ -92,6 +92,7 @@ export const useOneQuery = (name) => {
const value = searchParams.get(name);
const setValue = (newValue) => {
console.debug(`useOneQuery setValue=${newValue}`);
updateQuery({[name]: newValue});
}