feature: добавил кнопку отчистки поля поиска
This commit is contained in:
parent
d46e7cee06
commit
8a8d90e03a
|
|
@ -2,7 +2,7 @@ import {useEffect, useState} from "react";
|
||||||
import '../assets/styles/home.css';
|
import '../assets/styles/home.css';
|
||||||
import {
|
import {
|
||||||
Box, Button,
|
Box, Button,
|
||||||
Divider, Fab,
|
Divider, Fab, IconButton, InputAdornment,
|
||||||
TextField,
|
TextField,
|
||||||
ThemeProvider, Typography,
|
ThemeProvider, Typography,
|
||||||
useTheme
|
useTheme
|
||||||
|
|
@ -16,6 +16,7 @@ import ItemDialog from "~/components/itemDialog";
|
||||||
import OutlinedFlagIcon from '@mui/icons-material/OutlinedFlag';
|
import OutlinedFlagIcon from '@mui/icons-material/OutlinedFlag';
|
||||||
import ReportDialog from "~/components/reportDialog";
|
import ReportDialog from "~/components/reportDialog";
|
||||||
import LoopIcon from '@mui/icons-material/Loop';
|
import LoopIcon from '@mui/icons-material/Loop';
|
||||||
|
import ClearIcon from '@mui/icons-material/Clear';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const outerTheme = useTheme();
|
const outerTheme = useTheme();
|
||||||
|
|
@ -29,6 +30,7 @@ export default function Home() {
|
||||||
const [fabIsHovered, setFabIsHovered] = useState(false);
|
const [fabIsHovered, setFabIsHovered] = useState(false);
|
||||||
const [showReportDialog, setReportShowDialog] = useState(false);
|
const [showReportDialog, setReportShowDialog] = useState(false);
|
||||||
const [triggerUpdate, setTriggerUpdate] = useState(0);
|
const [triggerUpdate, setTriggerUpdate] = useState(0);
|
||||||
|
const [showEraseButton, setShowEraseButton] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isIgnore = false;
|
let isIgnore = false;
|
||||||
|
|
@ -52,12 +54,14 @@ export default function Home() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (searchText !== ""){
|
if (searchText !== ""){
|
||||||
|
setShowEraseButton(true);
|
||||||
setIsFetchingList(true);
|
setIsFetchingList(true);
|
||||||
let result = search(searchText);
|
let result = search(searchText);
|
||||||
console.log(result);
|
console.log(result);
|
||||||
setBlacklistItems(result);
|
setBlacklistItems(result);
|
||||||
setIsFetchingList(false);
|
setIsFetchingList(false);
|
||||||
} else {
|
} else {
|
||||||
|
setShowEraseButton(false);
|
||||||
setBlacklistItems(totalBlacklistItems);
|
setBlacklistItems(totalBlacklistItems);
|
||||||
}
|
}
|
||||||
}, [searchText]);
|
}, [searchText]);
|
||||||
|
|
@ -88,6 +92,10 @@ export default function Home() {
|
||||||
setTriggerUpdate(triggerUpdate + 1)
|
setTriggerUpdate(triggerUpdate + 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClickEraseSearch = () => {
|
||||||
|
setSearchText("");
|
||||||
|
};
|
||||||
|
|
||||||
const search = (searchString: string) => {
|
const search = (searchString: string) => {
|
||||||
searchString = searchString.toLowerCase();
|
searchString = searchString.toLowerCase();
|
||||||
return totalBlacklistItems.filter((item) => {
|
return totalBlacklistItems.filter((item) => {
|
||||||
|
|
@ -109,6 +117,33 @@ export default function Home() {
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => handleSearch(e.target.value)}
|
onChange={(e) => handleSearch(e.target.value)}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
slotProps={{
|
||||||
|
input: {
|
||||||
|
endAdornment: <InputAdornment position="end">
|
||||||
|
{ showEraseButton ? <IconButton
|
||||||
|
onClick={handleClickEraseSearch}
|
||||||
|
edge="end"
|
||||||
|
sx={{
|
||||||
|
marginRight: '1px',
|
||||||
|
padding: '5px!important',
|
||||||
|
'&:hover': {
|
||||||
|
// backgroundColor: '#282c34',
|
||||||
|
backgroundColor: '#E0E3E7',
|
||||||
|
border: '1px solid #E0E3E7',
|
||||||
|
'& > .MuiSvgIcon-root': {
|
||||||
|
color: '#282c34',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ClearIcon sx={{
|
||||||
|
color: '#E0E3E7',
|
||||||
|
fontSize: '1.2rem'
|
||||||
|
}}/>
|
||||||
|
</IconButton> : "" }
|
||||||
|
</InputAdornment>,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue