Ajoute des alias et refactor des hooks
parent
aa63dd4511
commit
13a8332d29
|
@ -0,0 +1 @@
|
|||
[]
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"message": "no results found",
|
||||
"spellcheck": null,
|
||||
"suggestions": []
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"message": "no results found",
|
||||
"spellcheck": null,
|
||||
"suggestions": [
|
||||
"menoz",
|
||||
"menozzi*albertini/marie agnes/",
|
||||
"menozzi*dominique emile/",
|
||||
"menoz compagnie yado",
|
||||
"menozzi champagne",
|
||||
"menozzi cite",
|
||||
"menozzi holding",
|
||||
"menozzi industrie",
|
||||
"menozzi vaise",
|
||||
"menozzi*amerio/laurence/"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useDebounce<T>(value: T, delay: number) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value)
|
||||
useEffect(
|
||||
() => {
|
||||
// Update debounced value after delay
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedValue(value)
|
||||
}, delay)
|
||||
|
||||
// Cancel the timeout if value changes (also on delay change or unmount)
|
||||
// This is how we prevent debounced value from updating if value is changed ...
|
||||
// .. within the delay period. Timeout gets cleared and restarted.
|
||||
return () => {
|
||||
clearTimeout(handler)
|
||||
}
|
||||
},
|
||||
[value, delay] // Only re-call effect if value or delay changes
|
||||
)
|
||||
return debouncedValue
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { Etablissement, searchDenominationOrSiren } from 'api/sirene'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useDebounce } from './useDebounce'
|
||||
|
||||
export default function useSearchCompany(
|
||||
value: string
|
||||
): [boolean, Array<Etablissement>] {
|
||||
const [result, setResult] = useState<Array<Etablissement>>([])
|
||||
const [searchPending, setSearchPending] = useState(!!value)
|
||||
const debouncedValue = useDebounce(value, 300)
|
||||
|
||||
useEffect(() => {
|
||||
setSearchPending(!!value)
|
||||
|
||||
if (!value) {
|
||||
setResult([])
|
||||
}
|
||||
}, [value, setResult, setSearchPending])
|
||||
|
||||
useEffect(() => {
|
||||
if (!debouncedValue) {
|
||||
return
|
||||
}
|
||||
|
||||
searchDenominationOrSiren(debouncedValue).then((établissements) => {
|
||||
setResult(établissements || [])
|
||||
setSearchPending(false)
|
||||
})
|
||||
}, [debouncedValue, setResult, setSearchPending])
|
||||
|
||||
return [searchPending && result.length <= 0, result.slice(0, 6)]
|
||||
}
|
|
@ -19,7 +19,9 @@
|
|||
"Selectors/*": ["selectors/*"],
|
||||
"Types/*": ["types/*"],
|
||||
"DesignSystem/*": ["design-system/*"],
|
||||
"Data/*": ["data/*"]
|
||||
"Data/*": ["data/*"],
|
||||
"Hooks/*": ["hooks/*"],
|
||||
"API/*": ["api/*"]
|
||||
},
|
||||
"typeRoots": ["./types/", "./node_modules/@types"],
|
||||
"noEmit": true,
|
||||
|
|
|
@ -114,6 +114,8 @@ module.exports.default = {
|
|||
Images: path.resolve('source/static/images/'),
|
||||
DesignSystem: path.resolve('source/design-system'),
|
||||
Data: path.resolve('source/data'),
|
||||
Hooks: path.resolve('source/hooks'),
|
||||
API: path.resolve('source/api'),
|
||||
},
|
||||
extensions: ['.js', '.ts', '.tsx'],
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue