Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: file fetching logic in LiveHtmlEditor component #29

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading