diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-07-14 10:08:36 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-07-14 10:08:36 -0400 |
commit | caabfbcdd56bdced7c5c1d38e00f488adffe7c60 (patch) | |
tree | 4d52326767246f331da352f0427e34bf714e3130 /webapp/actions/user_actions.jsx | |
parent | 8e810bc2ebb743717b5b0fc4541fcd3b2565966c (diff) | |
download | chat-caabfbcdd56bdced7c5c1d38e00f488adffe7c60.tar.gz chat-caabfbcdd56bdced7c5c1d38e00f488adffe7c60.tar.bz2 chat-caabfbcdd56bdced7c5c1d38e00f488adffe7c60.zip |
PLT-2992 Added the ability to use different themes for each team (#3411)
* Cleaned up user_settings_theme.jsx and import_theme_modal.jsx
* Made ImportThemeModal use a callback to return the theme to the user settings modal instead of saving it directly
* Moved user theme from model to preferences
* Added serverside API to delete preferences TODO update package with client stuff
* Changed constants.jsx so that Preferences and ActionTypes can be imported on their own
* Updated ThemeProps migration code to properly rename solarized code themes
* Fixed warnings thrown by AppDispatcher
* Added clientside UI to support team-specific themes
* Removed debugging code from test
* Fixed setting a user's theme when they haven't set their theme before
Diffstat (limited to 'webapp/actions/user_actions.jsx')
-rw-r--r-- | webapp/actions/user_actions.jsx | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 2f6eb9942..6d14e9fba 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -1,10 +1,15 @@ // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Client from 'utils/web_client.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; +import Client from 'utils/web_client.jsx'; +import PreferenceStore from 'stores/preference_store.jsx'; import TeamStore from 'stores/team_store.jsx'; +import UserStore from 'stores/user_store.jsx'; + +import {ActionTypes, Preferences} from 'utils/constants.jsx'; export function switchFromLdapToEmail(email, password, ldapPassword, onSuccess, onError) { Client.ldapToEmail( @@ -28,3 +33,52 @@ export function getMoreDmList() { AsyncClient.getProfilesForDirectMessageList(); AsyncClient.getTeamMembers(TeamStore.getCurrentId()); } + +export function saveTheme(teamId, theme, onSuccess, onError) { + AsyncClient.savePreference( + Preferences.CATEGORY_THEME, + teamId, + JSON.stringify(theme), + () => { + onThemeSaved(teamId, theme, onSuccess); + }, + (err) => { + onError(err); + } + ); +} + +function onThemeSaved(teamId, theme, onSuccess) { + const themePreferences = PreferenceStore.getCategory(Preferences.CATEGORY_THEME); + + if (teamId !== '' && themePreferences.size > 1) { + // no extra handling to be done to delete team-specific themes + onSuccess(); + return; + } + + const toDelete = []; + + for (const [name] of themePreferences) { + if (name === '') { + continue; + } + + toDelete.push({ + user_id: UserStore.getCurrentId(), + category: Preferences.CATEGORY_THEME, + name + }); + } + + // we're saving a new global theme so delete any team-specific ones + AsyncClient.deletePreferences(toDelete); + + // delete them locally before we hear from the server so that the UI flow is smoother + AppDispatcher.handleServerAction({ + type: ActionTypes.DELETED_PREFERENCES, + preferences: toDelete + }); + + onSuccess(); +}
\ No newline at end of file |