Skip to content

Commit

Permalink
feat: Next.js + Lens Client integration example
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Dec 27, 2024
1 parent 50d1b27 commit 848cbf9
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/nextjs-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
4 changes: 4 additions & 0 deletions examples/nextjs-client/.stackblitzrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"startCommand": "npm run dev",
"env": {}
}
5 changes: 5 additions & 0 deletions examples/nextjs-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Next.js - Lens Client Integration Example

This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/lens-protocol/lens-sdk/tree/next/examples/nextjs-client)
7 changes: 7 additions & 0 deletions examples/nextjs-client/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
24 changes: 24 additions & 0 deletions examples/nextjs-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nextjs-client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@lens-protocol/client": "canary",
"next": "15.1.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"simpledotcss": "^2.3.3"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5"
}
}
5 changes: 5 additions & 0 deletions examples/nextjs-client/src/app/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PublicClient, testnet } from '@lens-protocol/client';

export const client = PublicClient.create({
environment: testnet,
});
Binary file added examples/nextjs-client/src/app/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions examples/nextjs-client/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
30 changes: 30 additions & 0 deletions examples/nextjs-client/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import './globals.css';

const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
});

const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
});

export const metadata: Metadata = {
title: 'Next.js - Lens Client Integration',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang='en'>
<body className={`${geistSans.variable} ${geistMono.variable}`}>{children}</body>
</html>
);
}
168 changes: 168 additions & 0 deletions examples/nextjs-client/src/app/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
.page {
--gray-rgb: 0, 0, 0;
--gray-alpha-200: rgba(var(--gray-rgb), 0.08);
--gray-alpha-100: rgba(var(--gray-rgb), 0.05);

--button-primary-hover: #383838;
--button-secondary-hover: #f2f2f2;

display: grid;
grid-template-rows: 20px 1fr 20px;
align-items: center;
justify-items: center;
min-height: 100svh;
padding: 80px;
gap: 64px;
font-family: var(--font-geist-sans);
}

@media (prefers-color-scheme: dark) {
.page {
--gray-rgb: 255, 255, 255;
--gray-alpha-200: rgba(var(--gray-rgb), 0.145);
--gray-alpha-100: rgba(var(--gray-rgb), 0.06);

--button-primary-hover: #ccc;
--button-secondary-hover: #1a1a1a;
}
}

.main {
display: flex;
flex-direction: column;
gap: 32px;
grid-row-start: 2;
}

.main ol {
font-family: var(--font-geist-mono);
padding-left: 0;
margin: 0;
font-size: 14px;
line-height: 24px;
letter-spacing: -0.01em;
list-style-position: inside;
}

.main li:not(:last-of-type) {
margin-bottom: 8px;
}

.main code {
font-family: inherit;
background: var(--gray-alpha-100);
padding: 2px 4px;
border-radius: 4px;
font-weight: 600;
}

.ctas {
display: flex;
gap: 16px;
}

.ctas a {
appearance: none;
border-radius: 128px;
height: 48px;
padding: 0 20px;
border: none;
border: 1px solid transparent;
transition:
background 0.2s,
color 0.2s,
border-color 0.2s;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
line-height: 20px;
font-weight: 500;
}

a.primary {
background: var(--foreground);
color: var(--background);
gap: 8px;
}

a.secondary {
border-color: var(--gray-alpha-200);
min-width: 180px;
}

.footer {
grid-row-start: 3;
display: flex;
gap: 24px;
}

.footer a {
display: flex;
align-items: center;
gap: 8px;
}

.footer img {
flex-shrink: 0;
}

/* Enable hover only on non-touch devices */
@media (hover: hover) and (pointer: fine) {
a.primary:hover {
background: var(--button-primary-hover);
border-color: transparent;
}

a.secondary:hover {
background: var(--button-secondary-hover);
border-color: transparent;
}

.footer a:hover {
text-decoration: underline;
text-underline-offset: 4px;
}
}

@media (max-width: 600px) {
.page {
padding: 32px;
padding-bottom: 80px;
}

.main {
align-items: center;
}

.main ol {
text-align: center;
}

.ctas {
flex-direction: column;
}

.ctas a {
font-size: 14px;
height: 40px;
padding: 0 16px;
}

a.secondary {
min-width: auto;
}

.footer {
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
}

@media (prefers-color-scheme: dark) {
.logo {
filter: invert();
}
}
27 changes: 27 additions & 0 deletions examples/nextjs-client/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'simpledotcss/simple.min.css';
import { AccountsOrderBy, PageSize } from '@lens-protocol/client';
import { fetchAccounts } from '@lens-protocol/client/actions';
import { client } from './client';

export default async function Home() {
const result = await fetchAccounts(client, {
orderBy: AccountsOrderBy.AccountScore,
pageSize: PageSize.Ten,
});

if (result.isErr()) {
return <div>{result.error.message}</div>;
}

return (
<div>
<p>Top 10 Accounts by Account Score:</p>

<ul>
{result.value?.items.map((account) => (
<li key={account.address}>{account.username?.value}</li>
))}
</ul>
</div>
);
}
27 changes: 27 additions & 0 deletions examples/nextjs-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 848cbf9

Please sign in to comment.