continued nojs improvements
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
# Agent Guidelines for freno-dev
|
||||
|
||||
## Build/Lint/Test Commands
|
||||
- **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
|
||||
### Tech Stack
|
||||
- **Framework**: SolidJS with SolidStart (Vinxi)
|
||||
- **Routing**: @solidjs/router
|
||||
- **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 */
|
||||
|
||||
/* 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 {
|
||||
display: inline-block;
|
||||
width: 2px;
|
||||
|
||||
15
src/app.tsx
15
src/app.tsx
@@ -3,9 +3,9 @@ import { FileRoutes } from "@solidjs/start/router";
|
||||
import {
|
||||
createEffect,
|
||||
ErrorBoundary,
|
||||
Suspense,
|
||||
onMount,
|
||||
onCleanup
|
||||
onCleanup,
|
||||
Suspense
|
||||
} from "solid-js";
|
||||
import "./app.css";
|
||||
import { LeftBar, RightBar } from "./components/Bars";
|
||||
@@ -189,7 +189,7 @@ function AppLayout(props: { children: any }) {
|
||||
<div class="flex max-w-screen flex-row">
|
||||
<LeftBar />
|
||||
<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={
|
||||
barsInitialized()
|
||||
? {
|
||||
@@ -198,11 +198,20 @@ function AppLayout(props: { children: any }) {
|
||||
}
|
||||
: 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}
|
||||
onTouchEnd={handleCenterTapRelease}
|
||||
>
|
||||
<Suspense fallback={<TerminalSplash />}>{props.children}</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
<RightBar />
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -12,11 +12,6 @@ export default createHandler(() => (
|
||||
{assets}
|
||||
</head>
|
||||
<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>
|
||||
{scripts}
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Show, Suspense, For } from "solid-js";
|
||||
import { Show, For } from "solid-js";
|
||||
import {
|
||||
useParams,
|
||||
A,
|
||||
@@ -222,13 +222,20 @@ const getPostByTitle = query(
|
||||
export default function PostPage() {
|
||||
const params = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { centerWidth, leftBarSize, barsInitialized } = useBars();
|
||||
|
||||
const data = createAsync(() => {
|
||||
const data = createAsync(
|
||||
() => {
|
||||
const sortBy =
|
||||
(searchParams.sortBy as "newest" | "oldest" | "highest_rated" | "hot") ||
|
||||
"newest";
|
||||
(searchParams.sortBy as
|
||||
| "newest"
|
||||
| "oldest"
|
||||
| "highest_rated"
|
||||
| "hot") || "newest";
|
||||
return getPostByTitle(params.title, sortBy);
|
||||
});
|
||||
},
|
||||
{ deferStream: true }
|
||||
);
|
||||
|
||||
const hasCodeBlock = (str: string): boolean => {
|
||||
return str.includes("<code") && str.includes("</code>");
|
||||
@@ -236,8 +243,7 @@ export default function PostPage() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Suspense fallback={<TerminalSplash />}>
|
||||
<Show when={data()} fallback={null}>
|
||||
<Show when={data()} fallback={<TerminalSplash />}>
|
||||
{(loadedData) => (
|
||||
<Show when={loadedData().post} fallback={<Navigate href="/404" />}>
|
||||
{(p) => {
|
||||
@@ -250,7 +256,6 @@ export default function PostPage() {
|
||||
const reactionMap = new Map<number, CommentReaction[]>(
|
||||
postData.reactionArray || []
|
||||
);
|
||||
const { centerWidth, leftBarSize } = useBars();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -272,20 +277,30 @@ export default function PostPage() {
|
||||
<img
|
||||
src={p().banner_photo || "/blueprint.jpg"}
|
||||
alt="post-cover"
|
||||
class="h-full object-cover select-none"
|
||||
style={{
|
||||
class="blog-banner-image h-full object-cover select-none"
|
||||
style={
|
||||
barsInitialized()
|
||||
? {
|
||||
width: `${centerWidth()}px`,
|
||||
"margin-left": `${leftBarSize()}px`,
|
||||
"pointer-events": "none"
|
||||
}}
|
||||
}
|
||||
: {
|
||||
"pointer-events": "none"
|
||||
}
|
||||
}
|
||||
/>
|
||||
</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"
|
||||
style={{
|
||||
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={
|
||||
barsInitialized()
|
||||
? {
|
||||
width: `${centerWidth()}px`,
|
||||
"margin-left": `${leftBarSize()}px`
|
||||
}}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<div class="text-3xl font-light tracking-widest">
|
||||
{p().title.replaceAll("_", " ")}
|
||||
@@ -393,7 +408,6 @@ export default function PostPage() {
|
||||
</Show>
|
||||
)}
|
||||
</Show>
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,35 +1,101 @@
|
||||
import { Show, Suspense } from "solid-js";
|
||||
import { useSearchParams, A } from "@solidjs/router";
|
||||
import { Show } from "solid-js";
|
||||
import { useSearchParams, A, query } from "@solidjs/router";
|
||||
import { Title } from "@solidjs/meta";
|
||||
import { createAsync } from "@solidjs/router";
|
||||
import { api } from "~/lib/api";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import PostSortingSelect from "~/components/blog/PostSortingSelect";
|
||||
import TagSelector from "~/components/blog/TagSelector";
|
||||
import PostSorting from "~/components/blog/PostSorting";
|
||||
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() {
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const sort = () => searchParams.sort || "newest";
|
||||
const filters = () => searchParams.filter || "";
|
||||
|
||||
const data = createAsync(() => api.blog.getPosts.query());
|
||||
const data = createAsync(() => getPosts(), { deferStream: true });
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title>Blog | Michael Freno</Title>
|
||||
|
||||
<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">
|
||||
<PostSortingSelect />
|
||||
|
||||
<Show when={data() && Object.keys(data()!.tagMap).length > 0}>
|
||||
<TagSelector tagMap={data()!.tagMap} />
|
||||
<Show when={Object.keys(loadedData().tagMap).length > 0}>
|
||||
<TagSelector tagMap={loadedData().tagMap} />
|
||||
</Show>
|
||||
|
||||
<Show when={data()?.privilegeLevel === "admin"}>
|
||||
<Show when={loadedData().privilegeLevel === "admin"}>
|
||||
<div class="mt-2 flex justify-center md:mt-0 md:justify-end">
|
||||
<A
|
||||
href="/blog/create"
|
||||
@@ -40,24 +106,24 @@ export default function BlogIndex() {
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
</Suspense>
|
||||
|
||||
<Suspense fallback={<TerminalSplash />}>
|
||||
<Show
|
||||
when={data() && data()!.posts.length > 0}
|
||||
when={loadedData().posts.length > 0}
|
||||
fallback={<div class="pt-12 text-center">No posts yet!</div>}
|
||||
>
|
||||
<div class="mx-auto flex w-11/12 flex-col pt-8">
|
||||
<PostSorting
|
||||
posts={data()!.posts}
|
||||
tags={data()!.tags}
|
||||
privilegeLevel={data()!.privilegeLevel}
|
||||
posts={loadedData().posts}
|
||||
tags={loadedData().tags}
|
||||
privilegeLevel={loadedData().privilegeLevel}
|
||||
filters={filters()}
|
||||
sort={sort()}
|
||||
/>
|
||||
</div>
|
||||
</Show>
|
||||
</Suspense>
|
||||
</>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user