Skip to content

Commit

Permalink
Merge pull request #37 from YadlaMani/main
Browse files Browse the repository at this point in the history
updated main page
  • Loading branch information
Abidsyed25 authored May 27, 2024
2 parents 130a7ba + 64febcc commit ac68175
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 107 deletions.
7 changes: 3 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import Image from "next/image";

export default function Home() {
return (
<div style={{height:"100vh"}}>

<Nav/>
<Hero/>
<div className="bg-gray-950" style={{ height: "100vh" }}>
<Nav />
<Hero />
</div>
);
}
146 changes: 77 additions & 69 deletions components/Form.tsx
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>
</>
}
);
}
28 changes: 11 additions & 17 deletions components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ import { Blockquote } from "flowbite-react";
import Form from "./Form";
import Snackbar from "./Snackbar";


export default function Hero() {
return <>


<div className="h-5/6 flex flex-col justify-center items-center">
<div>


<Blockquote className="text-center my-10">
Unlock insights from the web with our powerful web scraper
</Blockquote>
<Form/>
</div>
return (
<>
<div className="h-5/6 flex flex-col justify-center items-center">
<div>
<Blockquote className=" text-blue-500 text-center my-10">
Unlock insights from the web with our powerful web scraper
</Blockquote>
<Form />
</div>



</div>
</>
}
);
}
41 changes: 24 additions & 17 deletions components/Nav.tsx
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>
);
}

0 comments on commit ac68175

Please sign in to comment.