mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
use timer for debounce
This commit is contained in:
parent
6694e0e334
commit
c7c49b2587
@ -14,6 +14,8 @@ export const WidgetBrowser = (props) => {
|
|||||||
|
|
||||||
const [searchValue, setSearchValue] = React.useState("")
|
const [searchValue, setSearchValue] = React.useState("")
|
||||||
|
|
||||||
|
let timer = null
|
||||||
|
|
||||||
const handleOnSearch = (e) => {
|
const handleOnSearch = (e) => {
|
||||||
// not allow to input space as first character
|
// not allow to input space as first character
|
||||||
if (e.target.value[0] === " ") {
|
if (e.target.value[0] === " ") {
|
||||||
@ -21,19 +23,19 @@ export const WidgetBrowser = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSearchValue(e.target.value)
|
setSearchValue(e.target.value)
|
||||||
}
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
timer = setTimeout(async () => {
|
||||||
const timer = setTimeout(async () => {
|
if (timer) {
|
||||||
|
clearTimeout(timer)
|
||||||
|
}
|
||||||
|
|
||||||
await M_Widgets({
|
await M_Widgets({
|
||||||
keywords: {
|
keywords: {
|
||||||
name: searchValue
|
name: e.target.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, 400)
|
}, 400)
|
||||||
|
}
|
||||||
return () => clearTimeout(timer)
|
|
||||||
}, [searchValue])
|
|
||||||
|
|
||||||
if (E_Widgets) {
|
if (E_Widgets) {
|
||||||
console.error(E_Widgets)
|
console.error(E_Widgets)
|
||||||
@ -62,24 +64,26 @@ export const WidgetBrowser = (props) => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
!L_Widgets && R_Widgets.map((widget, index) => {
|
!L_Widgets && R_Widgets.map((widget, index) => {
|
||||||
return <WidgetItemPreview
|
return <React.Fragment>
|
||||||
index={index}
|
<WidgetItemPreview
|
||||||
manifest={widget.manifest}
|
index={index}
|
||||||
onRemove={() => {
|
manifest={widget.manifest}
|
||||||
app.cores.widgets.uninstall(widget._id)
|
onRemove={() => {
|
||||||
}}
|
app.cores.widgets.uninstall(widget._id)
|
||||||
onInstall={() => {
|
}}
|
||||||
app.cores.widgets.install(widget._id)
|
onInstall={() => {
|
||||||
}}
|
app.cores.widgets.install(widget._id)
|
||||||
onUpdate={() => {
|
}}
|
||||||
app.cores.widgets.install(widget._id, {
|
onUpdate={() => {
|
||||||
update: true,
|
app.cores.widgets.install(widget._id, {
|
||||||
})
|
update: true,
|
||||||
}}
|
})
|
||||||
onChangeVisible={(visible) => {
|
}}
|
||||||
app.cores.widgets.toogleVisibility(widget._id, visible)
|
onChangeVisible={(visible) => {
|
||||||
}}
|
app.cores.widgets.toogleVisibility(widget._id, visible)
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user