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 Box from '@mui/material/Box';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
@ -7,6 +7,7 @@ import Typography from '@mui/material/Typography';
|
|||||||
import Pagination from '@mui/material/Pagination';
|
import Pagination from '@mui/material/Pagination';
|
||||||
|
|
||||||
import { DashboardContent } from 'src/layouts/dashboard';
|
import { DashboardContent } from 'src/layouts/dashboard';
|
||||||
|
import { Filter, getFiltersAsync } from 'src/api/filter-service';
|
||||||
|
|
||||||
import { Iconify } from 'src/components/iconify';
|
import { Iconify } from 'src/components/iconify';
|
||||||
|
|
||||||
@ -25,10 +26,18 @@ type Props = {
|
|||||||
export function DocSearchView({ posts }: Props) {
|
export function DocSearchView({ posts }: Props) {
|
||||||
const [sortBy, setSortBy] = useState('latest');
|
const [sortBy, setSortBy] = useState('latest');
|
||||||
|
|
||||||
|
const [filters, setFilters] = useState<Filter[]>()
|
||||||
|
|
||||||
const handleSort = useCallback((newSort: string) => {
|
const handleSort = useCallback((newSort: string) => {
|
||||||
setSortBy(newSort);
|
setSortBy(newSort);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getFiltersAsync().then((res) => {
|
||||||
|
setFilters(res);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardContent>
|
<DashboardContent>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user