-
Notifications
You must be signed in to change notification settings - Fork 36
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 #37 from YadlaMani/main
updated main page
- Loading branch information
Showing
4 changed files
with
115 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,92 @@ | ||
"use client" | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import Snackbar from "./Snackbar"; | ||
|
||
|
||
|
||
|
||
export default function Form() { | ||
const [url, seturl] = useState<string>(""); | ||
const [load,setload] = useState(false); | ||
const [err,seterr] = useState<any>(null); | ||
const update = (e: any) => { | ||
seturl(e.target.value); | ||
const [url, seturl] = useState<string>(""); | ||
const [load, setload] = useState(false); | ||
const [err, seterr] = useState<any>(null); | ||
const update = (e: any) => { | ||
seturl(e.target.value); | ||
}; | ||
|
||
const send = async () => { | ||
setload(true); | ||
if (err) { | ||
setload(false); | ||
return; | ||
} | ||
|
||
const send = async () => { | ||
setload(true); | ||
if(err){ | ||
setload(false); | ||
return; | ||
try { | ||
const response = await fetch( | ||
process.env.NEXT_PUBLIC_APP || "http://localhost:3000/api", | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ url }), | ||
} | ||
|
||
try { | ||
const response = await fetch(process.env.NEXT_PUBLIC_APP||"http://localhost:3000/api", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ url }) | ||
}); | ||
|
||
); | ||
|
||
|
||
console.log("Request sent successfully!"); | ||
const data = await response.json(); | ||
if(data.extractedText){ | ||
const blob = new Blob([data.extractedText], { type: 'text/plain' }); | ||
const url2 = window.URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url2; | ||
a.download = "data.txt"; | ||
document.body.appendChild(a); | ||
a.click(); | ||
window.URL.revokeObjectURL(url2); | ||
} | ||
else{ | ||
if(data.urlerror){ | ||
seterr(data.urlerror); | ||
} | ||
else{ | ||
seterr("URL cannot be loaded"); | ||
} | ||
|
||
setTimeout(() => { | ||
seterr(null); | ||
}, 3000); | ||
} | ||
setload(false); | ||
|
||
|
||
} catch (error: any) { | ||
console.error("Error:", error.message); | ||
seterr("Vercel timeout error. Please setup project locally"); | ||
setTimeout(() => { | ||
seterr(null); | ||
}, 3000); | ||
setload(false); | ||
console.log("Request sent successfully!"); | ||
const data = await response.json(); | ||
if (data.extractedText) { | ||
const blob = new Blob([data.extractedText], { type: "text/plain" }); | ||
const url2 = window.URL.createObjectURL(blob); | ||
const a = document.createElement("a"); | ||
a.href = url2; | ||
a.download = "data.txt"; | ||
document.body.appendChild(a); | ||
a.click(); | ||
window.URL.revokeObjectURL(url2); | ||
} else { | ||
if (data.urlerror) { | ||
seterr(data.urlerror); | ||
} else { | ||
seterr("URL cannot be loaded"); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
seterr(null); | ||
}, 3000); | ||
} | ||
setload(false); | ||
} catch (error: any) { | ||
console.error("Error:", error.message); | ||
seterr("Vercel timeout error. Please setup project locally"); | ||
setTimeout(() => { | ||
seterr(null); | ||
}, 3000); | ||
setload(false); | ||
} | ||
}; | ||
|
||
return <> | ||
<div className="mb-6"> | ||
<label className="block mb-2 text-sm font-medium text-green-700 dark:text-green-500">Type a website url</label> | ||
<input onChange={update} type="text" id="success" className="bg-green-50 border border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5 dark:bg-gray-700 dark:border-green-500 mb-5" placeholder="https://www.example.com" /> | ||
return ( | ||
<> | ||
<div className="mb-6"> | ||
<label className="block mb-2 text-sm font-medium text-white dark:text-white"> | ||
Type a website url | ||
</label> | ||
<input | ||
onChange={update} | ||
type="text" | ||
id="success" | ||
className="bg-green-50 border border-blue-500 text-blue-900 dark:text-blue-400 placeholder-black-700 dark:placeholder-black-500 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-blue-500 mb-5" | ||
placeholder="https://www.example.com" | ||
/> | ||
|
||
<button onClick={send} type="button" className="block text-white bg-gradient-to-r from-cyan-500 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-cyan-300 dark:focus:ring-cyan-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mx-auto">{load ? "Downloading...": "Download now"}</button> | ||
|
||
{ err && <Snackbar state={err} setstate={seterr}/>} | ||
<button | ||
onClick={send} | ||
type="button" | ||
className="block text-white bg-gradient-to-r from-cyan-500 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-cyan-300 dark:focus:ring-cyan-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mx-auto" | ||
> | ||
{load ? "Downloading..." : "Download now"} | ||
</button> | ||
|
||
</div> | ||
{err && <Snackbar state={err} setstate={seterr} />} | ||
</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,22 +1,29 @@ | ||
|
||
import Link from "next/link"; | ||
import { Navbar, NavbarBrand, NavbarCollapse, NavbarLink, NavbarToggle } from "flowbite-react"; | ||
import { | ||
Navbar, | ||
NavbarBrand, | ||
NavbarCollapse, | ||
NavbarLink, | ||
NavbarToggle, | ||
} from "flowbite-react"; | ||
import Social from "./Social"; | ||
|
||
export function Nav() { | ||
return ( | ||
<Navbar fluid rounded className="bg-transparent shadow-md max-w-screen-2xl m-auto"> | ||
|
||
|
||
<NavbarBrand as={Link} href="/" className="pl-9"> | ||
<span className="self-center whitespace-nowrap text-2xl font-semibold dark:text-white">ScrapQuest</span> | ||
</NavbarBrand> | ||
<NavbarToggle /> | ||
<NavbarCollapse> | ||
|
||
<Social/> | ||
</NavbarCollapse> | ||
|
||
</Navbar> | ||
); | ||
return ( | ||
<Navbar | ||
fluid | ||
rounded | ||
className="bg-gradient-to-r from-blue-500 shadow-md max-w-screen-2xl m-auto" | ||
> | ||
<NavbarBrand as={Link} href="/" className="pl-9"> | ||
<span className="self-center whitespace-nowrap text-2xl font-semibold dark:text-white"> | ||
ScrapQuest | ||
</span> | ||
</NavbarBrand> | ||
<NavbarToggle /> | ||
<NavbarCollapse> | ||
<Social /> | ||
</NavbarCollapse> | ||
</Navbar> | ||
); | ||
} |