Fixed sorting

This commit is contained in:
Lucas Oliveira 2023-11-21 23:00:05 -03:00
commit 103b497328
2 changed files with 53 additions and 53 deletions

View file

@ -19,15 +19,32 @@ export default function ComponentsComponent({
const { setErrorData, setSuccessData } = useContext(alertContext); const { setErrorData, setSuccessData } = useContext(alertContext);
const [pageSize, setPageSize] = useState(10); const [pageSize, setPageSize] = useState(10);
const [pageIndex, setPageIndex] = useState(1); const [pageIndex, setPageIndex] = useState(1);
const [allData, setAllData] = useState( const [allData, setAllData] = useState(flows);
flows.filter((f) => f.is_component === is_component)
);
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { useEffect(() => {
setAllData(flows.filter((f) => f.is_component === is_component)); setAllData(
console.log(allData); flows
.filter((f) => f.is_component === is_component)
.sort((a, b) => {
if (a?.updated_at && b?.updated_at) {
return (
new Date(b?.updated_at!).getTime() -
new Date(a?.updated_at!).getTime()
);
} else if (a?.updated_at && !b?.updated_at) {
return -1;
} else if (!a?.updated_at && b?.updated_at) {
return 1;
} else {
return (
new Date(b?.date_created!).getTime() -
new Date(a?.date_created!).getTime()
);
}
})
);
}, [flows]); }, [flows]);
useEffect(() => { useEffect(() => {
@ -80,25 +97,7 @@ export default function ComponentsComponent({
<div className="flex w-full flex-col gap-4"> <div className="flex w-full flex-col gap-4">
<div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2"> <div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2">
{!isLoading || data?.length > 0 ? ( {!isLoading || data?.length > 0 ? (
data data?.map((item, idx) => (
?.sort((a, b) => {
if (a?.updated_at && b?.updated_at) {
return (
new Date(b?.updated_at!).getTime() -
new Date(a?.updated_at!).getTime()
);
} else if (a?.updated_at && !b?.updated_at) {
return -1;
} else if (!a?.updated_at && b?.updated_at) {
return 1;
} else {
return (
new Date(b?.date_created!).getTime() -
new Date(a?.date_created!).getTime()
);
}
})
.map((item, idx) => (
<CollectionCardComponent <CollectionCardComponent
onDelete={() => { onDelete={() => {
removeFlow(item.id); removeFlow(item.id);

View file

@ -64,7 +64,8 @@ export default function HomePage(): JSX.Element {
useEffect(() => { useEffect(() => {
setTabId(""); setTabId("");
refreshFlows(); refreshFlows();
}, []); }, [pathname]);
const navigate = useNavigate(); const navigate = useNavigate();
// Personal flows display // Personal flows display