Skip to content

Commit aee9bdc

Browse files
committed
init
1 parent 65037bf commit aee9bdc

Some content is hidden

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

56 files changed

+2478
-146
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env
3031

3132
# vercel
3233
.vercel

app/actions.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use server";
2+
3+
import { getServerSession } from "next-auth";
4+
import { authOptions } from "@/lib/auth-options";
5+
import { prisma } from "@/prisma/db";
6+
import { revalidatePath } from "next/cache";
7+
import { redirect } from "next/navigation";
8+
9+
let sessionCache: any = null;
10+
11+
async function getSession() {
12+
if (!sessionCache) {
13+
sessionCache = await getServerSession(authOptions);
14+
}
15+
return sessionCache;
16+
}
17+
18+
export async function addSnippet(formData: FormData) {
19+
const session = await getSession();
20+
21+
const title = String(formData.get("title"));
22+
const code = String(formData.get("code"));
23+
const language = String(formData.get("language"));
24+
25+
const authorId = session?.user.id;
26+
const authorName = session?.user.name;
27+
28+
try {
29+
await prisma.snippet.create({
30+
data: {
31+
title,
32+
code,
33+
language,
34+
authorId,
35+
},
36+
});
37+
} catch (error: any) {
38+
return {
39+
error: error.message,
40+
};
41+
}
42+
revalidatePath("/profile");
43+
redirect(`/profile/${authorName}`);
44+
}

app/api/auth/[...nextauth]/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { authOptions } from "@/lib/auth-options";
2+
import NextAuth from "next-auth";
3+
4+
const handler = NextAuth(authOptions);
5+
6+
export { handler as GET, handler as POST };

app/api/chat/route.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import OpenAI from "openai";
2+
import { OpenAIStream, StreamingTextResponse } from "ai";
3+
4+
// Create an OpenAI API client (that's edge friendly!)
5+
const openai = new OpenAI({
6+
apiKey: process.env.OPENAI_API_KEY || "",
7+
});
8+
9+
// IMPORTANT! Set the runtime to edge
10+
export const runtime = "edge";
11+
12+
export async function POST(req: Request) {
13+
// Extract the `prompt` from the body of the request
14+
const { messages } = await req.json();
15+
16+
// Ask OpenAI for a streaming chat completion given the prompt
17+
const response = await openai.chat.completions.create({
18+
model: "gpt-3.5-turbo",
19+
stream: true,
20+
messages: messages,
21+
});
22+
23+
// Convert the response into a friendly text-stream
24+
const stream = OpenAIStream(response);
25+
// Respond with the stream
26+
return new StreamingTextResponse(stream);
27+
}

app/create/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
3+
import FormUpload from "@/components/snippets/form-upload";
4+
5+
export default function Home() {
6+
return (
7+
<div className="mt-4">
8+
<div className="md:flex md:items-center md:justify-between">
9+
<div className="min-w-0 flex-1">
10+
<h2 className="text-2xl font-bold leading-7 sm:truncate sm:text-3xl sm:tracking-tight">
11+
Create a new snippet
12+
</h2>
13+
</div>
14+
</div>
15+
<FormUpload />
16+
</div>
17+
);
18+
}

app/explore/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
export default function Page() {
4+
return <div>Explore</div>;
5+
}

app/globals.css

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,76 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 0 0% 3.9%;
49

5-
:root {
6-
--foreground-rgb: 0, 0, 0;
7-
--background-start-rgb: 214, 219, 220;
8-
--background-end-rgb: 255, 255, 255;
9-
}
10+
--card: 0 0% 100%;
11+
--card-foreground: 0 0% 3.9%;
12+
13+
--popover: 0 0% 100%;
14+
--popover-foreground: 0 0% 3.9%;
15+
16+
--primary: 0 0% 9%;
17+
--primary-foreground: 0 0% 98%;
18+
19+
--secondary: 0 0% 96.1%;
20+
--secondary-foreground: 0 0% 9%;
21+
22+
--muted: 0 0% 96.1%;
23+
--muted-foreground: 0 0% 45.1%;
24+
25+
--accent: 0 0% 96.1%;
26+
--accent-foreground: 0 0% 9%;
27+
28+
--destructive: 0 84.2% 60.2%;
29+
--destructive-foreground: 0 0% 98%;
1030

