Skip to content

Commit b4ba380

Browse files
authored
General eslint prettier + UI lib version update (#10)
1 parent dc4daea commit b4ba380

File tree

141 files changed

+3484
-2597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+3484
-2597
lines changed

.eslintrc.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
"root": true,
44
"extends": [
55
"next/core-web-vitals",
6-
"prettier",
76
"plugin:tailwindcss/recommended",
8-
"plugin:@typescript-eslint/recommended"
7+
"plugin:@typescript-eslint/recommended",
8+
"prettier"
99
],
10-
"plugins": ["tailwindcss"],
10+
"plugins": ["tailwindcss", "prettier"],
1111
"rules": {
1212
"@next/next/no-html-link-for-pages": "off",
1313
"react/jsx-key": "off",
1414
"tailwindcss/no-custom-classname": "off",
15-
"indent": ["error", 2],
1615
"@typescript-eslint/no-unused-vars": "error",
1716
"@typescript-eslint/ban-ts-comment": "off",
18-
"@typescript-eslint/no-empty-function": "off"
17+
"@typescript-eslint/no-empty-function": "off",
18+
"prettier/prettier": "error"
1919
},
2020
"settings": {
2121
"tailwindcss": {

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<p align="center">
1111
<a href="#tech-stacks"><strong>Tech stacks</strong></a> ·
12-
<a href="#nstallation"><strong>Installation</strong></a> ·
12+
<a href="#installation"><strong>Installation</strong></a> ·
1313
<a href="#run-locally"><strong>Run Locally</strong></a> ·
1414
<a href="#authors"><strong>Authors</strong></a>
1515
</p>

app/(auth)/layout.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { AppLogo } from "@/components/ui/common/AppLogo"
1+
import { AppLogo } from "@/components/ui/common/AppLogo";
22

33
type AuthLayoutProps = {
4-
children: React.ReactNode
5-
}
6-
4+
children: React.ReactNode;
5+
};
6+
77
export default function AuthLayout({ children }: AuthLayoutProps) {
88
return (
99
<div className="min-h-screen">
@@ -13,11 +13,11 @@ export default function AuthLayout({ children }: AuthLayoutProps) {
1313
className="absolute inset-0 bg-ring bg-right-bottom brightness-50 lg:bg-center lg:brightness-100"
1414
style={{
1515
backgroundImage:
16-
"url(https://images.unsplash.com/photo-1627645835237-0743e52b991f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1587&q=80)",
16+
"url(https://images.unsplash.com/photo-1627645835237-0743e52b991f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1587&q=80)",
1717
}}
1818
/>
1919
<div className="relative z-20 flex items-center text-lg font-medium">
20-
<AppLogo/>
20+
<AppLogo />
2121
</div>
2222
</div>
2323
<div className="z-10 w-screen px-4 lg:w-full lg:p-8">
@@ -27,5 +27,5 @@ export default function AuthLayout({ children }: AuthLayoutProps) {
2727
</div>
2828
</div>
2929
</div>
30-
)
31-
}
30+
);
31+
}

app/(auth)/signin/page.tsx

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import { Metadata } from "next"
2-
import { redirect } from "next/navigation"
3-
import { UserAuthForm } from "@/components/modules/auth/UserAuthForm"
4-
import { getCurrentSession } from "@/lib/session"
5-
import { createClient } from "@/lib/supabase/server"
6-
import { cookies } from "next/headers"
7-
import { Heading3 } from "@/components/ui/typography"
8-
import { siteConfig } from "@/config/site"
1+
import { Metadata } from "next";
2+
import { cookies } from "next/headers";
3+
import { redirect } from "next/navigation";
4+
5+
import { siteConfig } from "@/config/site";
6+
import { getCurrentSession } from "@/lib/session";
7+
import { createClient } from "@/lib/supabase/server";
8+
import { Heading3 } from "@/components/ui/typography";
9+
import { UserAuthForm } from "@/components/modules/auth/UserAuthForm";
910

1011
export const metadata: Metadata = {
1112
title: "Sigin",
1213
description: "Sigin to your account",
13-
}
14+
};
1415

15-
export const runtime = "edge"
16-
export const dynamic = 'force-dynamic'
16+
export const runtime = "edge";
17+
export const dynamic = "force-dynamic";
1718

1819
export default async function LoginPage() {
19-
const cookieStore = cookies()
20-
const supabase = createClient(cookieStore)
21-
const session = await getCurrentSession(supabase)
20+
const cookieStore = cookies();
21+
const supabase = createClient(cookieStore);
22+
const session = await getCurrentSession(supabase);
2223

2324
if (session) {
24-
redirect(`/apps/chat`)
25+
redirect(`/apps/chat`);
2526
}
2627

2728
return (
@@ -34,5 +35,5 @@ export default async function LoginPage() {
3435
</div>
3536
<UserAuthForm />
3637
</>
37-
)
38-
}
38+
);
39+
}

