Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/source options filters state #320

Merged
merged 3 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/source/SourceOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil
<CheckBoxFilter
key={`filters ${e.filter.name}`}
name={e.filter.name}
state={checkif === 'false' || (e.filter.state as boolean)}
state={checkif != null ? checkif === 'true' : (e.filter.state as boolean)}
position={index}
group={group}
updateFilterValue={updateFilterValue}
Expand All @@ -82,7 +82,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil
key={`filters ${e.filter.name}`}
name={e.filter.name}
values={e.filter.displayValues}
state={parseInt(checkif, 10) || (e.filter.state as number)}
state={checkif != null ? parseInt(checkif, 10) : (e.filter.state as number)}
selected={e.filter.selected}
position={index}
group={group}
Expand All @@ -98,7 +98,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil
key={`filters ${e.filter.name}`}
name={e.filter.name}
values={e.filter.values}
state={checkif ? JSON.parse(checkif) : (e.filter.state as IState)}
state={checkif ? JSON.parse(checkif) : { ...(e.filter.state as IState) }}
position={index}
group={group}
updateFilterValue={updateFilterValue}
Expand All @@ -110,7 +110,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil
<TextFilter
key={`filters ${e.filter.name}`}
name={e.filter.name}
state={checkif || (e.filter.state as string)}
state={checkif ?? (e.filter.state as string)}
position={index}
group={group}
updateFilterValue={updateFilterValue}
Expand All @@ -122,7 +122,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil
<TriStateFilter
key={`filters ${e.filter.name}`}
name={e.filter.name}
state={parseInt(checkif, 10) || (e.filter.state as number)}
state={checkif != null ? parseInt(checkif, 10) : (e.filter.state as number)}
position={index}
group={group}
updateFilterValue={updateFilterValue}
Expand Down
24 changes: 8 additions & 16 deletions src/components/source/filters/TextFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import SearchIcon from '@mui/icons-material/Search';
import { FormControl, Input, InputAdornment, InputLabel } from '@mui/material';
import React from 'react';
import React, { useEffect } from 'react';
import { useDebounce } from 'components/manga/hooks';

interface Props {
state: string;
Expand All @@ -22,32 +23,23 @@ interface Props {
const TextFilter: React.FC<Props> = (props) => {
const { state, name, position, group, updateFilterValue, update } = props;
const [Search, setsearch] = React.useState(state || '');
let typingTimer: NodeJS.Timeout;
const inputText = useDebounce(Search, 500);

function doneTyping(e: React.ChangeEvent<HTMLInputElement>) {
useEffect(() => {
const upd = update.filter(
(el: { position: number; group: number | undefined }) => !(position === el.position && group === el.group),
);
updateFilterValue([...upd, { position, state: e.target.value, group }]);
}

function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
setsearch(e.target.value);

clearTimeout(typingTimer);
typingTimer = setTimeout(() => {
doneTyping(e);
}, 2500);
}
updateFilterValue([...upd, { position, state: inputText, group }]);
}, [inputText]);

if (state !== undefined) {
return (
<FormControl sx={{ my: 1 }} variant="standard">
<InputLabel>{name}</InputLabel>
<Input
name={name}
value={Search || ''}
onChange={handleChange}
value={Search}
onChange={({ target: { value } }) => setsearch(value)}
endAdornment={
<InputAdornment position="end">
<SearchIcon />
Expand Down