forked from adrianhajdin/project_next_14_ai_prompt_sharing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c37f07
commit 4cafd7d
Showing
42 changed files
with
2,653 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.env | ||
|
||
# testing | ||
/coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,6 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file. | ||
|
||
[http://localhost:3000/api/hello](http://localhost:3000/api/hello) is an endpoint that uses [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers). This endpoint can be edited in `app/api/hello/route.js`. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. | ||
[] Implement Search | ||
- Search by prompt | ||
- Search by tag | ||
- Search by username | ||
[] Implement Click on tag | ||
[] Implement View other profiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import NextAuth from 'next-auth'; | ||
import GoogleProvider from 'next-auth/providers/google'; | ||
|
||
import User from '@models/user'; | ||
import { connectToDB } from '@utils/database'; | ||
|
||
const handler = NextAuth({ | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: process.env.GOOGLE_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
}) | ||
], | ||
callbacks: { | ||
async session({ session }) { | ||
const sessionUser = await User.findOne({ | ||
email: session.user.email | ||
}) | ||
|
||
session.user.id = sessionUser._id.toString(); | ||
|
||
return session; | ||
}, | ||
async signIn({ profile }) { | ||
try { | ||
await connectToDB(); | ||
|
||
// check if a user already exists | ||
const userExists = await User.findOne({ | ||
email: profile.email | ||
}); | ||
|
||
// if not, create a new user | ||
if(!userExists) { | ||
await User.create({ | ||
email: profile.email, | ||
username: profile.name.replace(" ", "").toLowerCase(), | ||
image: profile.picture | ||
}) | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
} | ||
} | ||
}) | ||
|
||
export { handler as GET, handler as POST }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { connectToDB } from '@utils/database'; | ||
import Prompt from '@models/prompt'; | ||
|
||
// GET (read) | ||
export const GET = async (request, { params }) => { | ||
try { | ||
await connectToDB(); | ||
|
||
const prompt = await Prompt.findById(params.id).populate('creator'); | ||
if(!prompt) return new Response("Prompt not found", { status: 404 }) | ||
|
||
return new Response(JSON.stringify(prompt), { status: 200 }) | ||
} catch (error) { | ||
return new Response("Failed to fetch all prompts", { status: 500 }) | ||
} | ||
} | ||
|
||
// PATCH (update) | ||
export const PATCH = async (request, { params }) => { | ||
const { prompt, tag } = await request.json(); | ||
|
||
try { | ||
await connectToDB(); | ||
|
||
const existingPrompt = await Prompt.findById(params.id); | ||
|
||
if(!existingPrompt) return new Response("Prompt not found", { status: 404 }) | ||
|
||
existingPrompt.prompt = prompt; | ||
existingPrompt.tag = tag; | ||
|
||
await existingPrompt.save(); | ||
|
||
return new Response(JSON.stringify(existingPrompt), { status: 200 }) | ||
} catch (error) { | ||
return new Response("Failed to update prompt", { status: 500 }) | ||
} | ||
} | ||
|
||
// DELETE (delete) | ||
export const DELETE = async (request, { params }) => { | ||
try { | ||
await connectToDB(); | ||
|
||
await Prompt.findByIdAndRemove(params.id); | ||
|
||
return new Response("Prompt deleted successfully", { status: 200 }) | ||
} catch (error) { | ||
return new Response("Failed to delete prompt", { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { connectToDB } from '@utils/database'; | ||
import Prompt from '@models/prompt'; | ||
|
||
export const POST = async (req) => { | ||
const { userId, prompt, tag } = await req.json(); | ||
|
||
try { | ||
await connectToDB(); | ||
const newPrompt = new Prompt({ | ||
creator: userId, | ||
prompt, | ||
tag | ||
}) | ||
|
||
await newPrompt.save(); | ||
|
||
return new Response(JSON.stringify(newPrompt), { status: 201 }) | ||
} catch (error) { | ||
return new Response("Failed to create a new prompt", { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { connectToDB } from '@utils/database'; | ||
import Prompt from '@models/prompt'; | ||
|
||
export const GET = async (request) => { | ||
try { | ||
await connectToDB(); | ||
|
||
const prompts = await Prompt.find({}).populate('creator'); | ||
|
||
return new Response(JSON.stringify(prompts), { status: 200 }) | ||
} catch (error) { | ||
return new Response("Failed to fetch all prompts", { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { connectToDB } from '@utils/database'; | ||
import Prompt from '@models/prompt'; | ||
|
||
export const GET = async (request, { params }) => { | ||
try { | ||
await connectToDB(); | ||
|
||
const prompts = await Prompt.find({ | ||
creator: params.id | ||
}).populate('creator'); | ||
|
||
return new Response(JSON.stringify(prompts), { status: 200 }) | ||
} catch (error) { | ||
return new Response("Failed to fetch all prompts", { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { useSession } from 'next-auth/react'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
import Form from '@components/Form'; | ||
|
||
const CreatePrompt = () => { | ||
const router = useRouter(); | ||
const { data: session } = useSession(); | ||
|
||
const [submitting, setSubmitting] = useState(false); | ||
const [post, setPost] = useState({ | ||
prompt: '', | ||
tag: '', | ||
}); | ||
|
||
const createPrompt = async (e) => { | ||
e.preventDefault(); | ||
setSubmitting(true); | ||
|
||
try { | ||
const response = await fetch('/api/prompt/new', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
prompt: post.prompt, | ||
userId: session?.user.id, | ||
tag: post.tag | ||
}) | ||
}) | ||
|
||
if(response.ok) { | ||
router.push('/'); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} finally { | ||
setSubmitting(false); | ||
} | ||
} | ||
|
||
return ( | ||
<Form | ||
type="Create" | ||
post={post} | ||
setPost={setPost} | ||
submitting={submitting} | ||
handleSubmit={createPrompt} | ||
/> | ||
) | ||
} | ||
|
||
export default CreatePrompt |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '@styles/globals.css'; | ||
|
||
import Nav from '@components/Nav'; | ||
import Provider from '@components/Provider'; | ||
|
||
export const metadata = { | ||
title: "Promptopia", | ||
description: 'Discover & Share AI Prompts' | ||
} | ||
|
||
const RootLayout = ({ children }) => { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Provider> | ||
<div className="main"> | ||
<div className="gradient" /> | ||
</div> | ||
|
||
<main className="app"> | ||
<Nav /> | ||
{children} | ||
</main> | ||
</Provider> | ||
</body> | ||
</html> | ||
) | ||
} | ||
|
||
export default RootLayout; |
Oops, something went wrong.