|
1 | 1 | // src/App.js |
2 | | -import ReactDOM from "react-dom"; |
3 | 2 | import React from "react"; |
| 3 | +import { createRoot } from "react-dom/client"; |
4 | 4 | import Map from "./Map"; |
5 | 5 | import Dataframe from "./Dataframe"; |
6 | 6 | import TimeSlider from "./TimeSlider"; |
@@ -410,7 +410,9 @@ class App extends React.Component { |
410 | 410 | checkForDemoFile = async () => { |
411 | 411 | try { |
412 | 412 | const response = await fetch("./data.json"); |
413 | | - if (!response.ok) { |
| 413 | + const contentType = response.headers.get("content-type"); |
| 414 | + |
| 415 | + if (!response.ok || !contentType || !contentType.includes("application/json")) { |
414 | 416 | return; |
415 | 417 | } |
416 | 418 | console.log("data.json demo file found on the server root, saving it to Dataset 1"); |
@@ -455,15 +457,19 @@ class App extends React.Component { |
455 | 457 | return { status: null, index }; |
456 | 458 | }) |
457 | 459 | ); |
458 | | - this.setState({ |
459 | | - uploadedDatasets: newUploadedDatasets.map((d) => d.status), |
460 | | - }); |
461 | | - if (this.state.activeDatasetIndex === null) { |
462 | | - const firstAvailableIndex = newUploadedDatasets.find((dataset) => dataset.status === "Uploaded")?.index; |
463 | | - if (firstAvailableIndex !== undefined) { |
464 | | - this.switchDataset(firstAvailableIndex); |
| 460 | + this.setState( |
| 461 | + { |
| 462 | + uploadedDatasets: newUploadedDatasets.map((d) => d.status), |
| 463 | + }, |
| 464 | + () => { |
| 465 | + if (this.state.activeDatasetIndex === null) { |
| 466 | + const firstAvailableIndex = newUploadedDatasets.find((dataset) => dataset.status === "Uploaded")?.index; |
| 467 | + if (firstAvailableIndex !== undefined) { |
| 468 | + this.switchDataset(firstAvailableIndex); |
| 469 | + } |
| 470 | + } |
465 | 471 | } |
466 | | - } |
| 472 | + ); |
467 | 473 | }; |
468 | 474 |
|
469 | 475 | handleLongPress = async (index) => { |
@@ -723,43 +729,45 @@ class App extends React.Component { |
723 | 729 | dialog.className = "cloud-logging-dialog"; |
724 | 730 |
|
725 | 731 | document.body.appendChild(dialog); |
| 732 | + const dialogRootElement = document.createElement("div"); |
| 733 | + dialog.appendChild(dialogRootElement); |
| 734 | + const dialogRoot = createRoot(dialogRootElement); |
726 | 735 | dialog.showModal(); |
727 | 736 | return new Promise((resolve) => { |
| 737 | + const cleanupAndResolve = (result) => { |
| 738 | + dialogRoot.unmount(); |
| 739 | + dialog.remove(); |
| 740 | + resolve(result); |
| 741 | + }; |
728 | 742 | const handleError = (error) => { |
729 | 743 | console.error("Cloud Logging Error:", error); |
730 | 744 | toast.error(error.message || "Failed to fetch logs. Please try again."); |
731 | | - dialog.remove(); |
732 | | - resolve(null); |
| 745 | + cleanupAndResolve(null); |
733 | 746 | }; |
734 | 747 |
|
735 | 748 | const handleFileUpload = (event) => { |
736 | | - log("File upload selected from Cloud Logging dialog"); |
| 749 | + console.log("File upload selected from Cloud Logging dialog"); |
737 | 750 | const file = event?.target?.files?.[0]; |
738 | 751 | if (file) { |
739 | | - dialog.remove(); |
740 | | - resolve({ file }); |
| 752 | + cleanupAndResolve({ file }); |
741 | 753 | } |
742 | 754 | }; |
743 | 755 |
|
744 | | - // Using direct DOM manipulation instead of ReactDOM.render to avoid React 17 issues |
745 | | - const root = document.createElement("div"); |
746 | | - dialog.appendChild(root); |
747 | | - |
748 | | - const cloudLogging = React.createElement(CloudLogging, { |
| 756 | + const cloudLoggingComponent = React.createElement(CloudLogging, { |
749 | 757 | onLogsReceived: (logs) => { |
750 | 758 | log(`Received ${logs.length} logs from Cloud Logging`); |
751 | | - dialog.remove(); |
752 | 759 | if (logs.length === 0) { |
753 | 760 | toast.warning("No logs found matching your criteria."); |
754 | | - resolve(null); |
| 761 | + cleanupAndResolve(null); |
755 | 762 | } else { |
756 | 763 | resolve({ logs }); |
| 764 | + cleanupAndResolve({ logs }); |
757 | 765 | } |
758 | 766 | }, |
759 | 767 | onFileUpload: handleFileUpload, |
760 | 768 | setError: handleError, |
761 | 769 | }); |
762 | | - ReactDOM.render(cloudLogging, root); |
| 770 | + dialogRoot.render(cloudLoggingComponent); |
763 | 771 | }); |
764 | 772 | } |
765 | 773 |
|
|
0 commit comments