Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 172 additions & 4 deletions frontend/components/Codesnippet/CodeSnippet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,178 @@
import React from 'react'
import React,{useState,useEffect} from 'react'
import axios from 'axios'
import OpenAIAPI from "react-openai-api";

function CodeSnippet() {
return (
<div>
const [data, setData] = useState( { text:'' });
const [query, setQuery] = useState('');
const [search, setSearch] = useState('');
const [isLoading, setIsLoading] = useState(false);


const changeHandler = (e) => {
setSearch(e.target.value);
}
const fetchData = async () => {
if (search) {
setIsLoading(true);
const res = await fetch(`/api/openai`, {
body: JSON.stringify({
name: search
}),
headers: {
'Content-Type': 'application/json'
},
method: 'POST'
})
const data = await res.json();
setData(data);
setIsLoading(false);
}};

const submitHandler=()=>{
fetchData()
}
// const fetchApi = async()=>{
// // try {
// // const resp = await axios.post('https://xcode321.herokuapp.com/snippet/',{
// // "prompt":"nodejs code for login"
// // })
// // console.log(resp.data)
// // } catch (error) {
// // console.log(error)
// // }
// try {

// let response = await axios.post('/api/openai')
// console.log(response)
// } catch (error) {
// console.log(error)
// }
// }

const onClick=()=>{
fetchApi()
}

return (<>
<div className="mb-24 mt-12">


<div class="flex flex-wrap -mx-3 ">

<div class="w-[10rem] px-3">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
Select Library
</label>
<div class="relative">
<select
name='type'
class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
id="grid-state"
// value={data.type}
// onChange={onChange}

>
<option className=''>Nodejs</option>
<option>Django</option>
<option >Spring</option>

</select>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-500">
<svg
class="fill-current h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
>
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</div>
</div>
</div>
</div>
)


<div class="flex flex-wrap -mx-3 mb-2">

<div class="w-[10rem] px-3">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
Use Case
</label>
<div class="relative">
<select
name='type'
class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
id="grid-state"
// value={data.type}
// onChange={onChange}

>
<option className=''>Login</option>
<option>Register</option>
<option >Get all</option>
<option >Post</option>
<option >Update</option>

</select>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-500">
<svg
class="fill-current h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
>
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</div>
</div>
</div>


</div>
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
Custom search
</label>
<input
type="text"
value={search}
className='border-2'
onChange={(e)=>changeHandler(e)}
/>
<div style={{
background: 'linear-gradient(90deg, #1E3B86 0%, #3765DC 100%)'
}} onClick={submitHandler }
className="mx-auto mt-12 text-lg text-white w-[10rem] text-center rounded-lg py-2 items-center ">
Generate
</div>
<div className="bg-black min-w-[30rem] max-w-[40rem] min-h-[10rem] mt-12 rounded-lg text-white p-2 pl-4">
<div className="flex gap-2">
<div className="w-4 h-4 bg-red-600 rounded-full"> </div>
<div className="w-4 h-4 bg-green-600 rounded-full"> </div>
<div className="w-4 h-4 bg-blue-600 rounded-full"> </div>
</div>
<div className="max-w-[20ch] mt-6 font-semibold text-white">
{isLoading ? (
<div>Loading ...</div>
) : (
<span>
{data.text}
</span>
)}


</div>
</div>
</div>
<div className=''>
<h3>
<title>GPT-3 App</title>
<link rel="icon" href="/favicon.ico" />
</h3>


</div>
</>
);
}


export default CodeSnippet
39 changes: 23 additions & 16 deletions frontend/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,34 @@ const Sidebar = () => {
<div className="mt-12">
<Link href="/dashboard/createtable">
<h3
className={`text-2xl cursor-pointer text-text-prm mt6 px-2 py-2 ${
router.pathname.includes("createtable")
className={`text-2xl cursor-pointer text-text-prm mt6 px-2 py-2 ${router.pathname.includes("createtable")
? "bg-gradient-to-r from-[#1e3b86] to-[#3765dc] rounded-sm"
: ""
}`}
}`}
>
Create Table
</h3>
</Link>
<Link href="/codesnippet">
<h3
className={`text-2xl cursor-pointer text-text-prm mt-6 px-2 py-2 ${router.pathname.includes("codesnippet")
? "bg-gradient-to-r from-[#1e3b86] to-[#3765dc] rounded-sm"
: ""
}`}
>
Code Snippet
</h3>
</Link>
<div className="w-44">
<h3
onClick={() => {
setToggle(!toggle);
setToggle2(false);
}}
className={` text-2xl flex items-center text-text-prm mt-8 cursor-pointer h-10 px-2 py-2 ${
router.pathname.includes("createapi")
className={` text-2xl flex items-center text-text-prm mt-8 cursor-pointer h-10 px-2 py-2 ${router.pathname.includes("createapi")
? "bg-gradient-to-r from-[#1e3b86] to-[#3765dc] rounded-sm"
: ""
}`}
}`}
>
Create API
{toggle ? (
Expand All @@ -80,7 +88,7 @@ const Sidebar = () => {
{tables?.map((data) => {
return (
<Link href={`/dashboard/createapi/${data.tablename}`}>
<li>{data.tablename}</li>
<li className="mt-2">{data.tablename}</li>
</Link>
);
})}
Expand All @@ -99,11 +107,10 @@ const Sidebar = () => {
setToggle2(!toggle2);
setToggle(false);
}}
className={`text-2xl flex items-center text-text-prm mt-8 cursor-pointer px-2 py-2 ${
router.pathname.includes("apidocs")
className={`text-2xl flex items-center text-text-prm mt-8 cursor-pointer px-2 py-2 ${router.pathname.includes("apidocs")
? "bg-gradient-to-r from-[#1e3b86] to-[#3765dc] rounded-sm"
: ""
}`}
}`}
>
API Docs
{toggle2 ? (
Expand All @@ -116,12 +123,12 @@ const Sidebar = () => {
<div className="text-xl text-text-prm p-4">
<ul className="cursor-pointer">
{tables?.map((data) => {
return (
<Link href={`/dashboard/apidocs/${data.tablename}`}>
<li>{data.tablename}</li>
</Link>
);
})}
return (
<Link href={`/dashboard/apidocs/${data.tablename}`}>
<li className="mt-2">{data.tablename}</li>
</Link>
);
})}
</ul>
</div>
)}
Expand Down
69 changes: 68 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"axios": "^1.1.3",
"next": "13.0.0",
"openai": "^3.0.1",
"openai-api": "^1.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.6.0"
"react-icons": "^4.6.0",
"react-openai-api": "^1.0.2"
},
"devDependencies": {
"autoprefixer": "^10.4.12",
Expand Down
Loading