Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated multi-page example #250

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/ten-beans-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"framesjs-starter": patch
---

feat: updated multi-page example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createFrames } from "frames.js/next";

export const frames = createFrames({
basePath: "/examples/new-api-multi-page/frames",
});
Original file line number Diff line number Diff line change
@@ -1,47 +1,25 @@
/* eslint-disable react/jsx-key */
import { createFrames, Button } from "frames.js/next";

const totalPages = 5;

const frames = createFrames({
basePath: "/examples/new-api-multi-page/frames",
});

const handleRequest = frames(async (ctx) => {
const pageIndex = Number(ctx.searchParams.pageIndex || 0);

const imageUrl = `https://picsum.photos/seed/frames.js-${pageIndex}/300/200`;
import { frames } from "./frames";
import { Button } from "frames.js/next";

const handler = frames(async () => {
return {
image: (
<div tw="flex flex-col">
<img width={300} height={200} src={imageUrl} alt="Image" />
<div tw="flex">
This is slide {pageIndex + 1} / {totalPages}
</div>
</div>
),
image: <div tw="flex">Welcome</div>,
buttons: [
// With query params
<Button
action="post"
target={{
query: { pageIndex: (pageIndex - 1) % totalPages },
}}
target={{ pathname: "/route1", query: { foo: "bar" } }}
>
Go to route 1
</Button>,
<Button
action="post"
target={{
query: { pageIndex: (pageIndex + 1) % totalPages },
}}
>
// Without query params
<Button action="post" target="/route2">
Go to route 2
</Button>,
],
textInput: "Type something!",
};
});

export const GET = handleRequest;
export const POST = handleRequest;
export const GET = handler;
export const POST = handler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable react/jsx-key */
import { frames } from "../frames";
import { Button } from "frames.js/next";

export const POST = frames(async (ctx) => {
const foo = ctx.searchParams.foo;

return {
image: <div tw="flex">Route 1 foo: {foo}</div>, // foo: bar
buttons: [
<Button action="post" target="/">
Go back
</Button>,
<Button action="post" target="/route2">
Go to route 2
</Button>,
],
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable react/jsx-key */
import { frames } from "../frames";
import { Button } from "frames.js/next";

export const POST = frames(async () => {
return {
image: <div tw="flex">Route 2</div>,
buttons: [
<Button action="post" target="/">
Go to initial route
</Button>,
<Button
action="post"
target={{ pathname: "/route1", query: { foo: "baz" } }}
>
Go to route 1
</Button>,
],
};
});
Loading