Skip to content

Commit

Permalink
Only re-generate graph if uploaded CALM instance json file has changed (
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivia Johnson committed Nov 7, 2024
1 parent 257477c commit a9cf638
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions calm-visualizer/src/components/fileuploader/FileUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

interface Props {
callback: (instanceFile: File, layoutFile?: File) => void
Expand All @@ -7,10 +7,16 @@ interface Props {
function FileUploader({ callback }: Props) {
const [instanceFile, setInstanceFile] = useState<File | null>(null);
const [layoutFile, setLayoutFile] = useState<File | null>(null);
const [filesChanged, setFilesChanged] = useState(false);

useEffect(() => {
setFilesChanged(true);
}, [instanceFile, layoutFile]);

const handleSubmit = () => {
if (instanceFile) {
if (instanceFile && filesChanged) {
callback(instanceFile, layoutFile || undefined);
setFilesChanged(false);
}
};

Expand All @@ -34,6 +40,7 @@ function FileUploader({ callback }: Props) {
{instanceFile && (
<button
onClick={handleSubmit}
disabled={!filesChanged}
className="submit"
>Upload a file</button>
)}
Expand Down

0 comments on commit a9cf638

Please sign in to comment.