Skip to content

Commit 010c7d5

Browse files
committed
added user field to application, some improvements
1 parent 5301d57 commit 010c7d5

14 files changed

+1116
-2272
lines changed

app/applications/page.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getApplications } from "@/lib/actions";
2+
import { notFound } from "next/navigation";
3+
import ApplicationsContainer from "@/components/ApplicationsContainer";
4+
5+
type PageProps = {
6+
searchParams: {
7+
user: string;
8+
};
9+
};
10+
11+
const MyApplications = async ({ searchParams }: PageProps) => {
12+
const user = searchParams.user;
13+
14+
if (!user) {
15+
return notFound();
16+
}
17+
18+
const applications = await getApplications(
19+
(applications) => applications.user === user
20+
);
21+
22+
return (
23+
<ApplicationsContainer applications={applications} className="mt-24" />
24+
);
25+
};
26+
27+
export default MyApplications;

app/page.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Inter } from "next/font/google";
2-
import Hero from "../components/Hero";
3-
import EditorsPick from "../components/EditorsPick";
4-
import AllApps from "../components/AllApps";
5-
import { getApplications } from "../lib/actions";
2+
import Hero from "@/components/Hero";
3+
import { getApplications } from "@/lib/actions";
4+
import ApplicationsContainer from "@/components/ApplicationsContainer";
65

76
const inter = Inter({ subsets: ["latin"] });
87

@@ -14,8 +13,16 @@ const Home = async () => {
1413
<div className="grid grid-cols-1 gap-4 sm:grid-cols-6"></div>
1514

1615
<Hero />
17-
<EditorsPick applications={applications?.slice(0, 3)} />
18-
<AllApps applications={applications} />
16+
<ApplicationsContainer
17+
header="Our Editor's Pick"
18+
applications={applications?.slice(0, 3)}
19+
className="mt-24"
20+
/>
21+
<ApplicationsContainer
22+
header="All Available Tools"
23+
applications={applications}
24+
className="mt-24"
25+
/>
1926
</div>
2027
);
2128
};

components/AllApps.tsx

-24
This file was deleted.

components/ApplicationsContainer.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { FC } from "react";
2+
import AppCard from "./AppCard";
3+
import { H2 } from "./Text";
4+
import { cn } from "@/lib/utils";
5+
6+
type ApplicationsContainerProps = {
7+
applications: IApplication[];
8+
header?: string;
9+
className?: string;
10+
};
11+
12+
const ApplicationsContainer: FC<ApplicationsContainerProps> = ({
13+
header,
14+
applications,
15+
className,
16+
}) => {
17+
return (
18+
<div className={cn(className, "container px-6 pb-2 mx-auto")}>
19+
{header && (
20+
<H2 className="text-center text-transparent mb-14 bg-gradient-to-br bg-clip-text from-primary to-slate-500">
21+
{header}
22+
</H2>
23+
)}
24+
<div className="grid justify-center gap-4 cursor-pointer md:grid-cols-2 lg:grid-cols-3 md:gap-6 lg:gap-12">
25+
{applications?.map((data) => (
26+
<AppCard key={data.id} application={data} />
27+
))}
28+
</div>
29+
</div>
30+
);
31+
};
32+
33+
export default ApplicationsContainer;

components/EditorsPick.tsx

-31
This file was deleted.

components/Nav.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
'use client';
1+
"use client";
22

33
import { Fragment, useState } from "react";
4-
import { Dialog, Menu, Transition } from "@headlessui/react";
5-
import { Bars4Icon, CheckIcon } from "@heroicons/react/24/outline";
4+
import { useAccount } from "wagmi";
5+
import { Menu, Transition } from "@headlessui/react";
6+
import { Bars4Icon } from "@heroicons/react/24/outline";
67
import NewApplication from "./NewApplication";
78
import Link from "next/link";
89
import PolisLogo from "./icons/PolisLogo";
910
import { ConnectButton } from "./ConnectButton";
1011

