Skip to content

Commit

Permalink
update tailwind & drizzle version
Browse files Browse the repository at this point in the history
  • Loading branch information
djsisson committed Nov 23, 2024
1 parent f929497 commit fb23afc
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 144 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@radix-ui/react-tooltip": "^1.1.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.36.0",
"drizzle-orm": "^0.36.4",
"jose": "^5.6.3",
"lucide-react": "^0.454.0",
"next": "^15.0.2",
Expand All @@ -42,19 +42,19 @@
},
"devDependencies": {
"@faker-js/faker": "^9.0.0",
"@tailwindcss/postcss": "^4.0.0-alpha.31",
"@tailwindcss/postcss": "^4.0.0-beta.2",
"@types/mdx": "^2.0.13",
"@types/node": "^20",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"babel-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
"drizzle-kit": "^0.27.0",
"drizzle-kit": "^0.28.1",
"eslint": "^9.12.0",
"eslint-config-next": "^15.0.0",
"eslint-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^4.0.0-alpha.31",
"tailwindcss": "^4.0.0-beta.2",
"tsx": "^4.19.2",
"typescript": "^5.5.3"
},
Expand Down
29 changes: 29 additions & 0 deletions src/app/forum/components/ActiveLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";

export default function ActiveLink({
pathname,
children,
}: {
pathname: string;
children: React.ReactNode;
}) {
const activePathname = usePathname();

const currentlyActive =
activePathname.slice(activePathname.length - pathname.length) == pathname;

return (
<Link href={pathname}>
<div
className={`flex justify-center p-4 py-1 rounded-lg link${
currentlyActive ? " bg-blue-600" : " hover:bg-blue-400"
}`}
>
{children}
</div>
</Link>
);
}
29 changes: 28 additions & 1 deletion src/app/forum/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import { dbClient } from "@/db/forum/db";
import { messages } from "@/db/forum/schema";
import { getUser } from "@/lib/auth-client";
import { desc, isNull } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { upsertTags } from "../lib/helper_functions";

export default async function Home({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const userId = await getUser();

async function NewPostFunction(formData: FormData) {
"use server";
try {
const msg = formData.get("message") as string;
const msgId = await dbClient()
.db.insert(messages)
.values({
message: msg,
user_id: userId?.sub as string,
})
.returning({ id: messages.id });
await upsertTags(msgId[0]?.id, msg, false);
revalidatePath("/forum/home");
} catch (error) {
console.log(error);
}
}

export default async function Home() {
const posts = await dbClient()
.db.select()
.from(messages)
Expand Down
38 changes: 38 additions & 0 deletions src/app/forum/lib/helper_functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { dbClient } from "@/db/forum/db";
import { eq, inArray, sql } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { hashtag_messages, hashtags, messages } from "@/db/forum/schema";

export const upsertTags = async (
msgid: string,
msg: string,
editmsg: boolean = false,
) => {
const tags = msg.toLowerCase().match(/#[\p{L}0-9-_]+/giu);

if (!tags || tags.length == 0) return;
tags.forEach((x) => revalidatePath(`forum/posts/tags/${x.slice(1)}`));

if (editmsg) {
await dbClient()
.db.delete(hashtag_messages)
.where(eq(hashtag_messages.message_id, msgid));
}

await dbClient()
.db.insert(hashtags)
.values(tags.map((x) => ({ hashtag: x })))
.onConflictDoNothing();

await dbClient()
.db.insert(hashtag_messages)
.select(
dbClient()
.db.select({
hashtag_id: hashtags.id,
message_id: sql`${msgid}`.as("message_id"),
})
.from(hashtags)
.where(inArray(hashtags.hashtag, tags)),
);
};
Loading

0 comments on commit fb23afc

Please sign in to comment.