Skip to content

Commit

Permalink
Fixed Filtering Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
olafwrieden committed Jun 7, 2020
1 parent b3c617b commit a27cb32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/src/components/Search/components/Filter/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Filter = ({ id, remove, handleChange }) => {
useEffect(() => {
setFilter((prevState) => ({
...prevState,
type: fieldSelector.value,
value: fieldSelector.values[0],
}));
}, [fieldSelector]);
Expand Down
25 changes: 15 additions & 10 deletions client/src/components/Search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ const Search = () => {
const [data, setData] = useState([]);
const fetchIdRef = useRef(0);

const fetchData = useCallback(async ({ pageSize, pageIndex }) => {
const fetchId = ++fetchIdRef.current;
const fetchData = useCallback(
async ({ pageSize, pageIndex }) => {
const fetchId = ++fetchIdRef.current;

// Fetch Data
const data = await fetch(
`/api/v1/evidence?limit=${pageSize}&page=${pageIndex}&fields=status.state&filter=AVAILABLE`
).then((res) => res.json());
// Fetch Data
const data = await fetch(
`/api/v1/evidence?limit=${pageSize}&page=${pageIndex}&fields=status.state&filter=AVAILABLE&filters=${JSON.stringify(
filters
)}`
).then((res) => res.json());

if (fetchId === fetchIdRef.current) {
setData(data.data);
}
}, []);
if (fetchId === fetchIdRef.current) {
setData(data.data);
}
},
[filters]
);

useEffect(() => {
fetchData(0, 10);
Expand Down

0 comments on commit a27cb32

Please sign in to comment.