Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
fix(app): sort trash bin page latesy by default
Browse files Browse the repository at this point in the history
  • Loading branch information
yehezkieldio committed Mar 2, 2024
1 parent f13b24b commit 55203eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/app/src/pages/operator/trash-bin/trashbin/trashbin.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useHistory } from "react-router-dom";
import { useState } from "react";
import Fuse from "fuse.js";
import { useTranslation } from "react-i18next";
import dayjs from "dayjs";

export interface InterfaceTrashbin {
id: number;
Expand Down Expand Up @@ -41,14 +42,25 @@ export function TrashBinPage() {
refetch();
});

function filterAndSortLatest(data: InterfaceTrashbin[]) {
return data
.filter((trashbin) => dayjs(trashbin.createdAt))
.sort((a, b) => dayjs(b.createdAt).valueOf() - dayjs(a.createdAt).valueOf());
}

const fuseOptions = {
keys: ["name"],
threshold: 0.4,
};
const fuse = new Fuse(!isLoading ? (trashBinData.data as InterfaceTrashbin[]) : [], fuseOptions);
const fuse = new Fuse(
!isLoading ? (filterAndSortLatest(trashBinData.data) as InterfaceTrashbin[]) : [],
fuseOptions
);

const filteredData: InterfaceTrashbin[] =
!isLoading && searchTerm === "" ? trashBinData.data : fuse.search(searchTerm).map((result) => result.item);
!isLoading && searchTerm === ""
? filterAndSortLatest(trashBinData.data)
: fuse.search(searchTerm).map((result) => result.item);

function handleRefresh(event: CustomEvent<RefresherEventDetail>) {
queryClient.invalidateQueries({
Expand Down

0 comments on commit 55203eb

Please sign in to comment.