From fd3e3280a2590be9ca074a172c535990a5035649 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Mon, 26 Dec 2022 00:11:58 -0500 Subject: Add a proxy option for static assets. Fix the paste view handlers. --- paste-ui/src/view.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 paste-ui/src/view.js (limited to 'paste-ui/src/view.js') diff --git a/paste-ui/src/view.js b/paste-ui/src/view.js new file mode 100644 index 0000000..e3bf0df --- /dev/null +++ b/paste-ui/src/view.js @@ -0,0 +1,54 @@ +import { useState } from "react"; +import { useEffect } from "react"; + + +export default function View(props) { + const [error, setError] = useState(null); + const [isLoaded, setIsLoaded] = useState(false); + const [item, setItems] = useState([]); + + // Note: the empty deps array [] means + // this useEffect will run once + // similar to componentDidMount() + useEffect(() => { + fetch("http://localhost:6130/api/v1/view/" + props.id) + .then(res => res.json()) + .then( + (result) => { + setIsLoaded(true); + setItems(result); + }, + // Note: it's important to handle errors here + // instead of a catch() block so that we don't swallow + // exceptions from actual bugs in components. + (error) => { + setIsLoaded(true); + setError(error); + } + ) + }, []) + + if (error) { + return
Error: {error.message}
; + } else if (!isLoaded) { + return
Loading...
; + } else { + if ('Code' in item && item.Code != 200) { + return ( +

+ Error: {item.Code} {item.Msg} +

+ ); + } + return ( +
+

ID: {props.id}

+
+                
+                    {item.Content}
+                
+            
+
+ ); + } +} \ No newline at end of file -- cgit v1.2.3