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

fix: update quickstart code and fix baseUrl #268

Merged
merged 1 commit into from
Apr 2, 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/small-clouds-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"docs": patch
---

fix: quickstart example and baseUrl
6 changes: 5 additions & 1 deletion docs/pages/guides/create-frame.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ yarn add frames.js

### Create your Frames app

Create a `frames` directory in your Next.js app and add the following files:

```tsx [./app/frames/frames.ts]
import { createFrames } from "frames.js/next";

export const frames = createFrames();
export const frames = createFrames({
basePath: "/frames",
});
```

### Create a route
Expand Down
95 changes: 67 additions & 28 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,53 +55,92 @@ pnpm create frames

### Start with frames.js in Next.js in three steps

```bash
::::steps

### Add `frames.js` to your project

```sh
yarn add frames.js
```

```tsx [./app/page.tsx]
import { fetchMetadata } from "frames.js/next";
### Create your Frames app

export async function generateMetadata() {
return {
title: "My page",
other: await fetchMetadata(
new URL(
"/frames",
process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000"
)
),
};
}
Create a `frames` directory in your Next.js app and add the following files:

export default function Home(props) {
return <div>My Page</div>;
}
```tsx [./app/frames/frames.ts]
import { createFrames } from "frames.js/next";

export const frames = createFrames({
basePath: "/frames",
});
```

```ts [./app/frames/route.tsx]
### Create a Frames route

```tsx [./app/frames/route.tsx]
/* eslint-disable react/jsx-key */
import { createFrames, Button } from 'frames.js/next';
import { Button } from "frames.js/next";
import { frames } from "./frames";

const frames = createFrames();
const handleRequest = frames(async (ctx) => {
return {
image: <div tw="w-full h-full bg-slate-700 text-white justify-center items-center">
{ctx.message?.state?.count ?? 0}
</div>,
image: (
<span>
{ctx.pressedButton
? `I clicked ${ctx.searchParams.value}`
: `Click some button`}
</span>
),
buttons: [
<Button action="post">Increment counter</Button>
<Button action="post" target={{ query: { value: "Yes" } }}>
Say Yes
</Button>,
<Button action="post" target={{ query: { value: "No" } }}>
Say No
</Button>,
],
state: { count: (ctx.message?.state?.count ?? 0) + 1 }
};
});

export const GET = handleRequest;
export const POST = handleRequest;
```

### Include Frames alongside your existing page's metadata

```tsx [./app/page.tsx]
import { fetchMetadata } from "frames.js/next";

export async function generateMetadata() {
return {
title: "My Page",
// ...
other: {
// ...
...(await fetchMetadata(
// provide a full URL to your /frames endpoint
new URL(
"/frames",
process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000"
)
)),
},
};
}

export default function Page() {
return <span>My existing page</span>;
}
```

### Run `yarn run dev`

### Done! 🎉

::::

## Community

Check out the following places for more Frames-related content:
Expand All @@ -117,7 +156,7 @@ Check out the following places for more Frames-related content:

Or use the [hosted Frames debugger](https://debugger.framesjs.org/?url=https%3A%2F%2Fframesjs.org). Running locally has the benefits of it working with natively with localhost.

## Prefer to not use JSX?
## Prefer to not use JSX?

### frames.js in Next.js using helper functions

Expand Down
86 changes: 61 additions & 25 deletions packages/frames.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,89 @@ or [clone from github](https://github.com/framesjs/frames.js/tree/main/examples/

## Alternatively, add frames.js to your existing project manually

### Start with frames.js in Next.js in three steps

```bash
### 1. Add `frames.js` to your project

```sh
yarn add frames.js
```

```tsx filename="// ./app/page.tsx"
// ./app/page.tsx
### 2. Create your Frames app

import { fetchMetadata } from "frames.js/next";
Create a `frames` directory in your Next.js app and add the following files:

export async function generateMetadata() {
return {
title: "My page",
other: await fetchMetadata(
new URL("/frames", process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : "http://localhost:3000")
),
};
}
#### `./app/frames/frames.ts`
```tsx [./app/frames/frames.ts]
import { createFrames } from "frames.js/next";

export default function Home(props) {
return <div>My Page</div>;
}
export const frames = createFrames({
basePath: "/frames",
});
```

```ts filename="./app/frames/route.tsx"
// ./app/frames/route.tsx
### 3. Create a Frames route

#### `./app/frames/route.tsx`
```tsx [./app/frames/route.tsx]
/* eslint-disable react/jsx-key */
import { createFrames, Button } from 'frames.js/next';
import { Button } from "frames.js/next";
import { frames } from "./frames";

const frames = createFrames();
const handleRequest = frames(async (ctx) => {
return {
image: <div tw="w-full h-full bg-slate-700 text-white justify-center items-center">
{ctx.message?.state?.count ?? 0}
</div>,
image: (
<span>
{ctx.pressedButton
? `I clicked ${ctx.searchParams.value}`
: `Click some button`}
</span>
),
buttons: [
<Button action="post">Increment counter</Button>
<Button action="post" target={{ query: { value: "Yes" } }}>
Say Yes
</Button>,
<Button action="post" target={{ query: { value: "No" } }}>
Say No
</Button>,
],
state: { count: (ctx.message?.state?.count ?? 0) + 1 }
};
});

export const GET = handleRequest;
export const POST = handleRequest;
```

### 4. Include Frames alongside your existing page's metadata

```tsx [./app/page.tsx]
import { fetchMetadata } from "frames.js/next";

export async function generateMetadata() {
return {
title: "My Page",
// ...
other: {
// ...
...(await fetchMetadata(
// provide a full URL to your /frames endpoint
new URL(
"/frames",
process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000"
)
)),
},
};
}

export default function Page() {
return <span>My existing page</span>;
}
```

### 5. Done! 🎉

![](/frames/frame2.png)

[Debugging your Frames locally](/guides/debugger)
Expand Down
Loading