mattermost-mobile/service/selectors/entities/preferences.js
Harrison Healey 61c4d8b585 Added basic theming support (#131)
* Moved all view action types into a single file

* Moved preferences into their own constants section

* Added basic theming support
2016-12-12 21:05:59 -03:00

42 lines
1.2 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import Config from 'config';
import {Preferences, Themes} from 'service/constants';
export function getTheme(state) {
const myPreferences = state.entities.preferences.myPreferences;
const currentTeamId = state.entities.teams.currentId;
// 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;
}