1112
export const Nav = () => {
1213
const [open, setOpen] = useState(false);
14+
const { address } = useAccount();
1315

1416
return (
1517
<>
@@ -21,7 +23,7 @@ export const Nav = () => {
2123
<div className="hidden lg:block">
2224
<div className="flex items-center gap-7">
2325
<Link
24-
href="/application"
26+
href={`/applications?user=${address}`}
2527
className="duration-200 ease-in-out hover:opacity-50"
2628
>
2729
My Application

components/NewApplication/Steps/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { FC, useState, useTransition } from "react";
3-
import { useRouter } from "next/navigation";
43
import cn from "classnames";
4+
import { useAccount } from "wagmi";
55
import { Tab } from "@headlessui/react";
66
import {
77
ChevronDoubleRightIcon,
@@ -24,7 +24,7 @@ type NewApplicationStepsProps = {
2424
const NewApplicationSteps: FC<NewApplicationStepsProps> = ({ closeModal }) => {
2525
const TOTAL_STEPS = 3;
2626
const [currentStep, setCurrentStep] = useState(0);
27-
const router = useRouter();
27+
const { address } = useAccount();
2828
const [isPending, startTransition] = useTransition();
2929
const methods = useForm<IApplicationInput>({
3030
defaultValues: {
@@ -73,7 +73,10 @@ const NewApplicationSteps: FC<NewApplicationStepsProps> = ({ closeModal }) => {
7373
}
7474

7575
startTransition(() => {
76-
submitApplication({ images: formData, data: JSON.stringify(rest) });
76+
submitApplication({
77+
images: formData,
78+
data: JSON.stringify({ ...rest, user: address }),
79+
});
7780
closeModal();
7881
});
7982
});

lib/actions.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import {
66
storeDatabase,
77
ApplicationNode,
88
query,
9+
Filter,
910
} from "./database";
1011
import { getDirectoryContent, add } from "./ipfs";
1112
import { revalidatePath } from "next/cache";
1213

13-
export const getApplications = async (): Promise<IApplication[]> => {
14-
const applicationNodes = await retrieveDatabase();
14+
export const getApplications = async (
15+
filter?: Filter
16+
): Promise<IApplication[]> => {
17+
const applicationNodes = await query(filter);
1518

1619
const applications = Array.from(applicationNodes.values()).map(
1720
async ({ screenshots: screenshotsHash, logo: logoHash, ...rest }) => {
@@ -105,5 +108,5 @@ export const submitApplication = async ({
105108
});
106109

107110
await storeDatabase(newState);
108-
revalidatePath("/")
111+
revalidatePath("/");
109112
};

lib/database.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ export type ApplicationNode = {
66
title: string;
77
category: string[];
88
description: string;
9+
user: string;
910
applicationUrl?: string;
1011
repoUrl?: string;
1112
logo?: string;
1213
screenshots?: string;
1314
};
1415

15-
type Query = (node: ApplicationNode) => boolean;
16+
export type Filter = (node: ApplicationNode) => boolean;
1617

1718
export const addNode = (
1819
state: Map<string, ApplicationNode>,
@@ -49,14 +50,14 @@ export const storeDatabase = async (state: Map<string, ApplicationNode>) => {
4950

5051
export const retrieveDatabase = async () => {
5152
const hash = await getcurrentHash();
52-
53+
5354
const json = await cat(hash);
5455
return deserializeDatabase(json);
5556
};
5657

57-
export const query = async (predicate: Query) => {
58+
export const query = async (predicate?: Filter) => {
5859
const state = await retrieveDatabase();
5960
const nodes = Array.from(state.values());
60-
const matches = nodes.filter(predicate);
61+
const matches = nodes.filter(predicate || Boolean);
6162
return matches;
6263
};

lib/utils.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ClassValue, clsx } from "clsx"
2+
import { twMerge } from "tailwind-merge"
3+
4+
export const cn= (...inputs: ClassValue[]) => {
5+
return twMerge(clsx(inputs))
6+
}

0 commit comments

Comments
 (0)