Skip to content

Commit

Permalink
fix: update viewer func
Browse files Browse the repository at this point in the history
  • Loading branch information
akuokojnr committed Apr 21, 2021
1 parent c9dd8ab commit 10accef
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions components/core/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,29 +221,38 @@ export default class ApplicationPage extends React.Component {
viewer: { ...this.state.viewer, ...newViewerState, type: "VIEWER" },
data,
});

return;
}
}

// NOTE(daniel): update optimistic files with upload data
let oldViewerState = this.state.viewer;
let oldLibrary = oldViewerState.library;
if (newViewerState.library?.length) {
let oldViewerState = this.state.viewer;
let oldLibrary = oldViewerState.library;

let update = newViewerState.library[0].children.map((child) => {
let optimisticFileIndex = oldLibrary[0].children.findIndex(
(item) => item.id === child.id && item.decorator.startsWith("OPTMISTIC")
);
if (optimisticFileIndex > -1) {
return { ...oldLibrary[0].children[optimisticFileIndex], ...child };
}

let update = newViewerState.library[0].children.map((child) => {
let optimisticFileIndex = oldLibrary[0].children.findIndex(
(item) => item.id === child.id && item.decorator.startsWith("OPTMISTIC")
);
if (optimisticFileIndex > -1) {
return { ...oldLibrary[0].children[optimisticFileIndex], ...child };
}
return child;
});

return child;
});
oldViewerState.library[0].children = update;

this.setState({
viewer: { ...oldViewerState, ...newViewerState, type: "VIEWER" },
});

oldViewerState.library[0].children = update;
return;
}

this.setState({
viewer: { ...oldViewerState, ...newViewerState, type: "VIEWER" },
viewer: { ...this.state.viewer, ...newViewerState, type: "VIEWER" },
});
};

Expand Down Expand Up @@ -356,7 +365,7 @@ export default class ApplicationPage extends React.Component {
return null;
}

files = await this._handleOptimisticUpload({ files });
files = await this._handleOptimisticUpload({ files, slate });

const resolvedFiles = [];
for (let i = 0; i < files.length; i++) {
Expand Down Expand Up @@ -464,7 +473,7 @@ export default class ApplicationPage extends React.Component {
this.setState({ optimisticFiles });

let update = [...optimisticFiles, ...this.state.viewer?.library[0].children];
let library = this.props.viewer.library;
let library = this.props.viewer?.library;
library[0].children = update;
this._handleUpdateViewer({ library });

Expand Down

0 comments on commit 10accef

Please sign in to comment.