continued nojs improvements
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
# Agent Guidelines for freno-dev
|
# Agent Guidelines for freno-dev
|
||||||
|
|
||||||
## Build/Lint/Test Commands
|
### Tech Stack
|
||||||
- **Dev**: `bun dev` (starts Vinxi dev server)
|
|
||||||
- **Build**: `bun build` (production build)
|
|
||||||
- **Start**: `bun start` (production server)
|
|
||||||
- **No tests configured** - No test runner or test scripts exist yet
|
|
||||||
|
|
||||||
## Tech Stack
|
|
||||||
- **Framework**: SolidJS with SolidStart (Vinxi)
|
- **Framework**: SolidJS with SolidStart (Vinxi)
|
||||||
- **Routing**: @solidjs/router
|
- **Routing**: @solidjs/router
|
||||||
- **API**: tRPC v10 with Zod validation
|
- **API**: tRPC v10 with Zod validation
|
||||||
|
|||||||
27
src/app.css
27
src/app.css
@@ -259,6 +259,33 @@ body {
|
|||||||
|
|
||||||
/* Note: JS will add inline styles and reactive classList that override these defaults */
|
/* Note: JS will add inline styles and reactive classList that override these defaults */
|
||||||
|
|
||||||
|
/* Blog banner fallbacks - similar to main layout */
|
||||||
|
.blog-banner-image {
|
||||||
|
/* Full width by default on mobile */
|
||||||
|
width: 100vw;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-banner-text {
|
||||||
|
/* Full width by default on mobile */
|
||||||
|
width: 100vw;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.blog-banner-image {
|
||||||
|
/* Account for sidebars on desktop */
|
||||||
|
width: calc(100vw - 600px);
|
||||||
|
margin-left: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-banner-text {
|
||||||
|
/* Account for sidebars on desktop */
|
||||||
|
width: calc(100vw - 600px);
|
||||||
|
margin-left: 300px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.cursor-typing {
|
.cursor-typing {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 2px;
|
width: 2px;
|
||||||
|
|||||||
15
src/app.tsx
15
src/app.tsx
@@ -3,9 +3,9 @@ import { FileRoutes } from "@solidjs/start/router";
|
|||||||
import {
|
import {
|
||||||
createEffect,
|
createEffect,
|
||||||
ErrorBoundary,
|
ErrorBoundary,
|
||||||
Suspense,
|
|
||||||
onMount,
|
onMount,
|
||||||
onCleanup
|
onCleanup,
|
||||||
|
Suspense
|
||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import "./app.css";
|
import "./app.css";
|
||||||
import { LeftBar, RightBar } from "./components/Bars";
|
import { LeftBar, RightBar } from "./components/Bars";
|
||||||
@@ -189,7 +189,7 @@ function AppLayout(props: { children: any }) {
|
|||||||
<div class="flex max-w-screen flex-row">
|
<div class="flex max-w-screen flex-row">
|
||||||
<LeftBar />
|
<LeftBar />
|
||||||
<div
|
<div
|
||||||
class="bg-base relative h-screen overflow-x-hidden overflow-y-scroll py-16"
|
class="bg-base relative h-screen overflow-x-hidden overflow-y-scroll"
|
||||||
style={
|
style={
|
||||||
barsInitialized()
|
barsInitialized()
|
||||||
? {
|
? {
|
||||||
@@ -198,11 +198,20 @@ function AppLayout(props: { children: any }) {
|
|||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
>
|
||||||
|
<noscript>
|
||||||
|
<div class="bg-yellow text-crust border-text fixed top-0 z-150 ml-16 border-b-2 p-4 text-center font-semibold md:ml-64">
|
||||||
|
JavaScript is disabled. Features will be limited.
|
||||||
|
</div>
|
||||||
|
</noscript>
|
||||||
|
<div
|
||||||
|
class="py-16"
|
||||||
onMouseUp={handleCenterTapRelease}
|
onMouseUp={handleCenterTapRelease}
|
||||||
onTouchEnd={handleCenterTapRelease}
|
onTouchEnd={handleCenterTapRelease}
|
||||||
>
|
>
|
||||||
<Suspense fallback={<TerminalSplash />}>{props.children}</Suspense>
|
<Suspense fallback={<TerminalSplash />}>{props.children}</Suspense>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<RightBar />
|
<RightBar />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ export default createHandler(() => (
|
|||||||
{assets}
|
{assets}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
|
||||||
<div style="position: fixed; top: 0; left: 0; right: 0; z-index: 9999; background-color: var(--color-yellow); color: var(--color-crust); padding: 1rem; text-align: center; font-weight: 600; border-bottom: 2px solid var(--color-text);">
|
|
||||||
JavaScript is disabled. Features will be limited.
|
|
||||||
</div>
|
|
||||||
</noscript>
|
|
||||||
<div id="app">{children}</div>
|
<div id="app">{children}</div>
|
||||||
{scripts}
|
{scripts}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Show, Suspense, For } from "solid-js";
|
import { Show, For } from "solid-js";
|
||||||
import {
|
import {
|
||||||
useParams,
|
useParams,
|
||||||
A,
|
A,
|
||||||
@@ -222,13 +222,20 @@ const getPostByTitle = query(
|
|||||||
export default function PostPage() {
|
export default function PostPage() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
const { centerWidth, leftBarSize, barsInitialized } = useBars();
|
||||||
|
|
||||||
const data = createAsync(() => {
|
const data = createAsync(
|
||||||
|
() => {
|
||||||
const sortBy =
|
const sortBy =
|
||||||
(searchParams.sortBy as "newest" | "oldest" | "highest_rated" | "hot") ||
|
(searchParams.sortBy as
|
||||||
"newest";
|
| "newest"
|
||||||
|
| "oldest"
|
||||||
|
| "highest_rated"
|
||||||
|
| "hot") || "newest";
|
||||||
return getPostByTitle(params.title, sortBy);
|
return getPostByTitle(params.title, sortBy);
|
||||||
});
|
},
|
||||||
|
{ deferStream: true }
|
||||||
|
);
|
||||||
|
|
||||||
const hasCodeBlock = (str: string): boolean => {
|
const hasCodeBlock = (str: string): boolean => {
|
||||||
return str.includes("<code") && str.includes("</code>");
|
return str.includes("<code") && str.includes("</code>");
|
||||||
@@ -236,8 +243,7 @@ export default function PostPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Suspense fallback={<TerminalSplash />}>
|
<Show when={data()} fallback={<TerminalSplash />}>
|
||||||
<Show when={data()} fallback={null}>
|
|
||||||
{(loadedData) => (
|
{(loadedData) => (
|
||||||
<Show when={loadedData().post} fallback={<Navigate href="/404" />}>
|
<Show when={loadedData().post} fallback={<Navigate href="/404" />}>
|
||||||
{(p) => {
|
{(p) => {
|
||||||
@@ -250,7 +256,6 @@ export default function PostPage() {
|
|||||||
const reactionMap = new Map<number, CommentReaction[]>(
|
const reactionMap = new Map<number, CommentReaction[]>(
|
||||||
postData.reactionArray || []
|
postData.reactionArray || []
|
||||||
);
|
);
|
||||||
const { centerWidth, leftBarSize } = useBars();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -272,20 +277,30 @@ export default function PostPage() {
|
|||||||
<img
|
<img
|
||||||
src={p().banner_photo || "/blueprint.jpg"}
|
src={p().banner_photo || "/blueprint.jpg"}
|
||||||
alt="post-cover"
|
alt="post-cover"
|
||||||
class="h-full object-cover select-none"
|
class="blog-banner-image h-full object-cover select-none"
|
||||||
style={{
|
style={
|
||||||
|
barsInitialized()
|
||||||
|
? {
|
||||||
width: `${centerWidth()}px`,
|
width: `${centerWidth()}px`,
|
||||||
"margin-left": `${leftBarSize()}px`,
|
"margin-left": `${leftBarSize()}px`,
|
||||||
"pointer-events": "none"
|
"pointer-events": "none"
|
||||||
}}
|
}
|
||||||
|
: {
|
||||||
|
"pointer-events": "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="text-shadow text-text absolute top-1/3 z-10 my-auto px-4 text-center tracking-widest brightness-150 select-text"
|
class="text-shadow text-text blog-banner-text absolute top-1/3 z-10 my-auto px-4 text-center tracking-widest brightness-150 select-text"
|
||||||
style={{
|
style={
|
||||||
|
barsInitialized()
|
||||||
|
? {
|
||||||
width: `${centerWidth()}px`,
|
width: `${centerWidth()}px`,
|
||||||
"margin-left": `${leftBarSize()}px`
|
"margin-left": `${leftBarSize()}px`
|
||||||
}}
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<div class="text-3xl font-light tracking-widest">
|
<div class="text-3xl font-light tracking-widest">
|
||||||
{p().title.replaceAll("_", " ")}
|
{p().title.replaceAll("_", " ")}
|
||||||
@@ -393,7 +408,6 @@ export default function PostPage() {
|
|||||||
</Show>
|
</Show>
|
||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
</Suspense>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,101 @@
|
|||||||
import { Show, Suspense } from "solid-js";
|
import { Show } from "solid-js";
|
||||||
import { useSearchParams, A } from "@solidjs/router";
|
import { useSearchParams, A, query } from "@solidjs/router";
|
||||||
import { Title } from "@solidjs/meta";
|
import { Title } from "@solidjs/meta";
|
||||||
import { createAsync } from "@solidjs/router";
|
import { createAsync } from "@solidjs/router";
|
||||||
import { api } from "~/lib/api";
|
import { getRequestEvent } from "solid-js/web";
|
||||||
import PostSortingSelect from "~/components/blog/PostSortingSelect";
|
import PostSortingSelect from "~/components/blog/PostSortingSelect";
|
||||||
import TagSelector from "~/components/blog/TagSelector";
|
import TagSelector from "~/components/blog/TagSelector";
|
||||||
import PostSorting from "~/components/blog/PostSorting";
|
import PostSorting from "~/components/blog/PostSorting";
|
||||||
import { TerminalSplash } from "~/components/TerminalSplash";
|
import { TerminalSplash } from "~/components/TerminalSplash";
|
||||||
|
|
||||||
|
// Server function to fetch all posts
|
||||||
|
const getPosts = query(async () => {
|
||||||
|
"use server";
|
||||||
|
const { ConnectionFactory, getPrivilegeLevel } =
|
||||||
|
await import("~/server/utils");
|
||||||
|
const { withCache } = await import("~/server/cache");
|
||||||
|
const event = getRequestEvent()!;
|
||||||
|
const privilegeLevel = await getPrivilegeLevel(event.nativeEvent);
|
||||||
|
|
||||||
|
return withCache(`posts-${privilegeLevel}`, 5 * 60 * 1000, async () => {
|
||||||
|
const conn = ConnectionFactory();
|
||||||
|
|
||||||
|
// Fetch all posts with aggregated data
|
||||||
|
let postsQuery = `
|
||||||
|
SELECT
|
||||||
|
p.id,
|
||||||
|
p.title,
|
||||||
|
p.subtitle,
|
||||||
|
p.body,
|
||||||
|
p.banner_photo,
|
||||||
|
p.date,
|
||||||
|
p.published,
|
||||||
|
p.category,
|
||||||
|
p.author_id,
|
||||||
|
p.reads,
|
||||||
|
p.attachments,
|
||||||
|
COUNT(DISTINCT pl.user_id) as total_likes,
|
||||||
|
COUNT(DISTINCT c.id) as total_comments
|
||||||
|
FROM Post p
|
||||||
|
LEFT JOIN PostLike pl ON p.id = pl.post_id
|
||||||
|
LEFT JOIN Comment c ON p.id = c.post_id
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (privilegeLevel !== "admin") {
|
||||||
|
postsQuery += ` WHERE p.published = TRUE`;
|
||||||
|
}
|
||||||
|
|
||||||
|
postsQuery += ` GROUP BY p.id, p.title, p.subtitle, p.body, p.banner_photo, p.date, p.published, p.category, p.author_id, p.reads, p.attachments`;
|
||||||
|
postsQuery += ` ORDER BY p.date ASC;`;
|
||||||
|
|
||||||
|
const postsResult = await conn.execute(postsQuery);
|
||||||
|
const posts = postsResult.rows;
|
||||||
|
|
||||||
|
const tagsQuery = `
|
||||||
|
SELECT t.value, t.post_id
|
||||||
|
FROM Tag t
|
||||||
|
JOIN Post p ON t.post_id = p.id
|
||||||
|
${privilegeLevel !== "admin" ? "WHERE p.published = TRUE" : ""}
|
||||||
|
ORDER BY t.value ASC
|
||||||
|
`;
|
||||||
|
|
||||||
|
const tagsResult = await conn.execute(tagsQuery);
|
||||||
|
const tags = tagsResult.rows;
|
||||||
|
|
||||||
|
const tagMap: Record<string, number> = {};
|
||||||
|
tags.forEach((tag: any) => {
|
||||||
|
const key = `${tag.value}`;
|
||||||
|
tagMap[key] = (tagMap[key] || 0) + 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return { posts, tags, tagMap, privilegeLevel };
|
||||||
|
});
|
||||||
|
}, "posts");
|
||||||
|
|
||||||
export default function BlogIndex() {
|
export default function BlogIndex() {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
|
||||||
const sort = () => searchParams.sort || "newest";
|
const sort = () => searchParams.sort || "newest";
|
||||||
const filters = () => searchParams.filter || "";
|
const filters = () => searchParams.filter || "";
|
||||||
|
|
||||||
const data = createAsync(() => api.blog.getPosts.query());
|
const data = createAsync(() => getPosts(), { deferStream: true });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Title>Blog | Michael Freno</Title>
|
<Title>Blog | Michael Freno</Title>
|
||||||
|
|
||||||
<div class="mx-auto pt-8 pb-24">
|
<div class="mx-auto pt-8 pb-24">
|
||||||
<Suspense fallback={<TerminalSplash />}>
|
<Show when={data()} fallback={<TerminalSplash />}>
|
||||||
|
{(loadedData) => (
|
||||||
|
<>
|
||||||
<div class="flex flex-row justify-around gap-4 px-4">
|
<div class="flex flex-row justify-around gap-4 px-4">
|
||||||
<PostSortingSelect />
|
<PostSortingSelect />
|
||||||
|
|
||||||
<Show when={data() && Object.keys(data()!.tagMap).length > 0}>
|
<Show when={Object.keys(loadedData().tagMap).length > 0}>
|
||||||
<TagSelector tagMap={data()!.tagMap} />
|
<TagSelector tagMap={loadedData().tagMap} />
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<Show when={data()?.privilegeLevel === "admin"}>
|
<Show when={loadedData().privilegeLevel === "admin"}>
|
||||||
<div class="mt-2 flex justify-center md:mt-0 md:justify-end">
|
<div class="mt-2 flex justify-center md:mt-0 md:justify-end">
|
||||||
<A
|
<A
|
||||||
href="/blog/create"
|
href="/blog/create"
|
||||||
@@ -40,24 +106,24 @@ export default function BlogIndex() {
|
|||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
</Suspense>
|
|
||||||
|
|
||||||
<Suspense fallback={<TerminalSplash />}>
|
|
||||||
<Show
|
<Show
|
||||||
when={data() && data()!.posts.length > 0}
|
when={loadedData().posts.length > 0}
|
||||||
fallback={<div class="pt-12 text-center">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">
|
<div class="mx-auto flex w-11/12 flex-col pt-8">
|
||||||
<PostSorting
|
<PostSorting
|
||||||
posts={data()!.posts}
|
posts={loadedData().posts}
|
||||||
tags={data()!.tags}
|
tags={loadedData().tags}
|
||||||
privilegeLevel={data()!.privilegeLevel}
|
privilegeLevel={loadedData().privilegeLevel}
|
||||||
filters={filters()}
|
filters={filters()}
|
||||||
sort={sort()}
|
sort={sort()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</Suspense>
|
</>
|
||||||
|
)}
|
||||||
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user