From 9e14ce8d6bc719cc227d7f1d61e69e69ee98762a Mon Sep 17 00:00:00 2001 From: alok8bb Date: Fri, 15 Jul 2022 13:05:07 +0530 Subject: [PATCH] feat: add raw route and add functionality to bar buttons --- src/App.tsx | 2 ++ src/components/BottomBar.tsx | 66 +++++++++++++++++++++++------------- src/pages/Home.tsx | 2 +- src/pages/Paste.tsx | 2 +- src/pages/Raw.tsx | 39 +++++++++++++++++++++ 5 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 src/pages/Raw.tsx diff --git a/src/App.tsx b/src/App.tsx index f9c9bd8..8b37499 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import Home from "./pages/Home"; +import Raw from "./pages/Raw"; import Paste from "./pages/Paste"; function App() { @@ -15,6 +16,7 @@ function App() { } /> } /> + } /> diff --git a/src/components/BottomBar.tsx b/src/components/BottomBar.tsx index 0d572ba..b892c91 100644 --- a/src/components/BottomBar.tsx +++ b/src/components/BottomBar.tsx @@ -1,4 +1,7 @@ -const BottomBar = () => { +import { FunctionComponent } from "react"; +import { useParams } from "react-router-dom"; + +const BottomBar: FunctionComponent = props => { return ( ); }; -const ButtonControl = (props: tControlProps) => { - return ( - -
  • - {props.text} -
  • -
    - ); +const linkStyle = { + color: "white", +}; + +const listStyle = { + marginInline: "10px", + listStyle: "none", + fontSize: "1rem", }; const Separator = () => ( @@ -67,9 +85,9 @@ const Separator = () => ( ); -interface tControlProps { - text: string; - link: string; +interface propTypes { + isNewPaste: boolean; + postCallback: Function | undefined; } export default BottomBar; diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index fab0218..a429e86 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -28,7 +28,7 @@ function Home() { return ( <> - + ); } diff --git a/src/pages/Paste.tsx b/src/pages/Paste.tsx index 887c066..234c546 100644 --- a/src/pages/Paste.tsx +++ b/src/pages/Paste.tsx @@ -41,7 +41,7 @@ function Paste() { readonly={true} placeholder={""} /> - + ); } diff --git a/src/pages/Raw.tsx b/src/pages/Raw.tsx new file mode 100644 index 0000000..424ec1d --- /dev/null +++ b/src/pages/Raw.tsx @@ -0,0 +1,39 @@ +import { useEffect, useState } from "react"; +import { useNavigate, useParams } from "react-router-dom"; +import { getPaste } from "../api/bin"; + +const Raw = () => { + let navigate = useNavigate(); + let [code, setCode] = useState(""); + let { id } = useParams(); + + const getCode = async () => { + if (id == undefined) { + alert("Something went wrong!"); + return navigate("/"); + } + + const res: Response = await getPaste(id); + + if (res.status == 404) { + alert("Paste not found!"); + navigate("/"); + } + + if (res.status == 200) { + setCode(await res.text()); + } + }; + + useEffect(() => { + getCode(); + }, []); + + return ( + <> +
    {code}
    + + ); +}; + +export default Raw;