Fix review findings

This commit is contained in:
Florian Scholdei
2020-10-20 10:18:44 +02:00
parent ed4a564677
commit 27d4b0a755
4 changed files with 44 additions and 86 deletions

View File

@@ -37,32 +37,25 @@ const SourcecodeViewer: FC<Props> = ({ file, language }) => {
const [currentFileRevision, setCurrentFileRevision] = useState("");
useEffect(() => {
function fetchContent() {
if (file.revision !== currentFileRevision) {
getContent((file._links.self as Link).href)
.then(content => {
setLoading(false);
setContent(content);
setCurrentFileRevision(file.revision);
})
.catch(error => {
setLoading(false);
setError(error);
});
})
.catch(setError);
}
if (file.revision !== currentFileRevision) {
fetchContent();
}
});
if (loading) {
return <Loading />;
}
}, [currentFileRevision, file]);
if (error) {
return <ErrorNotification error={error} />;
}
if (loading) {
return <Loading />;
}
if (!content) {
return null;
}