Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: use LinkForm and ActionContext.revalidate
  • Loading branch information
hi-ogawa committed Apr 7, 2024
commit 2ecc35c173235263db2a96a336ba2428c6c4d10b
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"cf-release": "cd misc/cloudflare-workers && wrangler deploy"
},
"dependencies": {
"@hiogawa/react-server": "latest",
"@hiogawa/react-server": "0.1.15",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"react-server-dom-webpack": "18.3.0-canary-14898b6a9-20240318"
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/routes/_action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use server";

import { redirect } from "@hiogawa/react-server/server";
import { ActionContext, redirect } from "@hiogawa/react-server/server";
import { createEmptyContact } from "./_data";

export async function actionNewContact() {
export async function actionNewContact(this: ActionContext) {
this.revalidate = true;
const contact = await createEmptyContact();
throw redirect(`/contacts/${contact.id}/edit`);
}
10 changes: 4 additions & 6 deletions src/routes/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Link } from "@hiogawa/react-server/client";
import { Link, LinkForm } from "@hiogawa/react-server/client";
import { getContacts } from "./_data";
import { actionNewContact } from "./_action";
import type { LayoutProps } from "@hiogawa/react-server/server";

export default async function Layout(props: LayoutProps) {
const contacts = await getContacts();
// TODO: search
props.url.search;

return (
Expand All @@ -20,8 +21,7 @@ export default async function Layout(props: LayoutProps) {
<Link href="/">Remix Contacts</Link>
</h1>
<div>
{/* TODO: GET form navigation */}
<form action="" id="search-form" role="search">
<LinkForm action="/" id="search-form" role="search" revalidate>
<input
aria-label="Search contacts"
id="q"
Expand All @@ -30,9 +30,7 @@ export default async function Layout(props: LayoutProps) {
type="search"
/>
<div aria-hidden hidden={true} id="search-spinner" />
</form>
{/* TODO: better error message when forgot to add `action`? */}
{/* TODO: layout doesn't invalidate when adding a new contact */}
</LinkForm>
<form action={actionNewContact}>
<button type="submit">New</button>
</form>
Expand Down