app/(auth)/signup/page.tsx

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import { Metadata } from "next"
2-
import { redirect } from "next/navigation"
3-
import { UserSignupForm } from "@/components/modules/auth/UserSignupForm"
4-
import { createClient } from "@/lib/supabase/server"
5-
import { getCurrentSession } from "@/lib/session"
6-
import { cookies } from "next/headers"
7-
import { Heading3 } from "@/components/ui/typography"
8-
import { siteConfig } from "@/config/site"
1+
import { Metadata } from "next";
2+
import { cookies } from "next/headers";
3+
import { redirect } from "next/navigation";
94

10-
export const runtime = "edge"
5+
import { siteConfig } from "@/config/site";
6+
import { getCurrentSession } from "@/lib/session";
7+
import { createClient } from "@/lib/supabase/server";
8+
import { Heading3 } from "@/components/ui/typography";
9+
import { UserSignupForm } from "@/components/modules/auth/UserSignupForm";
10+
11+
export const runtime = "edge";
1112
export const metadata: Metadata = {
1213
title: "Signup",
1314
description: "Signup a new account",
14-
}
15+
};
1516

16-
export const dynamic = 'force-dynamic'
17+
export const dynamic = "force-dynamic";
1718

1819
export default async function LoginPage() {
19-
const cookieStore = cookies()
20-
const supabase = createClient(cookieStore)
21-
const session = await getCurrentSession(supabase)
20+
const cookieStore = cookies();
21+
const supabase = createClient(cookieStore);
22+
const session = await getCurrentSession(supabase);
2223

2324
if (session) {
24-
redirect(`/apps/chat`)
25+
redirect(`/apps/chat`);
2526
}
2627

2728
return (
@@ -34,5 +35,5 @@ export default async function LoginPage() {
3435
</div>
3536
<UserSignupForm />
3637
</>
37-
)
38-
}
38+
);
39+
}

app/api/auth/callback/route.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { NextResponse } from 'next/server'
2-
import { cookies } from 'next/headers'
3-
import { createClient } from '@/lib/supabase/server'
1+
import { cookies } from "next/headers";
2+
import { NextResponse } from "next/server";
3+
4+
import { createClient } from "@/lib/supabase/server";
45

56
export async function GET(request: Request) {
67
// The `/auth/callback` route is required for the server-side auth flow implemented
78
// by the Auth Helpers package. It exchanges an auth code for the user's session.
89
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-sign-in-with-code-exchange
9-
const requestUrl = new URL(request.url)
10-
const code = requestUrl.searchParams.get('code')
10+
const requestUrl = new URL(request.url);
11+
const code = requestUrl.searchParams.get("code");
1112

1213
if (code) {
13-
const cookieStore = cookies()
14-
const supabase = createClient(cookieStore)
15-
await supabase.auth.exchangeCodeForSession(code)
14+
const cookieStore = cookies();
15+
const supabase = createClient(cookieStore);
16+
await supabase.auth.exchangeCodeForSession(code);
1617
}
1718

1819
// URL to redirect to after sign in process completes
19-
return NextResponse.redirect(requestUrl.origin)
20+
return NextResponse.redirect(requestUrl.origin);
2021
}

app/api/auth/logout/route.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { createClient } from '@/lib/supabase/server'
2-
import { cookies } from 'next/headers'
3-
import { type NextRequest, NextResponse } from 'next/server'
1+
import { cookies } from "next/headers";
2+
import { NextResponse, type NextRequest } from "next/server";
43

5-
export const dynamic = 'force-dynamic'
4+
import { createClient } from "@/lib/supabase/server";
5+
6+
export const dynamic = "force-dynamic";
67

78
export async function POST(req: NextRequest) {
8-
const cookieStore = cookies()
9-
const supabase = createClient(cookieStore)
9+
const cookieStore = cookies();
10+
const supabase = createClient(cookieStore);
1011

1112
// Check if we have a session
1213
const {
1314
data: { session },
14-
} = await supabase.auth.getSession()
15+
} = await supabase.auth.getSession();
1516

1617
if (session) {
17-
await supabase.auth.signOut()
18+
await supabase.auth.signOut();
1819
}
1920

20-
return NextResponse.redirect(new URL('/signin', req.url), {
21+
return NextResponse.redirect(new URL("/signin", req.url), {
2122
status: 302,
22-
})
23-
}
23+
});
24+
}

app/api/chat/route.ts

