Skip to content

Commit

Permalink
give lodash map an alias and rename conversionActive variable in view…
Browse files Browse the repository at this point in the history
…er state
  • Loading branch information
interim17 committed Dec 28, 2024
1 parent 20ec0c9 commit 13555ef
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions examples/src/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { map, isEqual, findIndex, reduce } from "lodash";
import { isEqual, findIndex, reduce, map as lodashMap } from "lodash";
import { v4 as uuidv4 } from "uuid";
import { InputParams } from "tweakpane";

Expand Down Expand Up @@ -87,7 +87,7 @@ interface ViewerState {
initialPlay: boolean;
firstFrameTime: number;
followObjectData: AgentData;
convertingFile: boolean;
conversionActive: boolean;
conversionFileName: string;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ const initialState: ViewerState = {
initialPlay: true,
firstFrameTime: 0,
followObjectData: nullAgent(),
convertingFile: false,
conversionActive: false,
conversionFileName: "",
};

Expand Down Expand Up @@ -288,7 +288,7 @@ class Viewer extends React.Component<InputParams, ViewerState> {
.then((data) => data.json())
.then((fileRefs) =>
Promise.all(
map(fileRefs, (ref) =>
lodashMap(fileRefs, (ref) =>
fetch(ref.download_url).then((data) => data.json())
)
)
Expand Down Expand Up @@ -337,7 +337,11 @@ class Viewer extends React.Component<InputParams, ViewerState> {

public convertFile(obj: Record<string, any>, fileType: TrajectoryType) {
const fileName = uuidv4() + ".simularium";
this.setState({ convertingFile: true, conversionFileName: fileName });
this.setState({
conversionActive: true,
conversionFileName: fileName,
});

simulariumController
.convertTrajectory(
this.netConnectionSettings,
Expand Down Expand Up @@ -428,26 +432,32 @@ class Viewer extends React.Component<InputParams, ViewerState> {
});
}

public receiveConvertedFile(data: TrajectoryFileInfo): void {
public receiveConvertedFile(): void {
simulariumController
.changeFile(
{ netConnectionSettings: this.netConnectionSettings },
this.state.conversionFileName,
true
{
netConnectionSettings: this.netConnectionSettings,
},
this.state.conversionFileName
)
.then(() => {
simulariumController.gotoTime(0);
})
.then(() => this.setState({ convertingFile: false }))
.then(() =>
this.setState({
conversionActive: false,
conversionFileName: "",
})
)
.catch((e) => {
console.warn(e);
});
}

public handleTrajectoryInfo(data: TrajectoryFileInfo): void {
console.log("Trajectory info arrived", data);
if (this.state.convertingFile === true) {
this.receiveConvertedFile(data);
if (this.state.conversionActive === true) {
this.receiveConvertedFile();
}
// NOTE: Currently incorrectly assumes initial time of 0
const totalDuration = (data.totalSteps - 1) * data.timeStepSize;
Expand Down

0 comments on commit 13555ef

Please sign in to comment.