Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: expired sorting #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 14 additions & 4 deletions src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 && <HomeMain spaces={spaces} apps={apps}/>}</>;
const appSortOption: GetAppsOptions = {
sortedBy: [
{ label: "createdAt", order: "desc" },
{
label: "endDate",
order: "desc",
},
],
};

const apps: ZkAppType[] = await spacesService.getApps(appSortOption);

return <>{spaces && <HomeMain spaces={spaces} apps={apps} />}</>;
}
14 changes: 12 additions & 2 deletions src/app/explore/apps/page.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 (
<ExploreAppsMain apps={apps} />
Expand Down
38 changes: 31 additions & 7 deletions src/services/spaces-service/spaces-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2596,27 +2596,27 @@
ethers "^5.6.1"
tslib "^2.4.0"

"@sismo-core/[email protected].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/[email protected].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"
Expand Down
Loading