diff --git a/.eslintrc b/.eslintrc index fa3aca98..2312f48f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "es6": true }, "rules": { + "new-cap": [2, {newIsCap: true, capIsNew: false}], "quotes": [2, "single"], "eol-last": [0], "no-mixed-requires": [0], @@ -34,7 +35,8 @@ "globals": { "Intercom": true, "fetch": true, - "require": true + "require": true, + "File": true }, "plugins": [ "react" diff --git a/index.html b/index.html index 1b5c26a2..743d01dc 100644 --- a/index.html +++ b/index.html @@ -51,8 +51,6 @@ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - - ga('create', 'UA-60614729-2', 'auto'); diff --git a/js/actions/coa_actions.js b/js/actions/coa_actions.js index 9af2841c..7c6f5118 100644 --- a/js/actions/coa_actions.js +++ b/js/actions/coa_actions.js @@ -7,7 +7,8 @@ import CoaFetcher from '../fetchers/coa_fetcher'; class CoaActions { constructor() { this.generateActions( - 'updateCoa' + 'updateCoa', + 'flushCoa' ); } @@ -26,9 +27,7 @@ class CoaActions { this.actions.updateCoa(res.coa); }) .catch((err) => { - console.log(err) console.logGlobal(err); - this.actions.updateCoa('Something went wrong, please try again later.'); }); } } diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index 0ab07b34..2d9868c1 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -1,6 +1,7 @@ 'use strict'; import alt from '../alt'; +import Q from 'q'; import EditionListFetcher from '../fetchers/edition_list_fetcher.js'; @@ -28,7 +29,7 @@ class EditionListActions { pageSize = 10; } - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { EditionListFetcher .fetch(pieceId, page, pageSize, orderBy, orderAsc) .then((res) => { diff --git a/js/actions/event_actions.js b/js/actions/event_actions.js new file mode 100644 index 00000000..8f1def9f --- /dev/null +++ b/js/actions/event_actions.js @@ -0,0 +1,19 @@ +'use strict'; + +import alt from '../alt'; + + +class EventActions { + constructor() { + this.generateActions( + 'applicationWillBoot', + 'applicationDidBoot', + 'profileDidLoad', + //'userDidLogin', + //'userDidLogout', + 'routeDidChange' + ); + } +} + +export default alt.createActions(EventActions); diff --git a/js/actions/piece_list_actions.js b/js/actions/piece_list_actions.js index 390dfb98..dfb9bd44 100644 --- a/js/actions/piece_list_actions.js +++ b/js/actions/piece_list_actions.js @@ -1,6 +1,7 @@ 'use strict'; import alt from '../alt'; +import Q from 'q'; import PieceListFetcher from '../fetchers/piece_list_fetcher'; @@ -29,7 +30,7 @@ class PieceListActions { // afterwards, we can load the list - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { PieceListFetcher .fetch(page, pageSize, search, orderBy, orderAsc) .then((res) => { diff --git a/js/actions/user_actions.js b/js/actions/user_actions.js index 1ea0c560..44682f17 100644 --- a/js/actions/user_actions.js +++ b/js/actions/user_actions.js @@ -13,7 +13,7 @@ class UserActions { } fetchCurrentUser() { - UserFetcher.fetchOne() + return UserFetcher.fetchOne() .then((res) => { this.actions.updateCurrentUser(res.users[0]); }) diff --git a/js/app.js b/js/app.js index 13aa38a5..81a8fb82 100644 --- a/js/app.js +++ b/js/app.js @@ -5,7 +5,9 @@ require('babel/polyfill'); import React from 'react'; import Router from 'react-router'; +/* eslint-disable */ import fetch from 'isomorphic-fetch'; +/* eslint-enable */ import ApiUrls from './constants/api_urls'; import { updateApiUrls } from './constants/api_urls'; @@ -16,6 +18,16 @@ import requests from './utils/requests'; import { getSubdomainSettings } from './utils/constants_utils'; import { initLogging } from './utils/error_utils'; +import EventActions from './actions/event_actions'; + +/* eslint-disable */ +// You can comment out the modules you don't need +// import DebugHandler from './third_party/debug'; +import GoogleAnalyticsHandler from './third_party/ga'; +import RavenHandler from './third_party/raven'; +import IntercomHandler from './third_party/intercom'; +/* eslint-enable */ + initLogging(); let headers = { @@ -43,25 +55,30 @@ class AppGateway { settings = getSubdomainSettings(subdomain); appConstants.whitelabel = settings; updateApiUrls(settings.type, subdomain); - this.load(settings.type); + this.load(settings); } catch(err) { // if there are no matching subdomains, we're routing // to the default frontend console.logGlobal(err); - this.load('default'); + this.load(); } } - load(type) { + load(settings) { + let type = 'default'; + if (settings) { + type = settings.type; + } + + EventActions.applicationWillBoot(settings); Router.run(getRoutes(type), Router.HistoryLocation, (App) => { - if (window.ga) { - window.ga('send', 'pageview'); - } React.render( , document.getElementById('main') ); + EventActions.routeDidChange(); }); + EventActions.applicationDidBoot(settings); } } diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index 4daa2543..b19f93b3 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -68,6 +68,15 @@ let Edition = React.createClass({ }, componentWillUnmount() { + // Flushing the coa state is essential to not displaying the same + // data to the user while he's on another edition + // + // BUGFIX: Previously we had this line in the componentWillUnmount of + // CoaDetails, but since we're reloading the edition after performing an ACL action + // on it, this resulted in multiple events occupying the dispatcher, which eventually + // resulted in crashing the app. + CoaActions.flushCoa(); + UserStore.unlisten(this.onChange); PieceListStore.unlisten(this.onChange); }, @@ -398,7 +407,7 @@ let CoaDetails = React.createClass({ componentDidMount() { CoaStore.listen(this.onChange); - if (this.props.edition.coa) { + if(this.props.edition.coa) { CoaActions.fetchOne(this.props.edition.coa); } else { @@ -415,7 +424,7 @@ let CoaDetails = React.createClass({ }, render() { - if (this.state.coa && this.state.coa.url_safe) { + if(this.state.coa && this.state.coa.url_safe) { return (

@@ -433,8 +442,7 @@ let CoaDetails = React.createClass({

); - } - else if (typeof this.state.coa === 'string'){ + } else if(typeof this.state.coa === 'string'){ return (
{this.state.coa} diff --git a/js/components/ascribe_detail/media_container.js b/js/components/ascribe_detail/media_container.js index 6bf58a9c..2ff5a55d 100644 --- a/js/components/ascribe_detail/media_container.js +++ b/js/components/ascribe_detail/media_container.js @@ -12,6 +12,11 @@ import CollapsibleButton from './../ascribe_collapsible/collapsible_button'; import AclProxy from '../acl_proxy'; +const EMBED_IFRAME_HEIGHT = { + video: 315, + audio: 62 +}; + let MediaContainer = React.createClass({ propTypes: { content: React.PropTypes.object @@ -29,7 +34,9 @@ let MediaContainer = React.createClass({ extraData = this.props.content.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label }; }); } - if (['video', 'audio'].indexOf(mimetype) > -1){ + if (['video', 'audio'].indexOf(mimetype) > -1) { + let height = EMBED_IFRAME_HEIGHT[mimetype]; + embed = ( - {''} }/> @@ -55,6 +62,7 @@ let MediaContainer = React.createClass({ encodingStatus={this.props.content.digital_work.isEncoding} />