Skip to content

Commit

Permalink
Fix: Preview navigation hook (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyajeet authored Mar 10, 2018
1 parent c93c045 commit 00096b7
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 233 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,27 @@
"regenerator-runtime": "^0.11.1",
"sass-lint": "^1.12.1",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.2",
"style-loader": "^0.20.3",
"stylelint": "^9.1.1",
"stylelint-config-standard": "^18.2.0",
"stylelint-order": "^0.8.1",
"uglifyjs-webpack-plugin": "^1.2.2",
"webpack": "^4.1.1",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0",
"worker-farm": "^1.5.4"
"webpack-cli": "^2.0.11",
"webpack-dev-server": "^3.1.1",
"worker-farm": "^1.6.0"
},
"peerDependencies": {
"axios": "^0.18.0",
"box-react-ui": "^22.4.9",
"box-react-ui": "^22.5.0",
"classnames": "^2.2.5",
"filesize": "^3.6.0",
"jsuri": "^1.3.1",
"lodash": "^4.17.5",
"randomcolor": "^0.5.3",
"react": "^15.6.0 || ^16.0.0",
"react-dom": "^15.6.0 || ^16.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-intl": "^2.3.0",
"react-measure": "^2.0.2",
"react-modal": "^3.3.1",
Expand Down
9 changes: 5 additions & 4 deletions src/components/ContentPreview/ContentPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class ContentPreview extends PureComponent<Props, State> {
*/
loadPreview = (): void => {
const { Preview } = global.Box;
const { fileId, token, onLoad, onNavigate, collection, ...rest }: Props = this.props;
const { fileId, token, collection, ...rest }: Props = this.props;
const { file }: State = this.state;

if (!this.isPreviewLibraryLoaded() || !file || !token) {
Expand All @@ -373,7 +373,6 @@ class ContentPreview extends PureComponent<Props, State> {
if (!this.preview) {
this.preview = new Preview();
this.preview.addListener('load', this.onPreviewLoad);
this.preview.addListener('navigate', onNavigate);
}

if (this.preview.getCurrentViewer()) {
Expand Down Expand Up @@ -509,15 +508,17 @@ class ContentPreview extends PureComponent<Props, State> {
* @return {void}
*/
navigateToIndex(index) {
const { collection }: Props = this.props;
const { collection, onNavigate }: Props = this.props;
const { length } = collection;
if (length < 2 || index < 0 || index > length - 1) {
return;
}

const fileOrId = collection[index];
const fileId = typeof fileOrId === 'object' ? fileOrId.id || '' : fileOrId;
onNavigate(fileId);
this.destroyPreview();
this.fetchFile(typeof fileOrId === 'object' ? fileOrId.id || '' : fileOrId);
this.fetchFile(fileId);
}

/**
Expand Down
Loading

0 comments on commit 00096b7

Please sign in to comment.