From a7c7ba687bc064c84af38a1a8b0673c97f183435 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Fri, 16 Aug 2024 22:08:19 +0800 Subject: [PATCH 01/23] chore: add schema for post and upvote --- packages/db/src/schema/post.ts | 26 ++++++++++++++++++++++++++ packages/db/src/schema/upvote.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 packages/db/src/schema/post.ts create mode 100644 packages/db/src/schema/upvote.ts diff --git a/packages/db/src/schema/post.ts b/packages/db/src/schema/post.ts new file mode 100644 index 00000000..e6554be9 --- /dev/null +++ b/packages/db/src/schema/post.ts @@ -0,0 +1,26 @@ +import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; +import { relations, sql } from "drizzle-orm"; +import { user } from "./user"; + +export const post = sqliteTable("message", { + id: text("id").primaryKey(), + content: text("content").notNull(), + authorId: text("author_id"), + createdAt: integer("created_at", { mode: "number" }) + .notNull() + .default(sql`(unixepoch())`), + updatedAt: integer("updated_at").$onUpdate(() => sql`(unixepoch())`), + upvoteCount: integer("upvote_count").notNull().default(0), + commentCount: integer("comment_count").notNull().default(0), +}); + +export const messageRelations = relations(post, ({ one }) => ({ + author: one(user, { + fields: [post.authorId], + references: [user.id], + relationName: "receiver", + }), +})); + +export type InsertMessage = typeof post.$inferInsert; +export type SelectMessage = typeof post.$inferSelect; diff --git a/packages/db/src/schema/upvote.ts b/packages/db/src/schema/upvote.ts new file mode 100644 index 00000000..654a586e --- /dev/null +++ b/packages/db/src/schema/upvote.ts @@ -0,0 +1,27 @@ +import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; +import { relations, sql } from "drizzle-orm"; +import { user } from "./user"; +import { post } from "./post"; + +export const upvote = sqliteTable("upvote", { + postId: text("post_id") + .notNull() + .references(() => post.id), + userId: text("user_id") + .notNull() + .references(() => user.id), + createdAt: integer("created_at", { mode: "number" }) + .notNull() + .default(sql`(unixepoch())`), +}); + +export const upvoteRelations = relations(upvote, ({ one }) => ({ + post: one(post, { + fields: [upvote.postId], + references: [post.id], + }), + user: one(user, { + fields: [upvote.userId], + references: [user.id], + }), +})); From 5ff3b2bddc0de445a25cf925614615e796b712a1 Mon Sep 17 00:00:00 2001 From: Dale B Date: Tue, 20 Aug 2024 17:00:01 +0800 Subject: [PATCH 02/23] feat: personal user profile --- .../src/app/(user)/user/[username]/page.tsx | 2 +- .../(user)/user/{[username] => }/loading.tsx | 17 ++- apps/social/src/app/(user)/user/page.tsx | 115 ++++++++++++++++++ apps/social/src/app/components/feed.tsx | 8 +- apps/social/src/app/components/navbar.tsx | 6 +- apps/social/src/app/components/post-card.tsx | 2 +- 6 files changed, 138 insertions(+), 12 deletions(-) rename apps/social/src/app/(user)/user/{[username] => }/loading.tsx (65%) create mode 100644 apps/social/src/app/(user)/user/page.tsx diff --git a/apps/social/src/app/(user)/user/[username]/page.tsx b/apps/social/src/app/(user)/user/[username]/page.tsx index b2ff2988..c2a30966 100644 --- a/apps/social/src/app/(user)/user/[username]/page.tsx +++ b/apps/social/src/app/(user)/user/[username]/page.tsx @@ -63,7 +63,7 @@ export default async function Page({ } return ( -
+
diff --git a/apps/social/src/app/(user)/user/[username]/loading.tsx b/apps/social/src/app/(user)/user/loading.tsx similarity index 65% rename from apps/social/src/app/(user)/user/[username]/loading.tsx rename to apps/social/src/app/(user)/user/loading.tsx index 506a8665..d623ffdd 100644 --- a/apps/social/src/app/(user)/user/[username]/loading.tsx +++ b/apps/social/src/app/(user)/user/loading.tsx @@ -21,14 +21,23 @@ export default function Loading() {
- +
-
- - +
+
+
+ + +
+ + +
+ + +
); diff --git a/apps/social/src/app/(user)/user/page.tsx b/apps/social/src/app/(user)/user/page.tsx new file mode 100644 index 00000000..46fd2221 --- /dev/null +++ b/apps/social/src/app/(user)/user/page.tsx @@ -0,0 +1,115 @@ +import { Suspense } from "react"; +import dynamic from "next/dynamic"; +import { getSession } from "@/lib/auth"; +import { redirect } from "next/navigation"; +import { userPlaceholder } from "@/app/components/feed"; + +import { + Tabs, + TabsContent, + TabsList, + TabsTrigger, +} from "@umamin/ui/components/tabs"; + +import { UserCard } from "@/app/components/user-card"; +import { Skeleton } from "@umamin/ui/components/skeleton"; +import { PostCard } from "@/app/components/post-card"; + +const AdContainer = dynamic(() => import("@umamin/ui/ad")); + +export const metadata = { + title: "Umamin — Inbox", + description: + "Manage your posts securely on Umamin. View, reply, and organize your inbox.", + robots: { + index: false, + follow: false, + }, + openGraph: { + type: "website", + title: "Umamin — Inbox", + description: + "Manage your posts securely on Umamin. View, reply, and organize your inbox.", + url: "https://www.umamin.link/inbox", + }, + twitter: { + card: "summary_large_image", + title: "Umamin — Inbox", + description: + "Manage your posts securely on Umamin. View, reply, and organize your inbox.", + }, +}; + +export default async function UserProfile() { + const { user } = await getSession(); + + if (!user) { + redirect("/login"); + } + + const tabsData = [ + { + name: "Posts", + content: () => ( + + + + + + } + > + + + ), + }, + { + name: "Likes", + content: () => ( + + + + + + } + > + {userPlaceholder.map((props) => ( + + ))} + + ), + }, + ]; + + return ( +
+ + + + + {tabsData.map((tab) => ( + + {tab.name} + + ))} + + + {/* v2-inbox */} + + + {tabsData.map((tab) => ( + + {tab.content()} + + ))} + +
+ ); +} diff --git a/apps/social/src/app/components/feed.tsx b/apps/social/src/app/components/feed.tsx index 2e08917b..adb25f3a 100644 --- a/apps/social/src/app/components/feed.tsx +++ b/apps/social/src/app/components/feed.tsx @@ -1,6 +1,6 @@ import { PostCard } from "./post-card"; -const data = [ +export const userPlaceholder = [ { id: "C-r5lAwpJUg", imageUrl: @@ -33,9 +33,9 @@ const data = [ export function Feed() { return ( -
-
- {data.map((props) => ( +
+
+ {userPlaceholder.map((props) => ( ))}
diff --git a/apps/social/src/app/components/navbar.tsx b/apps/social/src/app/components/navbar.tsx index 1c9c0535..0cc8b52f 100644 --- a/apps/social/src/app/components/navbar.tsx +++ b/apps/social/src/app/components/navbar.tsx @@ -34,7 +34,7 @@ export async function Navbar() { return ( <>