diff --git a/web/src/pages/Resources.tsx b/web/src/pages/Resources.tsx index a4767f07..44f248f1 100644 --- a/web/src/pages/Resources.tsx +++ b/web/src/pages/Resources.tsx @@ -1,4 +1,5 @@ import { Divider, IconButton, Input, Tooltip } from "@mui/joy"; +import dayjs from "dayjs"; import { includes } from "lodash-es"; import { useEffect, useState } from "react"; import Empty from "@/components/Empty"; @@ -13,22 +14,15 @@ import { Resource } from "@/types/proto/api/v1/resource_service"; import { useTranslate } from "@/utils/i18n"; function groupResourcesByDate(resources: Resource[]) { - const grouped = new Map(); + const grouped = new Map(); resources - .sort((a: Resource, b: Resource) => { - const a_date = new Date(a.createTime as any); - const b_date = new Date(b.createTime as any); - return b_date.getTime() - a_date.getTime(); - }) + .sort((a, b) => dayjs(b.createTime).unix() - dayjs(a.createTime).unix()) .forEach((item) => { - const date = new Date(item.createTime as any); - const year = date.getFullYear(); - const month = date.getMonth() + 1; - const timestamp = Date.UTC(year, month - 1, 1); - if (!grouped.has(timestamp)) { - grouped.set(timestamp, []); + const monthStr = dayjs(item.createTime).format("YYYY-MM"); + if (!grouped.has(monthStr)) { + grouped.set(monthStr, []); } - grouped.get(timestamp)?.push(item); + grouped.get(monthStr)?.push(item); }); return grouped; } @@ -101,13 +95,14 @@ const Resources = () => { ) : (
- {Array.from(groupedResources.entries()).map(([timestamp, resources]) => { - const date = new Date(timestamp); + {Array.from(groupedResources.entries()).map(([monthStr, resources]) => { return ( -
+
- {date.getFullYear()} - {date.toLocaleString(i18n.language, { month: "short" })} + {dayjs(monthStr).year()} + + {dayjs(monthStr).toDate().toLocaleString(i18n.language, { month: "short" })} +
{resources.map((resource) => {