Compare commits

..

1 commit

8 changed files with 63 additions and 96 deletions

View file

@ -7,7 +7,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = "shortenit" project = "shortenit"
copyright = "2025, Elia el Lazkani" copyright = "2024, Elia el Lazkani"
author = "Elia el Lazkani" author = "Elia el Lazkani"
release = "0.0.0" release = "0.0.0"

View file

@ -1,11 +1,11 @@
{ {
"name": "shortenit", "name": "frontend",
"version": "0.1.0", "version": "0.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "shortenit", "name": "frontend",
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",

View file

@ -35,66 +35,23 @@ export default function URLShortener() {
const api_url = `${config.url}${api_endpoint}`; const api_url = `${config.url}${api_endpoint}`;
// Send the POST request to the backend // Send the POST request to the backend
const response = await axios.post(api_url , {url: url}) await axios
if (response.data.url) { .post(api_url , {
url: url
})
.then((response) => {
if (response) {
const shortUrl: string = response.data.url; const shortUrl: string = response.data.url;
setShortenedUrl(shortUrl); setShortenedUrl(shortUrl);
setShowInput(true); setShowInput(true);
toast.success("URL Shortened Successfully", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
className: "custom-toast",
});
} else {
toast.error("Something went wrong while shortening the URL", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
className: "custom-toast",
});
} }
});
setTimeout(() => { setTimeout(() => {
setShowInput(false); setShowInput(false);
}, 900000); }, 10000);
} catch (error : any) { } catch (error) {
if (error.response) { console.log(error);
const errorMessage : string = error.response.data.msg || "An error occurred. Please try again.";
toast.error(errorMessage, {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
className: "custom-toast",
});
} else {
toast.error("Network error. Please check your connection and try again.", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
className: "custom-toast",
});
}
} }
} }
@ -119,14 +76,13 @@ export default function URLShortener() {
} }
} }
return ( return (
<>
<div className="URLShortener-component"> <div className="URLShortener-component">
<div className="left-side"> <div className="left-side">
<h1>Paste the URL</h1> <h1>Paste the URL</h1>
<form className="url-input" onSubmit={ShortenIt}> <form className="url-input" onSubmit={ShortenIt}>
<input <input
type="text" type="text"
placeholder="https://www.example.com" placeholder="www.example.com"
aria-label="URL input field" aria-label="URL input field"
value={url} value={url}
onChange={(e) => setUrl(e.target.value)} onChange={(e) => setUrl(e.target.value)}
@ -152,9 +108,7 @@ export default function URLShortener() {
</p> </p>
</div> </div>
</div> </div>
</div>
<ToastContainer /> <ToastContainer />
</> </div>
); );
} }

View file

@ -1,8 +1,5 @@
.footer { .footer {
width: 100%; width: 100%;
height: 100px; height: 200px;
background-color: var(--color-secondary); background-color: var(--color-secondary);
display: flex;
justify-content: center;
align-items: center;
} }

View file

@ -0,0 +1,13 @@
import React from "react";
import { QRCodeSVG } from "qrcode.react";
import { qrCodeGeneratorProps } from "./qrCodeGeneratorProps";
const QRCodeGenerator: React.FC<qrCodeGeneratorProps> = ({ url }) => {
return (
<div>
<QRCodeSVG id="qrCodeSVG" value={url} />
</div>
);
};
export default QRCodeGenerator;

View file

@ -0,0 +1,3 @@
export interface qrCodeGeneratorProps {
url: string;
}

View file

@ -80,7 +80,7 @@ class SiteHandler:
data = self.shortenit_load_format(data) data = self.shortenit_load_format(data)
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
return {"msg" : "Invalid URL format"}, 400 return {}, 400
self.logger.error(e) self.logger.error(e)
abort(400) abort(400)
try: try: