Skip to content

Commit

Permalink
Merge pull request #250 from framesjs/feat/updated-multi-page-example
Browse files Browse the repository at this point in the history
feat: updated multi-page example
  • Loading branch information
stephancill authored Mar 27, 2024
2 parents d594ec5 + 8800afa commit d860bc2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 34 deletions.
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>,
],
};
});

0 comments on commit d860bc2

Please sign in to comment.