refactor: code refactor

This commit is contained in:
Andrea
2023-03-14 13:54:52 +01:00
parent 6d3a6c2155
commit 84ed5530ca
19 changed files with 1666 additions and 1023 deletions

View File

@@ -0,0 +1,10 @@
export function EmptyState() {
return (
<div className="mt-5 flex flex-col items-center">
<div className="mb-5 font-bold">
I haven't post anything yet! So here's a pic of my cat
</div>
<img src="/cat.jpg" className="rounded-md" />
</div>
);
}

View File

@@ -0,0 +1,32 @@
import { Link } from "@remix-run/react";
type PostProps = {
filename: string;
title: string;
publishedAt: string;
description: string | null;
};
export function Post({ title, description, filename, publishedAt }: PostProps) {
return (
<div className="mx-5 md:mx-0 md:w-1/2 lg:w-1/3">
<div className="p-5 border-gray-600 border-2 rounded-lg">
<Link to={filename}>
<div className="text-center font-bold">
<span className="text-[#ffff00] hover:text-[#e6c2bf] md:text-2xl">
{title}
</span>
<span className="ml-2">{`(${new Date(
publishedAt
).toLocaleDateString()})`}</span>
</div>
{description && (
<div className="mt-5 italic md:text-xl max-w-3xl text-center">
{description}
</div>
)}
</Link>
</div>
</div>
);
}

View File

@@ -0,0 +1,32 @@
import { useLoaderData } from "@remix-run/react";
import { Title } from "~/components/Title";
import { findPosts } from "~/utils/posts.server";
import { EmptyState } from "./EmptyState";
import { Post } from "./Post";
export const handle = {
to: "/",
text: "Home",
};
export const loader = async () => {
return findPosts();
};
export default function () {
const posts = useLoaderData<typeof loader>();
return (
<>
<Title>Here I blog about whatever get my attention</Title>
{posts.length > 0 ? (
<div className="mt-10 w-full flex flex-col items-center space-y-5">
{posts.map((post, i) => (
<Post {...post} key={i} />
))}
</div>
) : (
<EmptyState />
)}
</>
);
}