mirror of
https://github.com/okiba-org/frontend.git
synced 2025-02-22 17:22:01 +00:00
feat: add raw route and add functionality to bar buttons
This commit is contained in:
parent
c5bfc3dd35
commit
9e14ce8d6b
@ -1,5 +1,6 @@
|
|||||||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
||||||
import Home from "./pages/Home";
|
import Home from "./pages/Home";
|
||||||
|
import Raw from "./pages/Raw";
|
||||||
import Paste from "./pages/Paste";
|
import Paste from "./pages/Paste";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@ -15,6 +16,7 @@ function App() {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Home />} />
|
<Route path="/" element={<Home />} />
|
||||||
<Route path="/:id" element={<Paste />} />
|
<Route path="/:id" element={<Paste />} />
|
||||||
|
<Route path="/raw/:id" element={<Raw />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
const BottomBar = () => {
|
import { FunctionComponent } from "react";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
const BottomBar: FunctionComponent<propTypes> = props => {
|
||||||
return (
|
return (
|
||||||
<footer
|
<footer
|
||||||
style={{
|
style={{
|
||||||
@ -28,33 +31,48 @@ const BottomBar = () => {
|
|||||||
marginBottom: "2px",
|
marginBottom: "2px",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}>
|
}}>
|
||||||
<ButtonControl text="raw" link="/" />
|
{/* make component of these links some day */}
|
||||||
|
|
||||||
|
{props.isNewPaste ? (
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
onClick={async () => {
|
||||||
|
if (props.postCallback != undefined) {
|
||||||
|
await props.postCallback();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
style={linkStyle}>
|
||||||
|
<li style={listStyle}>save</li>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<a href={`/raw/${useParams().id}`} style={linkStyle}>
|
||||||
|
<li style={listStyle}>raw</li>
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
<Separator />
|
<Separator />
|
||||||
<ButtonControl text="save" link="/" />
|
<a href={"/"} style={linkStyle}>
|
||||||
|
<li style={listStyle}>new</li>
|
||||||
|
</a>
|
||||||
<Separator />
|
<Separator />
|
||||||
<ButtonControl text="source" link="/" />
|
<a
|
||||||
|
href={"https://github.com/okiba-org/"}
|
||||||
|
target="_blank"
|
||||||
|
style={linkStyle}>
|
||||||
|
<li style={listStyle}>source</li>
|
||||||
|
</a>
|
||||||
</ul>
|
</ul>
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ButtonControl = (props: tControlProps) => {
|
const linkStyle = {
|
||||||
return (
|
color: "white",
|
||||||
<a
|
};
|
||||||
href={props.link}
|
|
||||||
style={{
|
const listStyle = {
|
||||||
color: "white",
|
marginInline: "10px",
|
||||||
}}>
|
listStyle: "none",
|
||||||
<li
|
fontSize: "1rem",
|
||||||
style={{
|
|
||||||
marginInline: "10px",
|
|
||||||
listStyle: "none",
|
|
||||||
fontSize: "1rem",
|
|
||||||
}}>
|
|
||||||
{props.text}
|
|
||||||
</li>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Separator = () => (
|
const Separator = () => (
|
||||||
@ -67,9 +85,9 @@ const Separator = () => (
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
interface tControlProps {
|
interface propTypes {
|
||||||
text: string;
|
isNewPaste: boolean;
|
||||||
link: string;
|
postCallback: Function | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BottomBar;
|
export default BottomBar;
|
||||||
|
@ -28,7 +28,7 @@ function Home() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Editor setCode={setCode} value={code} keyEvent={handleSaveKey} />
|
<Editor setCode={setCode} value={code} keyEvent={handleSaveKey} />
|
||||||
<BottomBar />
|
<BottomBar isNewPaste={true} postCallback={postPaste} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ function Paste() {
|
|||||||
readonly={true}
|
readonly={true}
|
||||||
placeholder={""}
|
placeholder={""}
|
||||||
/>
|
/>
|
||||||
<BottomBar />
|
<BottomBar isNewPaste={false} postCallback={undefined} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
39
src/pages/Raw.tsx
Normal file
39
src/pages/Raw.tsx
Normal file
@ -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 (
|
||||||
|
<>
|
||||||
|
<pre>{code}</pre>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Raw;
|
Loading…
x
Reference in New Issue
Block a user