Skip to content

Commit 50fffcc

Browse files
committedMar 24, 2024··
chore: adjust data structures
1 parent a765099 commit 50fffcc

File tree

12 files changed

+77
-35
lines changed

12 files changed

+77
-35
lines changed
 

‎.env.example

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ DB_AUTH_TOKEN='YOUR_DB_NAME'
1212
# @see https://next-auth.js.org/configuration/options#secret
1313
AUTH_SECRET='supersecret'
1414

15-
# Preconfigured Discord OAuth provider, works out-of-the-box
16-
# @see https://next-auth.js.org/providers/discord
17-
AUTH_DISCORD_ID=''
18-
AUTH_DISCORD_SECRET=''
15+
# Preconfigured Github OAuth provider, works out-of-the-box
16+
# @see https://next-auth.js.org/providers/github
17+
AUTH_GITHUB_ID=''
18+
AUTH_GITHUB_SECRET=''
19+
20+
# Unsplash API Keys
21+
UNSPLASH_ACCESS_KEY=''
22+
UNSPLASH_SECRET_KEY=''
23+
24+
# Upstash Redis Credentials
25+
REDIS_URL=''
26+
REDIS_TOKEN=''
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import React from "react";
22

33
import { NewsArticle } from "~/app/_components/details/news-article";
4-
import { exampleData } from "~/app/example-data";
5-
6-
export function generateStaticParams(): { itemId: string }[] {
7-
return exampleData.map((item) => ({
8-
itemId: item.id,
9-
}));
10-
}
114

