|
|
@ -1,24 +1,44 @@
|
|
|
|
import { db } from "../db";
|
|
|
|
import { db } from "../db";
|
|
|
|
import { tweets, type Tweet } from "../db/schema/tweets";
|
|
|
|
import { tweets } from "../db/schema/tweets";
|
|
|
|
|
|
|
|
|
|
|
|
export function TweetCard({ authorId, createdAt, content }: Tweet) {
|
|
|
|
export function TweetCard({
|
|
|
|
|
|
|
|
author: { handle },
|
|
|
|
|
|
|
|
createdAt,
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
}: {
|
|
|
|
|
|
|
|
createdAt: Date;
|
|
|
|
|
|
|
|
content: string;
|
|
|
|
|
|
|
|
author: {
|
|
|
|
|
|
|
|
handle: string;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div class="rounded-lg border p-4 shadow-md">
|
|
|
|
<div class="rounded-lg border p-4 shadow-md">
|
|
|
|
<h2 class="text-xl font-bold" safe>
|
|
|
|
<h2 class="text-xl font-bold" safe>
|
|
|
|
{authorId}
|
|
|
|
@{handle}
|
|
|
|
</h2>
|
|
|
|
</h2>
|
|
|
|
<p class="text-gray-700" safe>
|
|
|
|
<p class="text-gray-700" safe>
|
|
|
|
{content}
|
|
|
|
{content}
|
|
|
|
</p>
|
|
|
|
</p>
|
|
|
|
<span class="text-sm text-gray-500">
|
|
|
|
<span class="text-sm text-gray-500">
|
|
|
|
{new Date(createdAt).toLocaleString()}
|
|
|
|
{createdAt.toLocaleString()}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function TweetList() {
|
|
|
|
export async function TweetList() {
|
|
|
|
const tweetData = await db.select().from(tweets).limit(10);
|
|
|
|
const tweetData = await db.query.tweets.findMany({
|
|
|
|
|
|
|
|
limit: 10,
|
|
|
|
|
|
|
|
orderBy: (tweets, { desc }) => [desc(tweets.createdAt)],
|
|
|
|
|
|
|
|
with: {
|
|
|
|
|
|
|
|
author: {
|
|
|
|
|
|
|
|
columns: {
|
|
|
|
|
|
|
|
handle: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div class="space-y-4" id="tweetList">
|
|
|
|
<div class="space-y-4" id="tweetList">
|
|
|
@ -33,17 +53,15 @@ export function TweetCreationForm() {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div class="rounded-lg border p-4 shadow-md">
|
|
|
|
<div class="rounded-lg border p-4 shadow-md">
|
|
|
|
<h2 class="mb-4 text-xl font-bold">Create a new Tweet</h2>
|
|
|
|
<h2 class="mb-4 text-xl font-bold">Create a new Tweet</h2>
|
|
|
|
<form hx-post="/api/tweets" hx-swap="afterend" hx-target="#tweetList">
|
|
|
|
<form hx-post="/api/tweets" hx-swap="afterbegin" hx-target="#tweetList" _="on submit target.reset()">
|
|
|
|
<label class="mb-2 block text-sm font-bold" for="content">
|
|
|
|
<label class="mb-2 block text-sm font-bold" for="content">
|
|
|
|
Tweet:
|
|
|
|
Tweet:
|
|
|
|
</label>
|
|
|
|
</label>
|
|
|
|
<textarea
|
|
|
|
<input
|
|
|
|
class="w-full appearance-none rounded border px-3 py-2 leading-tight text-gray-700 shadow"
|
|
|
|
class="w-full appearance-none rounded border px-3 py-2 leading-tight text-gray-700 shadow"
|
|
|
|
name="content"
|
|
|
|
name="content"
|
|
|
|
rows="3"
|
|
|
|
|
|
|
|
required="true"
|
|
|
|
required="true"
|
|
|
|
_="on submit reset me"
|
|
|
|
/>
|
|
|
|
></textarea>
|
|
|
|
|
|
|
|
<button
|
|
|
|
<button
|
|
|
|
class="rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
|
|
|
class="rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
|
|
|
type="submit"
|
|
|
|
type="submit"
|
|
|
|