11-
@media (prefers-color-scheme: dark) {
12-
:root {
13-
--foreground-rgb: 255, 255, 255;
14-
--background-start-rgb: 0, 0, 0;
15-
--background-end-rgb: 0, 0, 0;
31+
--border: 0 0% 89.8%;
32+
--input: 0 0% 89.8%;
33+
--ring: 0 0% 3.9%;
34+
35+
--radius: 0.5rem;
36+
}
37+
38+
.dark {
39+
--background: 0 0% 3.9%;
40+
--foreground: 0 0% 98%;
41+
42+
--card: 0 0% 3.9%;
43+
--card-foreground: 0 0% 98%;
44+
45+
--popover: 0 0% 3.9%;
46+
--popover-foreground: 0 0% 98%;
47+
48+
--primary: 0 0% 98%;
49+
--primary-foreground: 0 0% 9%;
50+
51+
--secondary: 0 0% 14.9%;
52+
--secondary-foreground: 0 0% 98%;
53+
54+
--muted: 0 0% 14.9%;
55+
--muted-foreground: 0 0% 63.9%;
56+
57+
--accent: 0 0% 14.9%;
58+
--accent-foreground: 0 0% 98%;
59+
60+
--destructive: 0 62.8% 30.6%;
61+
--destructive-foreground: 0 0% 98%;
62+
63+
--border: 0 0% 14.9%;
64+
--input: 0 0% 14.9%;
65+
--ring: 0 0% 83.1%;
1666
}
1767
}
18-
19-
body {
20-
color: rgb(var(--foreground-rgb));
21-
background: linear-gradient(
22-
to bottom,
23-
transparent,
24-
rgb(var(--background-end-rgb))
25-
)
26-
rgb(var(--background-start-rgb));
27-
}
68+
69+
@layer base {
70+
* {
71+
@apply border-border;
72+
}
73+
body {
74+
@apply bg-background text-foreground;
75+
}
76+
}

app/layout.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
import type { Metadata } from 'next'
2-
import { Inter } from 'next/font/google'
3-
import './globals.css'
1+
import type { Metadata } from "next";
2+
import "./globals.css";
3+
import Navbar from "@/components/layout/navbar";
44

5-
const inter = Inter({ subsets: ['latin'] })
5+
import { AuthProvider } from "@/lib/auth-provider";
6+
import { ThemeProvider } from "@/lib/theme-provider";
7+
8+
import { GeistSans } from "geist/font";
9+
import { Container } from "@/components/layout/container";
10+
import { Toaster } from "sonner";
611

712
export const metadata: Metadata = {
8-
title: 'Create Next App',
9-
description: 'Generated by create next app',
10-
}
13+
title: "Create Next App",
14+
description: "Generated by create next app",
15+
};
1116

1217
export default function RootLayout({
1318
children,
1419
}: {
15-
children: React.ReactNode
20+
children: React.ReactNode;
1621
}) {
1722
return (
18-
<html lang="en">
19-
<body className={inter.className}>{children}</body>
23+
<html lang="en" className={GeistSans.className} suppressHydrationWarning>
24+
<AuthProvider>
25+
<body>
26+
<ThemeProvider
27+
attribute="class"
28+
defaultTheme="system"
29+
enableSystem
30+
disableTransitionOnChange
31+
>
32+
<Navbar />
33+
<Container>{children}</Container>
34+
<Toaster position="top-center" richColors />
35+
</ThemeProvider>
36+
</body>
37+
</AuthProvider>
2038
</html>
21-
)
39+
);
2240
}

app/opengraph-image.tsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { ImageResponse } from "next/og";
2+
3+
export const runtime = "edge";
4+
5+
export const alt = "About Acme";
6+
export const size = {
7+
width: 1200,
8+
height: 630,
9+
};
10+
11+
export const contentType = "image/png";
12+
13+
export default async function OGImage() {
14+
return new ImageResponse(
15+
(
16+
<div
17+
style={{
18+
display: "flex",
19+
height: "100%",
20+
width: "100%",
21+
alignItems: "center",
22+
justifyContent: "center",
23+
letterSpacing: "-.02em",
24+
fontWeight: 700,
25+
background: "white",
26+
}}
27+
>
28+
<div
29+
style={{
30+
left: 42,
31+
top: 42,
32+
position: "absolute",
33+
display: "flex",
34+
alignItems: "center",
35+
}}
36+
>
37+
<span
38+
style={{
39+
width: 24,
40+
height: 24,
41+
background: "black",
42+
}}
43+
/>
44+
<span
45+
style={{
46+
marginLeft: 8,
47+
fontSize: 20,
48+
}}
49+
>
50+
Snippets
51+
</span>
52+
</div>
53+
<div
54+
style={{
55+
display: "flex",
56+
flexWrap: "wrap",
57+
justifyContent: "center",
58+
padding: "20px 50px",
59+
margin: "0 42px",
60+
fontSize: 40,
61+
width: "auto",
62+
maxWidth: 550,
63+
textAlign: "center",
64+
backgroundColor: "black",
65+
color: "white",
66+
lineHeight: 1.4,
67+
}}
68+
>
69+
Manage your code snippets
70+
</div>
71+
</div>
72+
),
73+
{
74+
...size,
75+
}
76+
);
77+
}

0 commit comments

Comments
 (0)