diff --git a/package.json b/package.json index a4f72e91..e99af79e 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "dependencies": { "@google-cloud/local-auth": "^2.1.1", "@rainbow-me/rainbowkit": "^1.0.5", - "@sismo-core/sismo-connect-react": "^0.0.16", - "@sismo-core/sismo-connect-server": "^0.0.16", + "@sismo-core/sismo-connect-react": "^0.0.22", + "@sismo-core/sismo-connect-server": "^0.0.22", "@types/luxon": "^3.3.0", "@types/node": "18.16.1", "@types/react": "18.2.0", diff --git a/src/app/(home)/page.tsx b/src/app/(home)/page.tsx index 7ff07d62..00d98dff 100644 --- a/src/app/(home)/page.tsx +++ b/src/app/(home)/page.tsx @@ -1,5 +1,4 @@ - -import { SpaceType, ZkAppType } from "../../services/spaces-service"; +import { GetAppsOptions, SpaceType, ZkAppType } from "../../services/spaces-service"; import HomeMain from "@/src/components/HomeMain"; import env from "@/src/environments"; import ServiceFactory from "@/src/services/service-factory/service-factory"; @@ -42,7 +41,18 @@ export default async function HomePage() { const spacesService = ServiceFactory.getSpacesService(); const spaces: SpaceType[] = await spacesService.getSpaces(); - const apps: ZkAppType[] = await spacesService.getApps({ sortedBy: "createdAt" }); - return <>{spaces && }; + const appSortOption: GetAppsOptions = { + sortedBy: [ + { label: "createdAt", order: "desc" }, + { + label: "endDate", + order: "desc", + }, + ], + }; + + const apps: ZkAppType[] = await spacesService.getApps(appSortOption); + + return <>{spaces && }; } diff --git a/src/app/explore/apps/page.tsx b/src/app/explore/apps/page.tsx index 399b84d2..ec420a5f 100644 --- a/src/app/explore/apps/page.tsx +++ b/src/app/explore/apps/page.tsx @@ -1,7 +1,7 @@ import { SpaceConfig } from "@/space-configs/types"; import ExploreAppsMain from "@/src/components/ExploreAppsMain"; import ServiceFactory from "@/src/services/service-factory/service-factory"; -import { ZkAppType } from "@/src/services/spaces-service"; +import { GetAppsOptions, ZkAppType } from "@/src/services/spaces-service"; export type SpaceImportedImage = { config: SpaceConfig; @@ -11,7 +11,17 @@ export type SpaceImportedImage = { export default async function ExplorePage() { const spacesService = ServiceFactory.getSpacesService(); - const apps: ZkAppType[] = await spacesService.getApps({ sortedBy: "createdAt" }); + const appSortOption: GetAppsOptions = { + sortedBy: [ + { label: "createdAt", order: "desc" }, + { + label: "endDate", + order: "desc", + }, + ], + }; + + const apps: ZkAppType[] = await spacesService.getApps(appSortOption); return ( diff --git a/src/services/spaces-service/spaces-service.ts b/src/services/spaces-service/spaces-service.ts index 5dc51ba8..6d541236 100644 --- a/src/services/spaces-service/spaces-service.ts +++ b/src/services/spaces-service/spaces-service.ts @@ -12,8 +12,13 @@ import { AuthType } from "@sismo-core/sismo-connect-server"; import getImgSrcFromConfig from "@/src/utils/getImgSrcFromConfig"; import { SpaceConfig } from "@/space-configs/types"; +export type AppSortByOption = { + label: "createdAt" | "endDate"; + order: "asc" | "desc"; +}; + export type GetAppsOptions = { - sortedBy?: "createdAt"; + sortedBy?: AppSortByOption[]; where?: { spaceSlug?: string; appSlug?: string; @@ -48,18 +53,37 @@ export class SpacesService { public async getApps(options?: GetAppsOptions) { let apps = await this._getAllApps(); - if (options?.sortedBy === "createdAt") { - apps.sort((a, b) => { - return b.createdAt.getTime() - a.createdAt.getTime(); - }); + for (const sortedBy of options?.sortedBy ?? []) { + switch (sortedBy?.label) { + case "createdAt": + apps.sort((a, b) => { + return sortedBy.order === "desc" + ? b.createdAt.getTime() - a.createdAt.getTime() + : a.createdAt.getTime() - b.createdAt.getTime(); + }); + break; + case "endDate": + apps.sort((a, b) => { + const aEndDate = a?.endDate?.getTime?.(); + const bEndDate = b?.endDate?.getTime?.(); + + if (isNaN(aEndDate) && isNaN(bEndDate)) return 0; + if (isNaN(aEndDate)) return sortedBy.order === "desc" ? -1 : 1; + if (isNaN(bEndDate)) return sortedBy.order === "desc" ? 1 : -1; + return sortedBy.order === "desc" ? bEndDate - aEndDate: aEndDate - bEndDate; + }); + break; + default: + break; + } } if (options?.where?.appSlug) { - apps = apps.filter((app) => app.slug === options?.where?.appSlug); + apps = apps.filter((app) => app.slug === options.where.appSlug); } if (options?.where?.spaceSlug) { - apps = apps.filter((app) => app.space.slug === options?.where?.spaceSlug); + apps = apps.filter((app) => app.space.slug === options.where.spaceSlug); } return apps; diff --git a/yarn.lock b/yarn.lock index 20f7c3e1..1c1cfcba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2596,27 +2596,27 @@ ethers "^5.6.1" tslib "^2.4.0" -"@sismo-core/sismo-connect-client@0.0.16": - version "0.0.16" - resolved "https://registry.npmjs.org/@sismo-core/sismo-connect-client/-/sismo-connect-client-0.0.16.tgz#28f1c8e586509bf6272fc42969c8b13d837e3cbc" - integrity sha512-SO33SjpVPy2rVSIqE3B568+bQfNGe1T5ieh1pxNR68W6sAeLGU+PtzRegdKNbirFLVhVTi0Ky/vfmqI12Ehmng== +"@sismo-core/sismo-connect-client@0.0.20": + version "0.0.20" + resolved "https://registry.yarnpkg.com/@sismo-core/sismo-connect-client/-/sismo-connect-client-0.0.20.tgz#d0337f1e6c678b2e67f0c8dff2794c4a4e869e94" + integrity sha512-2AEfnVGQfhEwWqyTtBF9o2kOlm22cPmM+qG70zyZW+oN169rT9b9MMqM9qkWkknGm6aTPg8wq0dBQUbmaG8DsA== dependencies: "@ethersproject/bignumber" "5.7.0" js-base64 "^3.7.5" pako "^2.1.0" viem "^0.3.1" -"@sismo-core/sismo-connect-react@^0.0.16": - version "0.0.16" - resolved "https://registry.npmjs.org/@sismo-core/sismo-connect-react/-/sismo-connect-react-0.0.16.tgz#9c660f0fcd71d4497b5c1cc98f37c8b1b439e4d0" - integrity sha512-hZG+3AAUmTZ4Jsr9zypLfhWDRWvInbfBgVwNjnVpWPa1PUmfhVxn69b/zJL756TfENkgZqhIpknp1cvUN0Hmnw== +"@sismo-core/sismo-connect-react@^0.0.22": + version "0.0.22" + resolved "https://registry.yarnpkg.com/@sismo-core/sismo-connect-react/-/sismo-connect-react-0.0.22.tgz#01097c31ed3f6ff510b4be25f0c5a513ac131f92" + integrity sha512-UQA70pma6nhNzQnIJezJTlHCky+gZbOE8RowNo6dG0k/eMkv3OYNihv1oYJpjJ/H2Y/wMOyZsyHZE8UZsZlSnQ== dependencies: - "@sismo-core/sismo-connect-client" "0.0.16" + "@sismo-core/sismo-connect-client" "0.0.20" -"@sismo-core/sismo-connect-server@^0.0.16": - version "0.0.16" - resolved "https://registry.npmjs.org/@sismo-core/sismo-connect-server/-/sismo-connect-server-0.0.16.tgz#b32b90cc976197d38679bfecd09b56637a6471a8" - integrity sha512-E3mzc3OD0ZUJUKssu4eT86PxKDsOeI62rbwPQQDjrqPG+822G9YsbsjTKuzk72VaVimdohbbfmguoM7IiP5Fkg== +"@sismo-core/sismo-connect-server@^0.0.22": + version "0.0.22" + resolved "https://registry.yarnpkg.com/@sismo-core/sismo-connect-server/-/sismo-connect-server-0.0.22.tgz#61c45a40c7deb38e9381ee299233b72d36f03369" + integrity sha512-wX8mBrjfmzvHFurSDmQvEtDNgqXkLZHQ078oKoLOtouufISMK4Vh3foU1Cfat66/cfqzwmZ8swROa5JwoQgdJA== dependencies: "@ethersproject/bignumber" "^5.7.0" "@sismo-core/hydra-s3" "^1.0.0"