Add filters state and fetch logic in DocSearchView
Updated imports to include useEffect for side effects. Introduced a new state variable `filters` to manage Filter objects. Implemented useEffect to asynchronously fetch filters using getFiltersAsync.
This commit is contained in:
parent
a73ff5b9a4
commit
f8be0b0b5f
@ -1,4 +1,4 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
|
||||
import Box from '@mui/material/Box';
|
||||
import Grid from '@mui/material/Grid';
|
||||
@ -7,6 +7,7 @@ import Typography from '@mui/material/Typography';
|
||||
import Pagination from '@mui/material/Pagination';
|
||||
|
||||
import { DashboardContent } from 'src/layouts/dashboard';
|
||||
import { Filter, getFiltersAsync } from 'src/api/filter-service';
|
||||
|
||||
import { Iconify } from 'src/components/iconify';
|
||||
|
||||
@ -25,10 +26,18 @@ type Props = {
|
||||
export function DocSearchView({ posts }: Props) {
|
||||
const [sortBy, setSortBy] = useState('latest');
|
||||
|
||||
const [filters, setFilters] = useState<Filter[]>()
|
||||
|
||||
const handleSort = useCallback((newSort: string) => {
|
||||
setSortBy(newSort);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getFiltersAsync().then((res) => {
|
||||
setFilters(res);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<DashboardContent>
|
||||
<Box
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user