-
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
0 parents
commit e81ca97
Showing
31 changed files
with
3,861 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
.env* | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
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,36 @@ | ||
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 | ||
# or | ||
bun 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. | ||
|
||
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. |
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,56 @@ | ||
import NextAuth from "next-auth"; | ||
import GoogleProvider from 'next-auth/providers/google' | ||
import { connectToDB } from "@utils/database"; | ||
import User from "@models/user"; | ||
|
||
|
||
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 the a user is already exist | ||
|
||
const userExists = await User.findOne({ | ||
email: profile.email, | ||
}); | ||
if (userExists) { | ||
console.log("rak dakhl al 9lawi") | ||
} | ||
// if not, tell the user is not and 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 checking if user exists: ', error.message); | ||
return false; | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
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,19 @@ | ||
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() | ||
console.log('Prompt saved'); | ||
return new Response(JSON.stringify(newPrompt), { status: 201 }); | ||
} catch (error) { | ||
return new Response(`prompt is faied for this reason ${error}` , {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,49 @@ | ||
"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: '', | ||
tags: '' | ||
}) | ||
const createPrompt = async (e) => { | ||
console.log("is this heaten ") | ||
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.tags, | ||
}) | ||
}) | ||
|
||
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 |
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: "Prompt.Ai", | ||
description : "Discover & Share" | ||
} | ||
|
||
const RoutLayout = ({ children }) => { | ||
return ( | ||
<Provider> | ||
<html lang="en"> | ||
<body> | ||
<div className="main"> | ||
<div className="gradient"></div> | ||
</div> | ||
|
||
<main className="app"> | ||
<Nav /> | ||
{children} | ||
</main> | ||
</body> | ||
</html> | ||
</Provider> | ||
); | ||
} | ||
|
||
export default RoutLayout |
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,20 @@ | ||
import Feed from "@components/Feed"; | ||
|
||
const Home = () => { | ||
return ( | ||
<section className="w-full flex-center flex-col"> | ||
<h1 className="head_text text-center"> | ||
Discover & Share | ||
<br className="max-md:hidden" /> | ||
<span className="orange_gradient text-center"> AI Powered Prompts</span> | ||
</h1> | ||
<p className="desc text-center"> | ||
Prompt is an open-source AI prompting tool for modern world to discover, create and share creative prompts with all community | ||
</p> | ||
|
||
<Feed /> | ||
</section> | ||
); | ||
}; | ||
export default Home; | ||
|
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,15 @@ | ||
"use client" | ||
import { useState } from "react" | ||
const Feed = () => { | ||
const [text, setText] = useState("") | ||
const handleSearchChange = () => {}; | ||
return ( | ||
|
||
<section> | ||
<form > | ||
<input type="text" value={text} onChange={handleSearchChange} /> | ||
</form> | ||
</section> | ||
) | ||
} | ||
export default Feed |
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,55 @@ | ||
import Link from "next/link"; | ||
|
||
const Form = ({ type, post, setPost, submitting, handleSubmit }) => { | ||
return ( | ||
<> | ||
<section className="w-full max-w-full flex flex-col "> | ||
<h1 className="head_text text-left"> | ||
<span className="blue_gradient">{type} Post</span> | ||
</h1> | ||
<p className="desc text-left max-w-md"> | ||
{type} and share amazing prompts with the worlsd, and let your imagination to inspire the entire world with best | ||
AI prompts{' '} | ||
</p> | ||
<form onSubmit={handleSubmit} className="mt-10 w-full max-w-2xl flex flex-col gap-7 glassmorphism"> | ||
<label> | ||
<span className="font-satoshi font-semibold text-base text-gray">Your Ai Prompt</span> | ||
<textarea | ||
value={post.prompt} | ||
onChange={(e) => setPost({ ...post, prompt: e.target.value })} | ||
placeholder="please tap your prompt" | ||
required | ||
className="form_textarea" | ||
></textarea> | ||
</label> | ||
|
||
<label> | ||
<span className="font-satoshi font-semibold text-base"> | ||
Tag : <span className="font-normal">( #product, #webdevelopment, #idea, etc)</span> | ||
</span> | ||
<textarea | ||
value={post.tags} | ||
onChange={(e) => setPost({ ...post, tags: e.target.value })} | ||
placeholder="#tag" | ||
required | ||
className="form_input" | ||
></textarea> | ||
<div className="flex-end mt-3 mb-5 mx-3 gap-4"> | ||
<Link href="/" className=" text-gray-500 text-sm"> | ||
Cancel | ||
</Link> | ||
<button | ||
type="submit" | ||
disabled={submitting} | ||
className="px-5 py-1.5 text-sm bg-primary-orange rounded-full text-white" | ||
> | ||
{submitting ? `${type}ing...` : type} | ||
</button> | ||
</div> | ||
</label> | ||
</form> | ||
</section> | ||
</> | ||
); | ||
} | ||
export default Form |
Oops, something went wrong.