From b27fc16ed244e6c790237abc792f8547f88e3140 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 16 Feb 2021 17:42:42 +0100 Subject: [PATCH] added errors and load state --- src/App.tsx | 32 ++++++++++++++++++++++++-------- src/style.css | 13 +++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bfff4e6..83e7e76 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -29,31 +29,35 @@ function App(props: Props) { const [content,setContent] = useState(""); const [title,setTitle] = useState(""); const [lang,setLang] = useState("text"); + const [appState,setAppState] = useState("loading"); useEffect(()=>{ (async ()=>{ + + if (!props.shareID){ + // No share defined + setAppState("noID"); + return + } + const response = await fetch(`/index.php/s/${props.shareID}/download`); if (response.status === 404){ // File not found - // TODO display error + setAppState("notFound"); return; } - const contentLength = parseInt(response.headers.get("content-length")!,10); const filename = parseFilename(response.headers); setTitle(filename); document.title = filename; setLang(getLangFromFilename(filename) || "text") - if (contentLength <= 20000) { - const text = await response.text() - setContent(text); + const text = await response.text() + setContent(text); + setAppState("done"); - }else{ - // TODO display error - } })() },[props.shareID]) @@ -61,6 +65,18 @@ function App(props: Props) { window.open(`/index.php/s/${props.shareID}/download`, "_self"); } + // Handle error/loading cases + switch (appState) { + case "loading": + return
; + case "notFound": + return
404
+ case "noID": + return
NO ID PROVIDED
+ default: + break; + } + return (
diff --git a/src/style.css b/src/style.css index 9b0e0db..5e65c1a 100644 --- a/src/style.css +++ b/src/style.css @@ -51,6 +51,19 @@ color: #50545b !important; } +.error { + /*Center element*/ + margin: 0; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%,-50%); + + font-size: 5rem; + font-family: sans-serif; + color: #58a6ff; +} + body { background-color: #0d1117; }