Skip to content

Commit

Permalink
fix url imports by ensuring that fileJson state variable is always …
Browse files Browse the repository at this point in the history
…json
  • Loading branch information
edchapman88 committed Jan 26, 2024
1 parent 7457b6c commit 641fbaf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions frontend/src/components/CaseImporterFlow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function CaseImporterFlow({ titleId, onClose }) {
if (svgElement && svgElement.hasAttribute("data-metadata")) {
const metadataStr = svgElement.getAttribute("data-metadata");
try {
return JSON.parse(decodeFromHtml(metadataStr));
return JSON.parse(JSON.parse(decodeFromHtml(metadataStr)));
} catch (err) {
console.error("Error parsing metadata:", err);
}
Expand Down Expand Up @@ -76,14 +76,14 @@ function CaseImporterFlow({ titleId, onClose }) {
);

const postCaseJSON = useCallback(
(json_str) => {
(json) => {
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Token ${token}`,
},
body: json_str,
body: JSON.stringify(json),
};

setLoading(true);
Expand Down Expand Up @@ -123,7 +123,7 @@ function CaseImporterFlow({ titleId, onClose }) {
if (uploadType === "url") {
getUrlContent(url).then((json) => {
if (json) {
postCaseJSON(JSON.stringify(json));
postCaseJSON(json);
}
});
} else {
Expand Down Expand Up @@ -160,7 +160,7 @@ function CaseImporterFlow({ titleId, onClose }) {
const metadataStr = svgElement.getAttribute("data-metadata");
try {
const metadataJSON = JSON.parse(metadataStr);
setFileJson(metadataJSON);
setFileJson(JSON.parse(metadataJSON));
} catch (err) {
// TODO error could be better
setFileError("File is not a valid SVG");
Expand Down

0 comments on commit 641fbaf

Please sign in to comment.