+53-45
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
import OpenAI from 'openai'
2-
import { OpenAIStream, StreamingTextResponse } from 'ai'
3-
import { pick } from 'lodash';
4-
import { AxiomRequest, withAxiom } from 'next-axiom';
5-
import { getCurrentSession } from '@/lib/session';
6-
import { createNewMessage, deleteMessagesFrom, getMessageById } from '@/lib/db/message';
7-
import { createNewChat } from '@/lib/db/chats';
8-
import { getAppBySlug } from '@/lib/db/apps';
9-
import { createClient } from "@/lib/supabase/server";
101
import { cookies } from "next/headers";
2+
import { env } from "@/env.mjs";
3+
import { OpenAIStream, StreamingTextResponse } from "ai";
4+
import { pick } from "lodash";
5+
import { AxiomRequest, withAxiom } from "next-axiom";
6+
import OpenAI from "openai";
7+
8+
import { getAppBySlug } from "@/lib/db/apps";
9+
import { createNewChat } from "@/lib/db/chats";
1110
import {
12-
env
13-
} from '@/env.mjs';
11+
createNewMessage,
12+
deleteMessagesFrom,
13+
getMessageById,
14+
} from "@/lib/db/message";
15+
import { getCurrentSession } from "@/lib/session";
16+
import { createClient } from "@/lib/supabase/server";
1417

1518
export const dynamic = "force-dynamic";
16-
export const runtime = "edge"
17-
export const preferredRegion = "home"
19+
export const runtime = "edge";
20+
export const preferredRegion = "home";
1821

1922
const openai = new OpenAI({
20-
apiKey: env.OPENAI_API_KEY
21-
})
23+
apiKey: env.OPENAI_API_KEY,
24+
});
2225

2326
export const POST = withAxiom(async (req: AxiomRequest) => {
2427
const log = req.log.with({
25-
route: 'api/chat',
28+
route: "api/chat",
2629
});
27-
28-
const cookieStore = cookies()
29-
const supabase = createClient(cookieStore)
30-
const params = await req.json()
30+
31+
const cookieStore = cookies();
32+
const supabase = createClient(cookieStore);
33+
const params = await req.json();
3134
const {
3235
messages,
3336
temperature,
@@ -39,18 +42,18 @@ export const POST = withAxiom(async (req: AxiomRequest) => {
3942
chatId,
4043
isRegenerate,
4144
regenerateMessageId,
42-
isNewChat
45+
isNewChat,
4346
} = params;
4447

45-
const session = await getCurrentSession(supabase)
46-
const currentApp = await getAppBySlug(supabase, '/apps/chat')
48+
const session = await getCurrentSession(supabase);
49+
const currentApp = await getAppBySlug(supabase, "/apps/chat");
4750

4851
if (!session) {
49-
return new Response('Unauthorized', { status: 401 })
52+
return new Response("Unauthorized", { status: 401 });
5053
}
5154

52-
const lastMessage = messages[messages.length - 1]
53-
const profileId = session.user.id
55+
const lastMessage = messages[messages.length - 1];
56+
const profileId = session.user.id;
5457

5558
if (!isRegenerate) {
5659
if (isNewChat && currentApp) {
@@ -59,45 +62,50 @@ export const POST = withAxiom(async (req: AxiomRequest) => {
5962
appId: currentApp.id,
6063
profileId,
6164
name: lastMessage.content,
62-
})
65+
});
6366
}
6467
await createNewMessage(supabase, {
6568
chatId,
6669
content: lastMessage.content,
6770
profileId,
68-
role: 'user',
69-
id: lastMessage.id
70-
})
71-
}else if (regenerateMessageId) {
72-
const fromMessage = await getMessageById(supabase, regenerateMessageId)
71+
role: "user",
72+
id: lastMessage.id,
73+
});
74+
} else if (regenerateMessageId) {
75+
const fromMessage = await getMessageById(supabase, regenerateMessageId);
7376
if (fromMessage?.createdAt) {
74-
await deleteMessagesFrom(supabase, chatId, profileId, fromMessage.createdAt)
77+
await deleteMessagesFrom(
78+
supabase,
79+
chatId,
80+
profileId,
81+
fromMessage.createdAt
82+
);
7583
}
7684
}
7785

7886
const response = await openai.chat.completions.create({
7987
model,
8088
temperature,
8189
// eslint-disable-next-line @typescript-eslint/no-explicit-any
82-
messages: messages.map((message: any) => pick(message, 'content', 'role')),
90+
messages: messages.map((message: any) => pick(message, "content", "role")),
8391
max_tokens: maxTokens,
8492
top_p: topP,
8593
frequency_penalty: frequencyPenalty,
8694
presence_penalty: presencePenalty,
87-
stream: true
88-
})
89-
log.debug('Create stream');
90-
95+
stream: true,
96+
});
97+
log.debug("Create stream");
98+
9199
const stream = OpenAIStream(response, {
92100
onCompletion: async (completion: string) => {
93101
await createNewMessage(supabase, {
94102
chatId,
95103
content: completion,
96104
profileId,
97-
role: 'assistant',
98-
})
99-
}
100-
})
101-
102-
return new StreamingTextResponse(stream)
103-
})
105+
role: "assistant",
106+
});
107+
},
108+
});
109+
110+
return new StreamingTextResponse(stream);
111+
});

0 commit comments

Comments
 (0)