Skip to content

Commit

Permalink
refactor: file fetching logic in LiveHtmlEditor component
Browse files Browse the repository at this point in the history
  • Loading branch information
albertkun committed Dec 15, 2023
1 parent be4033b commit 6530efb
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/components/LiveHtmlEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ export default function LiveHtmlEditor({ fileUrl }) {
setCode(text);
setLoading(false);
} else if (response.status === 404) {
// Remove the last directory from the url
const directoryUrl = url.substring(0, url.lastIndexOf('/'));

// Recursively try to fetch the file from the parent directory
fetchFile(`${directoryUrl}/${filename}`);
// Try to fetch the file from the root of the examples directory
fetchFile(`/examples/${filename}`);
} else {
throw new Error(`HTTP error! status: ${response.status}`);
}
Expand All @@ -38,14 +35,6 @@ export default function LiveHtmlEditor({ fileUrl }) {
setLoading(false);
});
}, [fileUrl, fetchFile]);

useEffect(() => {
fetchFile(fileUrl).catch(error => {
setError(error.message);
setLoading(false);
});
}, [fileUrl, fetchFile]);


if (loading) {
return <div>Loading...</div>;
Expand Down

0 comments on commit 6530efb

Please sign in to comment.