Skip to content

Commit

Permalink
refactor: remove old search component
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 9, 2024
1 parent 36f2bd8 commit d4016b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 65 deletions.
58 changes: 0 additions & 58 deletions src/components/layout/dialogs/filters/AdvSearch.jsx

This file was deleted.

18 changes: 17 additions & 1 deletion src/components/layout/dialogs/webhooks/Tracked.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Virtuoso } from 'react-virtuoso'
import Typography from '@mui/material/Typography'

import Box from '@mui/material/Box'
import { WebhookSearch } from '@components/layout/dialogs/filters/AdvSearch'
import { Loading } from '@components/layout/general/Loading'
import { GenericSearch } from '@components/layout/drawer/ItemSearch'

import TrackedTile from './tiles/TrackedTile'
import Selecting from './Selecting'
import { useGetWebhookData } from './hooks'
import { useWebhookStore } from './store'

/**
*
Expand Down Expand Up @@ -47,4 +48,19 @@ const Tracked = ({ category }) => {
)
}

export const WebhookSearch = React.memo(() => {
const search = useWebhookStore((s) => s.trackedSearch)
const category = useWebhookStore((s) => s.category)

return (
<GenericSearch
value={search}
setValue={(newValue) =>
useWebhookStore.setState({ trackedSearch: newValue })
}
label={`search_${category}`}
/>
)
})

export default Tracked
16 changes: 10 additions & 6 deletions src/components/layout/drawer/ItemSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ import { useDeepStore } from '@hooks/useStore'

/**
* @typedef {{
* field: import('@hooks/useStore').UseStorePaths,
* field?: import('@hooks/useStore').UseStorePaths,
* value?: string,
* setValue?: (value: string) => void,
* label?: string,
* disabled?: boolean,
* } & import('@mui/material').TextFieldProps} Props
*/

/** @type {React.ForwardRefExoticComponent<Props>} */
export const GenericSearch = React.forwardRef(
({ field, label, disabled, ...props }, ref) => {
({ field, label, disabled, value, setValue, ...props }, ref) => {
const { t } = useTranslation()
const [value, setValue] = useDeepStore(field, '')
const [searchValue, setSearchValue] = field
? useDeepStore(field, '')
: [value, setValue]

const InputProps = React.useMemo(
() => ({
endAdornment: (
<IconButton
size="small"
disabled={!value}
onClick={() => setValue('')}
onClick={() => setSearchValue('')}
>
<HighlightOffIcon fontSize="small" />
</IconButton>
),
}),
[!!value, setValue],
[!!searchValue, setSearchValue],
)
/** @type {import('@mui/material').TextFieldProps['onChange']} */
const onChange = React.useCallback(
Expand All @@ -51,7 +55,7 @@ export const GenericSearch = React.forwardRef(
fullWidth
size="small"
disabled={disabled}
value={value}
value={searchValue}
onChange={onChange}
InputProps={InputProps}
{...props}
Expand Down

0 comments on commit d4016b5

Please sign in to comment.