Files
mattermost/webapp/components/root.jsx
Harrison Healey dc2f2a8001 PLT-3145 Custom Emojis (#3381)
* Reorganized Backstage code to use a view controller and separated it from integrations code

* Renamed InstalledIntegrations component to BackstageList

* Added EmojiList page

* Added AddEmoji page

* Added custom emoji to autocomplete and text formatter

* Moved system emoji to EmojiStore

* Stopped trying to get emoji before logging in

* Rerender posts when emojis change

* Fixed submit handler on backstage pages to properly support enter

* Removed debugging code

* Updated javascript driver

* Fixed unit tests

* Fixed backstage routes

* Added clientside validation to prevent users from creating an emoji with the same name as a system one

* Fixed AddEmoji page to properly redirect when an emoji is created successfully

* Fixed updating emoji list when an emoji is deleted

* Added type prop to BackstageList to properly support using a table for the list

* Added help text to EmojiList

* Fixed backstage on smaller screen sizes

* Disable custom emoji by default

* Improved restrictions on creating emojis

* Fixed non-admin users seeing the option to delete each other's emojis

* Fixing gofmt

* Fixed emoji unit tests

* Fixed trying to get emoji from the server when it's disabled
2016-07-05 11:58:18 -04:00

98 lines
3.7 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as GlobalActions from 'actions/global_actions.jsx';
import LocalizationStore from 'stores/localization_store.jsx';
import Client from 'utils/web_client.jsx';
import {IntlProvider} from 'react-intl';
import React from 'react';
import FastClick from 'fastclick';
import {browserHistory} from 'react-router/es6';
import UserStore from 'stores/user_store.jsx';
export default class Root extends React.Component {
constructor(props) {
super(props);
this.state = {
locale: 'en',
translations: null
};
this.localizationChanged = this.localizationChanged.bind(this);
this.redirectIfNecessary = this.redirectIfNecessary.bind(this);
// Ya....
/*eslint-disable */
if (window.mm_config.SegmentDeveloperKey != null && window.mm_config.SegmentDeveloperKey !== "") {
!function(){var analytics=global.window.analytics=global.window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.1";
analytics.load(window.mm_config.SegmentDeveloperKey);
analytics.page();
}}();
}
/*eslint-enable */
// Fastclick
FastClick.attach(document.body);
}
localizationChanged() {
const locale = LocalizationStore.getLocale();
Client.setAcceptLanguage(locale);
this.setState({locale, translations: LocalizationStore.getTranslations()});
}
redirectIfNecessary(props) {
if (props.location.pathname === '/') {
if (UserStore.getNoAccounts()) {
browserHistory.push('/signup_user_complete');
} else if (UserStore.getCurrentUser()) {
browserHistory.push('/select_team');
} else {
browserHistory.push('/login');
}
}
}
componentWillReceiveProps(newProps) {
this.redirectIfNecessary(newProps);
}
componentWillMount() {
// Redirect if Necessary
this.redirectIfNecessary(this.props);
}
componentDidMount() {
// Setup localization listener
LocalizationStore.addChangeListener(this.localizationChanged);
// Get our localizaiton
GlobalActions.loadDefaultLocale();
}
componentWillUnmount() {
LocalizationStore.removeChangeListener(this.localizationChanged);
}
render() {
if (this.state.translations == null || this.props.children == null) {
return <div/>;
}
return (
<IntlProvider
locale={this.state.locale}
messages={this.state.translations}
key={this.state.locale}
>
{this.props.children}
</IntlProvider>
);
}
}
Root.defaultProps = {
};
Root.propTypes = {
children: React.PropTypes.object
};