Cleanup AI slop and simplify db interface
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import React from 'react';
|
||||
import { getRecentPosts, formatDate, calculateReadTime, getNumOfPosts } from '../../db/posts';
|
||||
import { parseTags } from '../../db/tags';
|
||||
import { type BlogPost } from '../../db/queries';
|
||||
|
||||
import { dbConnection } from '../../db';
|
||||
import { formatDate } from '../utils';
|
||||
|
||||
// Extract the post type from the database return type
|
||||
type Post = {
|
||||
id: number;
|
||||
path: string;
|
||||
title: string;
|
||||
date: string;
|
||||
readingTime: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
tags: string[];
|
||||
};
|
||||
|
||||
export function Home({ searchParams }: { searchParams: URLSearchParams }) {
|
||||
const postsPerPage = 10;
|
||||
const tags = searchParams.getAll('tag');
|
||||
|
||||
const currentPage = parseInt(searchParams.get('page') || "1", 10);
|
||||
const totalPages = Math.ceil(getNumOfPosts(tags) / postsPerPage);
|
||||
const totalPages = Math.ceil(dbConnection.getNumOfPosts(tags) / postsPerPage);
|
||||
const offset = (currentPage - 1) * postsPerPage;
|
||||
|
||||
|
||||
const posts = getRecentPosts(postsPerPage, offset, tags); // Get posts for the current page
|
||||
const posts = dbConnection.getPosts(postsPerPage, offset, tags); // Get posts for the current page
|
||||
|
||||
return (
|
||||
<main>
|
||||
@@ -33,12 +44,8 @@ export function Home({ searchParams }: { searchParams: URLSearchParams }) {
|
||||
);
|
||||
}
|
||||
|
||||
interface PostCardProps {
|
||||
post: BlogPost;
|
||||
}
|
||||
|
||||
function PostCard({ post }: PostCardProps) {
|
||||
const tags = parseTags(post.tags);
|
||||
function PostCard({ post }: { post: Post }) {
|
||||
const tags = post.tags;
|
||||
const formattedDate = formatDate(post.date);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user