mattermost-mobile/service/selectors/entities/preferences.js
Harrison Healey d0481605fb Add ability to post messages (#158)
* Fixed copyright date

* Removed unnecessary components folder from channel scene

* Added initial version of post textbox

* Moved getTheme into a proper selector

* Moved ChannelHeader into its own component

* Flipped post list so that the most recent posts appear at the bottom

* Moved post textbox value into redux view store

* Switched new components from PureRenderMixin to React.PureComponent
2017-01-13 10:40:00 -03:00

52 lines
1.5 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {createSelector} from 'reselect';
import Config from 'assets/config.json';
import Themes from 'assets/themes.json';
import {Preferences} from 'service/constants';
import {getCurrentTeamId} from './teams';
export function getMyPreferences(state) {
return state.entities.preferences.myPreferences;
}
export const getTheme = createSelector(
getMyPreferences,
getCurrentTeamId,
(myPreferences, currentTeamId) => {
// Prefer the user's current team-specific theme over the user's current global theme over the default theme
let themePreference;
if (currentTeamId) {
themePreference = myPreferences[`${Preferences.CATEGORY_THEME}--${currentTeamId}`];
}
if (!themePreference) {
themePreference = myPreferences[`${Preferences.CATEGORY_THEME}--`];
}
let theme;
if (themePreference) {
theme = themePreference.value;
} else {
theme = Config.DefaultTheme;
}
if (typeof theme === 'string') {
try {
// A custom theme will be a JSON-serialized object stored in a preference
theme = JSON.parse(theme);
} catch (e) {
// But if it's not a JSON object, it must be the name of a default theme
theme = Themes[theme];
}
}
// At this point, the theme should be a plain object
return theme;
}
);