2024-08-04 22:47:43 +05:30
|
|
|
import { useEffect, useMemo, useState } from "react"
|
|
|
|
|
|
|
|
|
|
import { CloseCircleFilled, SearchOutlined } from "@ant-design/icons"
|
|
|
|
|
|
2024-09-22 12:39:03 +05:30
|
|
|
import {SidebarWidgetCard} from "../components/cards"
|
2024-08-04 22:47:43 +05:30
|
|
|
|
|
|
|
|
import ButtonWidget from "../assets/widgets/button.png"
|
|
|
|
|
|
|
|
|
|
import { filterObjectListStartingWith } from "../utils/filter"
|
2024-09-22 12:39:03 +05:30
|
|
|
import Widget from "../canvas/widgets/base"
|
2024-09-24 14:33:02 +05:30
|
|
|
import { SearchComponent } from "../components/inputs"
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-09-11 19:06:04 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {function} onWidgetsUpdate - this is a callback that will be called once the sidebar is populated with widgets
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2024-09-22 12:39:03 +05:30
|
|
|
function WidgetsContainer({sidebarContent, onWidgetsUpdate}){
|
|
|
|
|
|
2024-08-04 22:47:43 +05:30
|
|
|
|
|
|
|
|
const [searchValue, setSearchValue] = useState("")
|
2024-09-22 12:39:03 +05:30
|
|
|
const [widgetData, setWidgetData] = useState(sidebarContent)
|
2024-08-04 22:47:43 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
2024-09-22 12:39:03 +05:30
|
|
|
setWidgetData(sidebarContent)
|
|
|
|
|
// if (onWidgetsUpdate){
|
|
|
|
|
// onWidgetsUpdate(widgets)
|
|
|
|
|
// }
|
2024-09-11 19:06:04 +05:30
|
|
|
|
2024-09-22 12:39:03 +05:30
|
|
|
}, [sidebarContent])
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-09-11 19:06:04 +05:30
|
|
|
|
|
|
|
|
|
2024-08-04 22:47:43 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
if (searchValue.length > 0){
|
2024-09-22 12:39:03 +05:30
|
|
|
const searchData = filterObjectListStartingWith(sidebarContent, "name", searchValue)
|
2024-08-04 22:47:43 +05:30
|
|
|
setWidgetData(searchData)
|
|
|
|
|
}else{
|
2024-09-22 12:39:03 +05:30
|
|
|
setWidgetData(sidebarContent)
|
2024-08-04 22:47:43 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, [searchValue])
|
|
|
|
|
|
|
|
|
|
function onSearch(event){
|
|
|
|
|
|
|
|
|
|
setSearchValue(event.target.value)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-12 19:20:46 +05:30
|
|
|
<div className="tw-w-full tw-p-2 tw-gap-4 tw-flex tw-flex-col tw-overflow-x-hidden">
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-09-24 14:33:02 +05:30
|
|
|
<SearchComponent onSearch={onSearch} searchValue={searchValue}
|
|
|
|
|
onClear={() => setSearchValue("")} />
|
|
|
|
|
<div className="tw-flex tw-flex-col tw-place-items-center tw-gap-2 tw-h-full tw-p-1">
|
2024-09-11 19:06:04 +05:30
|
|
|
|
2024-08-04 22:47:43 +05:30
|
|
|
{
|
|
|
|
|
widgetData.map((widget, index) => {
|
|
|
|
|
return (
|
2024-09-22 12:39:03 +05:30
|
|
|
<SidebarWidgetCard key={widget.name}
|
2024-09-11 19:06:04 +05:30
|
|
|
name={widget.name}
|
|
|
|
|
img={widget.img}
|
|
|
|
|
url={widget.link}
|
2024-09-22 12:39:03 +05:30
|
|
|
widgetClass={widget.widgetClass}
|
2024-09-11 19:06:04 +05:30
|
|
|
/>
|
2024-08-04 22:47:43 +05:30
|
|
|
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
2024-09-24 14:33:02 +05:30
|
|
|
|
2024-08-04 22:47:43 +05:30
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default WidgetsContainer
|