migration of comments
This commit is contained in:
@@ -11,7 +11,7 @@ import PostSorting from "~/components/blog/PostSorting";
|
||||
// Server function to fetch posts
|
||||
const getPosts = cache(async (category: string, privilegeLevel: string) => {
|
||||
"use server";
|
||||
|
||||
|
||||
let query = `
|
||||
SELECT
|
||||
Post.id,
|
||||
@@ -45,18 +45,19 @@ const getPosts = cache(async (category: string, privilegeLevel: string) => {
|
||||
}
|
||||
}
|
||||
query += ` GROUP BY Post.id, Post.title, Post.subtitle, Post.body, Post.banner_photo, Post.date, Post.published, Post.category, Post.author_id, Post.reads, Post.attachments ORDER BY Post.date DESC;`;
|
||||
|
||||
|
||||
const conn = ConnectionFactory();
|
||||
const results = await conn.execute(query);
|
||||
const posts = results.rows;
|
||||
|
||||
const postIds = posts.map((post: any) => post.id);
|
||||
const tagQuery = postIds.length > 0
|
||||
? `SELECT * FROM Tag WHERE post_id IN (${postIds.join(", ")})`
|
||||
: "SELECT * FROM Tag WHERE 1=0";
|
||||
const tagQuery =
|
||||
postIds.length > 0
|
||||
? `SELECT * FROM Tag WHERE post_id IN (${postIds.join(", ")})`
|
||||
: "SELECT * FROM Tag WHERE 1=0";
|
||||
const tagResults = await conn.execute(tagQuery);
|
||||
const tags = tagResults.rows;
|
||||
|
||||
|
||||
let tagMap: Record<string, number> = {};
|
||||
tags.forEach((tag: any) => {
|
||||
tagMap[tag.value] = (tagMap[tag.value] || 0) + 1;
|
||||
@@ -67,24 +68,32 @@ const getPosts = cache(async (category: string, privilegeLevel: string) => {
|
||||
|
||||
export default function BlogIndex() {
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
|
||||
// TODO: Get actual privilege level from session/auth
|
||||
const privilegeLevel = "anonymous";
|
||||
|
||||
|
||||
const category = () => searchParams.category || "all";
|
||||
const sort = () => searchParams.sort || "newest";
|
||||
const filters = () => searchParams.filter || "";
|
||||
|
||||
|
||||
const data = createAsync(() => getPosts(category(), privilegeLevel));
|
||||
|
||||
const bannerImage = () => category() === "project" ? "/blueprint.jpg" : "/manhattan-night-skyline.jpg";
|
||||
const pageTitle = () => category() === "all" ? "Posts" : category() === "project" ? "Projects" : "Blog";
|
||||
|
||||
const bannerImage = () =>
|
||||
category() === "project"
|
||||
? "/blueprint.jpg"
|
||||
: "/manhattan-night-skyline.jpg";
|
||||
const pageTitle = () =>
|
||||
category() === "all"
|
||||
? "Posts"
|
||||
: category() === "project"
|
||||
? "Projects"
|
||||
: "Blog";
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title>{pageTitle()} | Michael Freno</Title>
|
||||
|
||||
<div class="min-h-screen overflow-x-hidden bg-white dark:bg-zinc-900">
|
||||
|
||||
<div class="bg-base min-h-screen overflow-x-hidden">
|
||||
<div class="z-30">
|
||||
<div class="page-fade-in z-20 mx-auto h-80 sm:h-96 md:h-[30vh]">
|
||||
<div class="image-overlay fixed h-80 w-full brightness-75 sm:h-96 md:h-[50vh]">
|
||||
@@ -95,7 +104,7 @@ export default function BlogIndex() {
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="text-shadow fixed top-36 z-10 w-full select-text text-center tracking-widest text-white brightness-150 sm:top-44 md:top-[20vh]"
|
||||
class="text-shadow fixed top-36 z-10 w-full text-center tracking-widest text-white brightness-150 select-text sm:top-44 md:top-[20vh]"
|
||||
style={{ "pointer-events": "none" }}
|
||||
>
|
||||
<div class="z-10 text-5xl font-light tracking-widest">
|
||||
@@ -104,8 +113,8 @@ export default function BlogIndex() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="relative z-40 mx-auto -mt-16 min-h-screen w-11/12 rounded-t-lg bg-zinc-50 pb-24 pt-8 shadow-2xl dark:bg-zinc-800 sm:-mt-20 md:mt-0 md:w-5/6 lg:w-3/4">
|
||||
|
||||
<div class="bg-surface0 relative z-40 mx-auto -mt-16 min-h-screen w-11/12 rounded-t-lg pt-8 pb-24 shadow-2xl sm:-mt-20 md:mt-0 md:w-5/6 lg:w-3/4">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div class="mx-auto pt-48">
|
||||
@@ -119,8 +128,8 @@ export default function BlogIndex() {
|
||||
href="/blog?category=all"
|
||||
class={`rounded border px-4 py-2 transition-all duration-300 ease-out active:scale-90 ${
|
||||
category() === "all"
|
||||
? "border-orange-500 bg-orange-400 text-white dark:border-orange-700 dark:bg-orange-700"
|
||||
: "border-zinc-800 hover:bg-zinc-200 dark:border-white dark:hover:bg-zinc-700"
|
||||
? "border-peach bg-peach text-base"
|
||||
: "border-text hover:brightness-125"
|
||||
}`}
|
||||
>
|
||||
All
|
||||
@@ -129,8 +138,8 @@ export default function BlogIndex() {
|
||||
href="/blog?category=blog"
|
||||
class={`rounded border px-4 py-2 transition-all duration-300 ease-out active:scale-90 ${
|
||||
category() === "blog"
|
||||
? "border-orange-500 bg-orange-400 text-white dark:border-orange-700 dark:bg-orange-700"
|
||||
: "border-zinc-800 hover:bg-zinc-200 dark:border-white dark:hover:bg-zinc-700"
|
||||
? "border-peach bg-peach text-base"
|
||||
: "border-text hover:brightness-125"
|
||||
}`}
|
||||
>
|
||||
Blog
|
||||
@@ -139,28 +148,30 @@ export default function BlogIndex() {
|
||||
href="/blog?category=project"
|
||||
class={`rounded border px-4 py-2 transition-all duration-300 ease-out active:scale-90 ${
|
||||
category() === "project"
|
||||
? "border-blue-500 bg-blue-400 text-white dark:border-blue-700 dark:bg-blue-700"
|
||||
: "border-zinc-800 hover:bg-zinc-200 dark:border-white dark:hover:bg-zinc-700"
|
||||
? "border-blue bg-blue text-base"
|
||||
: "border-text hover:brightness-125"
|
||||
}`}
|
||||
>
|
||||
Projects
|
||||
</A>
|
||||
</div>
|
||||
|
||||
<PostSortingSelect type={category() === "project" ? "project" : "blog"} />
|
||||
|
||||
|
||||
<PostSortingSelect
|
||||
type={category() === "project" ? "project" : "blog"}
|
||||
/>
|
||||
|
||||
<Show when={data() && Object.keys(data()!.tagMap).length > 0}>
|
||||
<TagSelector
|
||||
tagMap={data()!.tagMap}
|
||||
category={category() === "project" ? "project" : "blog"}
|
||||
<TagSelector
|
||||
tagMap={data()!.tagMap}
|
||||
category={category() === "project" ? "project" : "blog"}
|
||||
/>
|
||||
</Show>
|
||||
|
||||
|
||||
<Show when={privilegeLevel === "admin"}>
|
||||
<div class="mt-2 flex justify-center md:mt-0 md:justify-end">
|
||||
<A
|
||||
href="/blog/create"
|
||||
class="rounded border border-zinc-800 px-4 py-2 transition-all duration-300 ease-out hover:bg-zinc-200 active:scale-90 dark:border-white dark:hover:bg-zinc-700 md:mr-4"
|
||||
class="border-text rounded border px-4 py-2 transition-all duration-300 ease-out hover:brightness-125 active:scale-90 md:mr-4"
|
||||
>
|
||||
Create Post
|
||||
</A>
|
||||
@@ -168,7 +179,7 @@ export default function BlogIndex() {
|
||||
</Show>
|
||||
</div>
|
||||
</Suspense>
|
||||
|
||||
|
||||
<Suspense
|
||||
fallback={
|
||||
<div class="mx-auto pt-48">
|
||||
@@ -178,7 +189,7 @@ export default function BlogIndex() {
|
||||
>
|
||||
<Show
|
||||
when={data() && data()!.posts.length > 0}
|
||||
fallback={<div class="text-center pt-12">No posts yet!</div>}
|
||||
fallback={<div class="pt-12 text-center">No posts yet!</div>}
|
||||
>
|
||||
<div class="mx-auto flex w-11/12 flex-col pt-8">
|
||||
<PostSorting
|
||||
|
||||
Reference in New Issue
Block a user