Skip to content

Commit

Permalink
specify localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
nickcherry committed Jan 26, 2024
1 parent 7b2044b commit 0ea5e35
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 202 deletions.
18 changes: 9 additions & 9 deletions web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
extends: ['next/core-web-vitals', 'plugin:tailwindcss/recommended'],
plugins: ['simple-import-sort', 'unused-imports'],
extends: ["next/core-web-vitals", "plugin:tailwindcss/recommended"],
plugins: ["simple-import-sort", "unused-imports"],
rules: {
'@next/next/no-img-element': 'off',
'jsx-a11y/alt-text': 'off',
'no-duplicate-imports': 'error',
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
'tailwindcss/no-custom-classname': 'error',
'unused-imports/no-unused-imports': 'error',
"@next/next/no-img-element": "off",
"jsx-a11y/alt-text": "off",
"no-duplicate-imports": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"tailwindcss/no-custom-classname": "error",
"unused-imports/no-unused-imports": "error",
},
};
2 changes: 1 addition & 1 deletion web/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */

import { NextConfig } from 'next';
import { NextConfig } from "next";

const nextConfig: NextConfig = {
reactStrictMode: true,
Expand Down
26 changes: 13 additions & 13 deletions web/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { createAppClient, viemConnector } from '@farcaster/auth-client';
import NextAuth from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { createAppClient, viemConnector } from "@farcaster/auth-client";
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

import { getProfile } from '../../../../lib/services/user';
import { getProfile } from "../../../../lib/services/user";

export const authOptions = {
providers: [
CredentialsProvider({
name: 'Sign in with Farcaster',
name: "Sign in with Farcaster",
credentials: {
message: {
label: 'Message',
type: 'text',
placeholder: '0x0',
label: "Message",
type: "text",
placeholder: "0x0",
},
signature: {
label: 'Signature',
type: 'text',
placeholder: '0x0',
label: "Signature",
type: "text",
placeholder: "0x0",
},
csrfToken: {
type: 'text',
type: "text",
},
},
async authorize(credentials) {
Expand All @@ -31,7 +31,7 @@ export const authOptions = {
const verifyResponse = await appClient.verifySignInMessage({
message: credentials!.message as string,
signature: credentials!.signature as `0x${string}`,
domain: 'example.com',
domain: "http://localhost:3000",
nonce: credentials!.csrfToken,
});

Expand Down
10 changes: 5 additions & 5 deletions web/src/app/api/feed/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getFeed } from '@lib/services/feed';
import { FeedApiResponse } from '@shared/types/api';
import { NextResponse } from 'next/server';
import { getFeed } from "@lib/services/feed";
import { FeedApiResponse } from "@shared/types/api";
import { NextResponse } from "next/server";

export async function GET(request: Request) {
const fid = new URL(request.url).searchParams.get('fid');
const fid = new URL(request.url).searchParams.get("fid");
if (!fid) {
return NextResponse.json({ error: 'fid is required' }, { status: 400 });
return NextResponse.json({ error: "fid is required" }, { status: 400 });
}
const payload: FeedApiResponse = { feed: await getFeed({ fid }) };
return NextResponse.json(payload);
Expand Down
8 changes: 4 additions & 4 deletions web/src/app/api/users/[fid]/casts/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getCasts } from '@lib/services/casts';
import { ProfileCastsApiResponse } from '@shared/types/api';
import { NextResponse } from 'next/server';
import { getCasts } from "@lib/services/casts";
import { ProfileCastsApiResponse } from "@shared/types/api";
import { NextResponse } from "next/server";

export async function GET(
_request: Request,
{ params: { fid } }: { params: { fid: string } },
) {
if (!fid) {
return NextResponse.json({ error: 'fid is required' }, { status: 400 });
return NextResponse.json({ error: "fid is required" }, { status: 400 });
}

const payload: ProfileCastsApiResponse = { casts: await getCasts({ fid }) };
Expand Down
8 changes: 4 additions & 4 deletions web/src/app/api/users/[fid]/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getProfile } from '@lib/services/user';
import { ProfileApiResponse } from '@shared/types/api';
import { NextResponse } from 'next/server';
import { getProfile } from "@lib/services/user";
import { ProfileApiResponse } from "@shared/types/api";
import { NextResponse } from "next/server";

export async function GET(
_request: Request,
{ params: { fid } }: { params: { fid: string } },
) {
if (!fid) {
return NextResponse.json({ error: 'fid is required' }, { status: 400 });
return NextResponse.json({ error: "fid is required" }, { status: 400 });
}

const payload: ProfileApiResponse = { profile: await getProfile({ fid }) };
Expand Down
12 changes: 7 additions & 5 deletions web/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { FeedPage } from '@components/feed/FeedPage';
import { LandingPage } from '@components/landing/LandingPage';
import { getServerSession } from 'next-auth';
import { FeedPage } from "@components/feed/FeedPage";
import { LandingPage } from "@components/landing/LandingPage";
import { getServerSession } from "next-auth";

import { authOptions } from './api/auth/[...nextauth]/route';
import { authOptions } from "./api/auth/[...nextauth]/route";

export default async function Home() {
const session = await getServerSession(authOptions);

if (session) {
const { user: { fid } } = session;
const {
user: { fid },
} = session;
return (
<div>
<FeedPage fid={fid} />
Expand Down
16 changes: 8 additions & 8 deletions web/src/components/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use client';
"use client";

import { User } from '@shared/types/models';
import { useMemo, useState } from 'react';
import { User } from "@shared/types/models";
import { useMemo, useState } from "react";

const fallbackUrl = '/default-avatar.png';
const fallbackUrl = "/default-avatar.png";

type AvatarProps = {
size?: 'sm' | 'md' | 'lg';
size?: "sm" | "md" | "lg";
user: User;
pfpDiameter?: number;
};
export function Avatar({ size = 'md', user }: AvatarProps) {
export function Avatar({ size = "md", user }: AvatarProps) {
const [src, setSrc] = useState(user.pfp_url || fallbackUrl);

const diameter = useMemo(() => {
switch (size) {
case 'sm':
case "sm":
return 32;
case 'md':
case "md":
return 46;
default:
return 86;
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/feed/Cast.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Avatar } from '@components/avatar/Avatar';
import { CastEmbeds } from '@components/feed/CastEmbeds';
import { Cast as CastType } from '@shared/types/models';
import { formatDistance } from 'date-fns';
import { Avatar } from "@components/avatar/Avatar";
import { CastEmbeds } from "@components/feed/CastEmbeds";
import { Cast as CastType } from "@shared/types/models";
import { formatDistance } from "date-fns";

type CastProps = {
cast: CastType;
Expand All @@ -21,7 +21,7 @@ export function Cast({ cast }: CastProps) {
</div>
<div
className="text-balance break-words"
style={{ wordBreak: 'break-word' }}
style={{ wordBreak: "break-word" }}
>
{cast.text}
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/feed/CastEmbeds.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Embeds } from '@shared/types/models';
import { Embeds } from "@shared/types/models";

import { CastImageEmbed } from './CastImageEmbed';
import { CastImageEmbed } from "./CastImageEmbed";

type CastEmbedsProps = {
embeds: Embeds;
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/feed/CastImageEmbed.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
"use client";

import { useState } from 'react';
import { useState } from "react";

type CastImageEmbedProps = {
url: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/feed/FeedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Cast } from "@components/feed/Cast";
import { Profile } from '@components/profile/Profile';
import { Profile } from "@components/profile/Profile";
import { getFeed } from "@lib/services/feed";

import { getProfile } from '../../lib/services/user';
import { getProfile } from "../../lib/services/user";

type FeedPageProps = {
fid: string;
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/landing/LandingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Login from '@components/login/Login';
import Login from "@components/login/Login";

export function LandingPage() {
return (
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default function Login() {
config={{
relay: "https://relay.farcaster.xyz",
rpcUrl: "https://mainnet.optimism.io",
siweUri: "http://example.com/login",
domain: "example.com",
siweUri: "http://localhost:3000",
domain: "http://localhost:3000",
}}
>
<SignInButton
Expand All @@ -46,3 +46,5 @@ export default function Login() {
</AuthKitProvider>
);
}

function Button() {}
4 changes: 2 additions & 2 deletions web/src/components/logout/Logout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
"use client";

import { signOut } from 'next-auth/react';
import { signOut } from "next-auth/react";

export default function Logout() {
return (
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from '@shared/types/models';
import { User } from "@shared/types/models";

import { Avatar } from '../avatar/Avatar';
import Logout from '../logout/Logout';
import { Avatar } from "../avatar/Avatar";
import Logout from "../logout/Logout";

type ProfileProps = {
user: User;
Expand Down
64 changes: 32 additions & 32 deletions web/src/lib/services/casts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Embeds } from '@shared/types/models';
import { sql } from 'kysely';
import { Embeds } from "@shared/types/models";
import { sql } from "kysely";

import { db } from '../database/db';
import { processEmbeds } from './embeds';
import { db } from "../database/db";
import { processEmbeds } from "./embeds";

export function formatHash(hash: Buffer) {
return hash.toString('hex');
return hash.toString("hex");
}

export async function getCasts({
Expand All @@ -16,39 +16,39 @@ export async function getCasts({
limit?: number;
}) {
const profile = db
.selectFrom('user_data')
.selectFrom("user_data")
.select([
'fid',
sql`MAX(CASE WHEN type = 1 THEN value ELSE NULL END)`.as('pfp_url'),
sql`MAX(CASE WHEN type = 2 THEN value ELSE NULL END)`.as('display_name'),
sql`MAX(CASE WHEN type = 3 THEN value ELSE NULL END)`.as('bio'),
sql`MAX(CASE WHEN type = 6 THEN value ELSE NULL END)`.as('username'),
"fid",
sql`MAX(CASE WHEN type = 1 THEN value ELSE NULL END)`.as("pfp_url"),
sql`MAX(CASE WHEN type = 2 THEN value ELSE NULL END)`.as("display_name"),
sql`MAX(CASE WHEN type = 3 THEN value ELSE NULL END)`.as("bio"),
sql`MAX(CASE WHEN type = 6 THEN value ELSE NULL END)`.as("username"),
])
.where('deleted_at', 'is', null)
.where('fid', '=', fid)
.groupBy('fid')
.as('profile');
.where("deleted_at", "is", null)
.where("fid", "=", fid)
.groupBy("fid")
.as("profile");

const casts = await db
.selectFrom('casts')
.leftJoin(profile, 'profile.fid', 'casts.fid')
.selectFrom("casts")
.leftJoin(profile, "profile.fid", "casts.fid")
.select([
'casts.hash',
'casts.timestamp',
'casts.text',
'casts.embeds',
'casts.mentions',
'casts.mentions_positions',
'casts.fid',
'profile.pfp_url',
'profile.display_name',
'profile.bio',
'profile.username',
"casts.hash",
"casts.timestamp",
"casts.text",
"casts.embeds",
"casts.mentions",
"casts.mentions_positions",
"casts.fid",
"profile.pfp_url",
"profile.display_name",
"profile.bio",
"profile.username",
])
.where('casts.fid', '=', fid)
.where('casts.deleted_at', 'is', null)
.where('casts.parent_hash', 'is', null)
.orderBy('casts.timestamp', 'desc')
.where("casts.fid", "=", fid)
.where("casts.deleted_at", "is", null)
.where("casts.parent_hash", "is", null)
.orderBy("casts.timestamp", "desc")
.limit(limit)
.execute();

Expand Down
Loading

0 comments on commit 0ea5e35

Please sign in to comment.