Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/RefreshButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client'

import { useTransition } from 'react'
import { refreshFeed } from './actions'

export default function RefreshButton() {
const [pending, startTransition] = useTransition()

return (
<div className="flex justify-center border-b border-neutral-800 py-2">
<button
type="button"
disabled={pending}
onClick={() => startTransition(() => refreshFeed())}
className="rounded-full border border-neutral-700 px-5 py-1.5 text-sm font-semibold transition hover:bg-neutral-900 disabled:opacity-50"
>
{pending ? 'Refreshing…' : 'Refresh'}
</button>
</div>
)
}
6 changes: 5 additions & 1 deletion app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use server";

import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
import { revalidatePath, refresh } from "next/cache";
import { query } from "@/lib/db";
import {
createSession,
Expand Down Expand Up @@ -70,6 +70,10 @@ export async function logout() {
redirect("/login");
}

export async function refreshFeed(): Promise<void> {
refresh();
}

export async function createPost(formData: FormData): Promise<void> {
const user = await getCurrentUser();
if (!user) redirect("/login");
Expand Down
3 changes: 3 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getCurrentUser } from "@/lib/auth";
import { query } from "@/lib/db";
import Composer from "./Composer";
import LogoutButton from "./LogoutButton";
import RefreshButton from "./RefreshButton";

type FeedPost = {
id: number;
Expand Down Expand Up @@ -80,6 +81,8 @@ export default async function Home() {
</div>
)}

<RefreshButton />

<section>
{posts.length === 0 ? (
<p className="p-8 text-center text-neutral-500">
Expand Down
1 change: 1 addition & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
allowedDevOrigins: ["*.trycloudflare.com"],
experimental: {
serverActions: {
// Allow image uploads up to ~5MB through Server Actions.
Expand Down