feat: apply across all pages

This commit is contained in:
Mohamed Marrouchi
2025-05-28 19:07:46 +01:00
parent 6b0ad29ee8
commit 7a4f8a7786
19 changed files with 236 additions and 101 deletions

View File

@@ -222,7 +222,7 @@ const AttachmentUploader: FC<FileUploadProps> = ({
{
defaultValues: { accept, onChange },
},
{ maxWidth: "xl" },
{ maxWidth: "xl", isSingleton: true },
)
}
>

View File

@@ -14,7 +14,7 @@ import {
InputAdornment,
TextFieldProps,
} from "@mui/material";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useRef } from "react";
import { useTranslate } from "@/hooks/useTranslate";
@@ -37,30 +37,49 @@ export const FilterTextfield = ({
...props
}) => {
const { t } = useTranslate();
const [inputValue, setInputValue] = useState(defaultValue);
const ref = useRef<HTMLInputElement>(null);
const isTyping = useRef(false);
const toggleTyping = useMemo(
() =>
debounce((value: boolean) => {
isTyping.current = value;
}, delay * 2),
[delay],
);
const debouncedSearch = useMemo(
() =>
debounce((value: string) => {
onSearch?.(value);
toggleTyping(false);
}, delay),
// eslint-disable-next-line react-hooks/exhaustive-deps
[onSearch, delay],
);
const handleChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setInputValue(value);
toggleTyping(true);
debouncedSearch(value);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[debouncedSearch],
);
const handleClear = useCallback(() => {
setInputValue("");
debouncedSearch("");
}, [debouncedSearch]);
useEffect(() => {
// Avoid infinite loop cycle (input => URL update => default value)
if (defaultValue !== ref.current?.value && !isTyping.current) {
ref.current && (ref.current.value = defaultValue);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultValue]);
return (
<Input
inputRef={ref}
InputProps={{
startAdornment: <Adornment Icon={SearchIcon} />,
endAdornment: clearable && (
@@ -73,7 +92,8 @@ export const FilterTextfield = ({
}}
placeholder={t("placeholder.keywords")}
{...props}
value={inputValue}
// value={inputValue}
defaultValue={defaultValue}
onChange={handleChange}
/>
);