Fix text previews

This commit is contained in:
Kieran 2022-05-24 22:45:05 +01:00
parent ef5b00b16b
commit 56a4c52e24
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 13 additions and 3 deletions

View File

@ -3,4 +3,5 @@
padding: 10px;
border-radius: 10px;
text-align: initial;
overflow: auto;
}

View File

@ -5,15 +5,24 @@ export function TextPreview(props) {
let [content, setContent] = useState("Loading..");
async function getContent(link) {
let req = await fetch(link);
let req = await fetch(`${link}?t=${new Date().getTime()}`, {
headers: {
"pragma": "no-cache",
"cache-control": "no-cache"
}
});
if (req.ok) {
setContent(await req.text());
} else {
setContent("ERROR :(")
}
}
useEffect(() => {
getContent(props.link);
}, []);
if (props.link !== undefined && props.link !== "#") {
getContent(props.link);
}
}, [props.link]);
return (
<pre className="text-preview">{content}</pre>