-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rajatkriplani/feature/migrate-html-to-nextjs
Feature/migrate html to nextjs
- Loading branch information
Showing
9 changed files
with
190 additions
and
31 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
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
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,24 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST(request: Request) { | ||
const { userInput } = await request.json(); | ||
try { | ||
// Make a request to the Flask app | ||
const response = await fetch('http://127.0.0.1:5000/api/similarity', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ user_input: userInput }), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch data'); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
return NextResponse.json({ error: 'An error occurred while fetching data' }, { 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,89 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { VerseSimilarity } from "@/lib/interface"; | ||
|
||
export default function VerseSearch() { | ||
const [userInput, setUserInput] = useState(""); | ||
const [verses, setVerses] = useState<VerseSimilarity>(); | ||
const [error, setError] = useState<string>(); | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setUserInput(e.target.value); | ||
setError(""); | ||
} | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
try { | ||
const response = await fetch('/api/similarity', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ userInput }), | ||
}); | ||
|
||
if (!response.ok) { | ||
setError('Failed to fetch data'); | ||
return | ||
} | ||
|
||
const data = await response.json(); | ||
setVerses(data); | ||
setUserInput(""); | ||
setError(""); | ||
} catch (error) { | ||
setError('An error occurred while fetching data'); | ||
} | ||
}; | ||
|
||
const filteredVerses = verses && verses.results.filter((result) => result[1] > 0); | ||
|
||
return ( | ||
<div className="flex flex-col min-h-screen items-center justify-center p-8 gap-8 max-sm:m-auto"> | ||
<h1 className="text-2xl sm:text-4xl font-extrabold sm:font-bold text-center text-siteColor"> | ||
Bible Verse Similarity | ||
</h1> | ||
<form onSubmit={handleSubmit} className="flex flex-col items-center gap-2 bg-white p-8 rounded-xl shadow-xl w-full sm:w-[32rem]"> | ||
<p className="text-xl font-bold text-gray-700">Enter a theme:</p> | ||
<input | ||
type="text" | ||
value={userInput} | ||
onChange={(e) => handleInputChange(e)} | ||
required | ||
className="p-2 border border-gray-300 rounded w-full mb-8 text-lg" | ||
/> | ||
{error && <p className="text-red-500 mt-[-6px]">{error}</p>} | ||
<button | ||
type="submit" | ||
className="bg-siteColor/95 text-white py-3 px-6 w-full rounded mt-4 hover:bg-siteColor text-center text-lg max-xs:text-sm font-semibold"> | ||
Find Similar Verses | ||
</button> | ||
</form> | ||
{/* Display results if any are available */} | ||
{verses && ( | ||
<div className="flex flex-col items-center gap-4"> | ||
<h2 className="text-xl sm:text-3xl font-bold text-gray-700">Results for "{verses.user_input}"</h2> | ||
{filteredVerses?.length === 0 ? ( | ||
<p className="text-sm sm:text-xl font-bold text-gray-600 text-center"> | ||
Your search returned void 😅, good news God's word never does! Try another search 🔎 | ||
</p> | ||
) : | ||
<ul className="flex flex-col gap-4 w-full sm:w-[80%] text-gray-600"> | ||
{filteredVerses?.map((result, index) => ( | ||
<li | ||
key={index} | ||
className="p-4 bg-white rounded-xl shadow"> | ||
<p className="text-md font-semibold mb-2"><span className="text-siteColor font-bold">Verse:</span> 1 John {result[0]}</p> | ||
<p className="text-md font-semibold"><span className="text-siteColor font-bold">Similarity:</span> {result[1]}</p> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
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
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,9 +1,9 @@ | ||
import VerseSearch from "./components/VerseSearch"; | ||
|
||
export default function Home() { | ||
return ( | ||
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]"> | ||
Home page | ||
|
||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="min-h-screen"> | ||
<VerseSearch /> | ||
</div> | ||
); | ||
} |
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,4 @@ | ||
export interface VerseSimilarity { | ||
user_input: string; | ||
results: [string, number][]; | ||
} |
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
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
- namit2111 | ||
- justinhSE | ||
- lisamessier | ||
- rajatkriplani | ||
- d-beloved |