|
1 |
| -import { |
2 |
| - FrameButton, |
3 |
| - FrameContainer, |
4 |
| - FrameImage, |
5 |
| - FrameReducer, |
6 |
| - NextServerPageProps, |
7 |
| - getFrameMessage, |
8 |
| - getPreviousFrame, |
9 |
| - useFramesReducer, |
10 |
| -} from "frames.js/next/server"; |
| 1 | +import { fetchMetadata } from "frames.js/next"; |
| 2 | +import { Metadata } from "next"; |
11 | 3 |
|
12 |
| -type State = { |
13 |
| - saidGm: boolean; |
14 |
| -}; |
15 |
| - |
16 |
| -const initialState: State = { saidGm: false }; |
17 |
| - |
18 |
| -const reducer: FrameReducer<State> = (state, action) => { |
| 4 | +export async function generateMetadata(): Promise<Metadata> { |
19 | 5 | return {
|
20 |
| - saidGm: true, |
| 6 | + title: "Frames Next.js Example", |
| 7 | + other: { |
| 8 | + ...(await fetchMetadata( |
| 9 | + new URL("/frames", process.env.VERCEL_URL || "http://localhost:3000") |
| 10 | + )), |
| 11 | + }, |
21 | 12 | };
|
22 |
| -}; |
23 |
| - |
24 |
| -// This is a react server component only |
25 |
| -export default async function Home({ |
26 |
| - params, |
27 |
| - searchParams, |
28 |
| -}: NextServerPageProps) { |
29 |
| - const previousFrame = getPreviousFrame<State>(searchParams); |
30 |
| - |
31 |
| - const frameMessage = await getFrameMessage(previousFrame.postBody, { |
32 |
| - // remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub |
33 |
| - ...(process.env.NODE_ENV === "production" |
34 |
| - ? {} |
35 |
| - : { |
36 |
| - hubHttpUrl: "http://localhost:3010/hub", |
37 |
| - }), |
38 |
| - }); |
39 |
| - |
40 |
| - if (frameMessage && !frameMessage?.isValid) { |
41 |
| - throw new Error("Invalid frame payload"); |
42 |
| - } |
43 |
| - |
44 |
| - const [state, dispatch] = useFramesReducer<State>( |
45 |
| - reducer, |
46 |
| - initialState, |
47 |
| - previousFrame |
48 |
| - ); |
49 |
| - |
50 |
| - // Here: do a server side side effect either sync or async (using await), such as minting an NFT if you want. |
51 |
| - // example: load the users credentials & check they have an NFT |
52 |
| - console.log("info: state is:", state); |
| 13 | +} |
53 | 14 |
|
54 |
| - // then, when done, return next frame |
55 |
| - return ( |
56 |
| - <div> |
57 |
| - GM user data example. |
58 |
| - <FrameContainer |
59 |
| - pathname="/" |
60 |
| - postUrl="/frames" |
61 |
| - state={state} |
62 |
| - previousFrame={previousFrame} |
63 |
| - > |
64 |
| - <FrameImage> |
65 |
| - {frameMessage ? ( |
66 |
| - <div |
67 |
| - style={{ |
68 |
| - display: "flex", |
69 |
| - flexDirection: "column", |
70 |
| - }} |
71 |
| - > |
72 |
| - GM, {frameMessage.requesterUserData?.displayName}! Your FID is{" "} |
73 |
| - {frameMessage.requesterFid} |
74 |
| - {", "} |
75 |
| - {frameMessage.requesterFid < 20_000 |
76 |
| - ? "you're OG!" |
77 |
| - : "welcome to the Farcaster!"} |
78 |
| - </div> |
79 |
| - ) : ( |
80 |
| - <div |
81 |
| - style={{ |
82 |
| - display: "flex", |
83 |
| - flexDirection: "column", |
84 |
| - }} |
85 |
| - > |
86 |
| - Say GM |
87 |
| - </div> |
88 |
| - )} |
89 |
| - </FrameImage> |
90 |
| - {!state.saidGm ? <FrameButton>Say GM</FrameButton> : null} |
91 |
| - </FrameContainer> |
92 |
| - </div> |
93 |
| - ); |
| 15 | +export default async function Home() { |
| 16 | + return <div>GM user data example.</div>; |
94 | 17 | }
|
0 commit comments