125
export default async function Page({
136
params,
147
}: {
15-
params: { itemId: string };
8+
params: { articleUrl: string; type: string };
169
}): Promise<React.ReactElement> {
1710
// const articleData = exampleData.filter(
1811
// (item) => item.id === params.itemId,
@@ -21,6 +14,8 @@ export default async function Page({
2114
// (res) => res.filter((item) => item.id === params.itemId)[0],
2215
// );
2316

24-
return <NewsArticle url={decodeURIComponent(params.itemId)} />;
17+
if (params.type === "news")
18+
return <NewsArticle url={decodeURIComponent(params.articleUrl)} />;
19+
return <div>Something is not quite right</div>;
2520
// if (articleData?.type === "news") return <div>Article not found</div>;
2621
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DashboardItem } from "~/app/example-data";
12
import { DashboardList } from "~/app/_components/dashboard-list";
23
import { getRssData } from "~/app/example-data";
34

@@ -6,9 +7,22 @@ export const revalidate = 3600;
67
export default async function Page(): Promise<React.ReactElement> {
78
const rssData = await getRssData();
89

10+
const items: DashboardItem[] | undefined = rssData.items?.map((item) => ({
11+
title: item.title ?? "",
12+
id: item.id,
13+
contentSnippet: item.contentSnippet ?? "",
14+
icon: "",
15+
details: {
16+
type: "news",
17+
articleUrl: item.link ?? "",
18+
date: item.isoDate ?? "",
19+
source: rssData.title ?? "",
20+
},
21+
}));
22+
923
return (
1024
<div className="relative max-w-full p-2 md:p-8">
11-
<DashboardList rssData={rssData} />
25+
{items !== undefined ? <DashboardList items={items} /> : null}
1226
</div>
1327
);
1428
}

‎apps/nextjs/src/app/(dashboard)/details/[itemId]/page.tsx renamed to ‎apps/nextjs/src/app/(dashboard)/details/[type]/[articleUrl]/page.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { NewsArticle } from "~/app/_components/details/news-article";
1313
export async function generateMetadata({
1414
params,
1515
}: {
16-
params: { itemId?: string };
16+
params: { articleUrl?: string; type?: string };
1717
}): Promise<Metadata> {
18-
const url = decodeURIComponent(params.itemId ?? "");
18+
const url = decodeURIComponent(params.articleUrl ?? "");
1919
let extractedData;
2020
try {
2121
try {
@@ -60,12 +60,14 @@ export async function generateMetadata({
6060
export default function Page({
6161
params,
6262
}: {
63-
params: { itemId: string };
63+
params: { articleUrl: string; type: string };
6464
}): React.ReactElement {
6565
// const articleData = exampleData.filter(
6666
// (item) => item.id === params.itemId,
6767
// )[0];
6868

69-
return <NewsArticle url={decodeURIComponent(params.itemId)} />;
69+
if (params.type === "news")
70+
return <NewsArticle url={decodeURIComponent(params.articleUrl)} />;
71+
return <div>Something is not quite right</div>;
7072
// if (articleData?.type === "news") return <div>Article not found</div>;
7173
}

‎apps/nextjs/src/app/_components/dashboard-item.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
import { usePathname } from "next/navigation";
44
import { LinkButton } from "@ai-inbox/ui/button";
5-
import { IconNews } from "@tabler/icons-react";
5+
import { IconMail, IconNews } from "@tabler/icons-react";
66

7-
import type { NewsItem } from "../example-data";
7+
import type { DashboardItem } from "../example-data";
88

99
export function DashboardItem({
1010
item,
1111
}: {
12-
item: NewsItem;
12+
item: DashboardItem;
1313
}): React.ReactElement {
1414
// eslint-disable-next-line react/jsx-no-useless-fragment -- i need it to be a react node
1515
let icon = <></>;
16-
switch (item.type) {
17-
// case "email":
18-
// icon = <IconMail size={20} className="shrink-0" />;
19-
// break;
20-
case "newsItem":
16+
switch (item.details.type) {
17+
case "email":
18+
icon = <IconMail size={20} className="shrink-0" />;
19+
break;
20+
case "news":
2121
icon = <IconNews size={20} className="shrink-0" />;
2222
break;
2323
// case "other":
@@ -28,7 +28,7 @@ export function DashboardItem({
2828

2929
return (
3030
<LinkButton
31-
href={`/details/${item.id}`}
31+
href={`/details/${item.details.type}/${item.id}`}
3232
variant={pathname.includes(`/details/${item.id}`) ? "secondary" : "ghost"}
3333
className="min-w-0 max-w-full shrink grow items-center justify-start gap-2 p-1 px-1"
3434
>

‎apps/nextjs/src/app/_components/dashboard-list.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
import { Input } from "@ai-inbox/ui/input";
1212
import { IconFilter, IconSortAscending } from "@tabler/icons-react";
1313

14-
import type { NewsFeed } from "../example-data";
14+
import type { DashboardItem as DashboardItemType } from "../example-data";
1515
import { DashboardItem } from "~/app/_components/dashboard-item";
1616
import { feeds } from "~/app/feeds";
1717

1818
export function DashboardList({
19-
rssData,
19+
items,
2020
}: {
21-
rssData: NewsFeed;
21+
items: DashboardItemType[];
2222
}): React.ReactElement {
2323
const [searchString, setSearchString] = useState("");
2424
return (
@@ -64,8 +64,8 @@ export function DashboardList({
6464
</DropdownMenu>
6565
</div>
6666
<div className="flex w-full flex-col gap-2">
67-
{rssData.items.map((item) =>
68-
item.title?.toLowerCase().includes(searchString.toLowerCase()) ? (
67+
{items.map((item) =>
68+
item.title.toLowerCase().includes(searchString.toLowerCase()) ? (
6969
<DashboardItem key={item.id} item={item} />
7070
) : null,
7171
)}

‎apps/nextjs/src/app/example-data.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,32 @@ export type NewsItem = Parser.Item & {
114114
export type NewsFeed = Omit<Parser.Output<undefined>, "items"> & {
115115
id: string;
116116
type: "newsFeed";
117-
items: NewsItem[];
117+
items?: NewsItem[];
118118
};
119119

120120
export type NewsSource = {
121121
title: string;
122+
icon: string;
122123
url: string;
123124
feeds: NewsFeed[];
124125
};
126+
127+
export type DashboardItem = {
128+
id: string;
129+
title: string;
130+
contentSnippet: string;
131+
icon: string;
132+
details: DashboardDetails;
133+
};
134+
135+
export type DashboardDetails =
136+
| {
137+
type: "news";
138+
articleUrl: string;
139+
date: Date | string;
140+
source: string;
141+
}
142+
| {
143+
type: "email";
144+
id: string;
145+
};

‎apps/nextjs/src/env.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const env = createEnv({
1717
DB_AUTH_TOKEN: z.string(),
1818
UNSPLASH_ACCESS_KEY: z.string(),
1919
UNSPLASH_SECRET_KEY: z.string(),
20+
// UPSTASH_REDIS_REST_TOKEN: z.string(),
21+
// UPSTASH_REDIS_REST_URL: z.string(),
2022
},
2123
/**
2224
* Specify your client-side environment variables schema here.

‎bun.lockb

0 Bytes
Binary file not shown.

‎packages/auth/env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { z } from "zod";
33

44
export const env = createEnv({
55
server: {
6-
AUTH_DISCORD_ID: z.string().min(1),
7-
AUTH_DISCORD_SECRET: z.string().min(1),
6+
AUTH_GITHUB_ID: z.string().min(1),
7+
AUTH_GITHUB_SECRET: z.string().min(1),
88
AUTH_SECRET:
99
process.env.NODE_ENV === "production"
1010
? z.string().min(1)

0 commit comments

Comments
 (0)
Please sign in to comment.