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

fix loading from url, was still assuming pure json format #345

Merged
merged 1 commit into from
May 26, 2022
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
20 changes: 14 additions & 6 deletions src/state/trajectory/logics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { batch } from "react-redux";
import { createLogic } from "redux-logic";
import { ArgumentAction } from "redux-logic/definitions/action";
import queryString from "query-string";
import { ErrorLevel, FrontEndError } from "@aics/simularium-viewer";
import {
ErrorLevel,
FrontEndError,
loadSimulariumFile,
} from "@aics/simularium-viewer";

import { URL_PARAM_KEY_FILE_NAME } from "../../constants";
import { clearUrlParams } from "../../util";
Expand Down Expand Up @@ -174,8 +178,9 @@ const loadNetworkedFile = createLogic({
.then(() => {
return dispatch(
requestCachedPlotData({
url: `${simulariumFile.name.split(".")[0]
}/plot-data.json`, // placeholder for however we organize this data in s3
url: `${
simulariumFile.name.split(".")[0]
}/plot-data.json`, // placeholder for however we organize this data in s3
})
);
})
Expand Down Expand Up @@ -272,18 +277,21 @@ const loadFileViaUrl = createLogic({
fetch(url)
.then((response) => {
if (response.ok) {
return response.json();
return response.blob();
} else {
// If there's a CORS error, this line of code is not reached because there is no response
throw new Error(`Failed to fetch - ${response.status}`);
}
})
.then((json) => {
.then((blob) => {
return loadSimulariumFile(blob);
})
.then((simulariumFile) => {
dispatch(
changeToLocalSimulariumFile(
{
name: action.fileId, //TODO: add this to metadata about the file
data: json,
data: simulariumFile,
// Temp solution: Set lastModified to a date in the future to tell this apart
// from legitimate lastModified values
lastModified: Date.now() + 600000, //TODO: add this to metadata about the file
Expand Down