mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +03:00
Move changeTheme and convertThemeName to Themes.js
This commit is contained in:
parent
10835a6f82
commit
04c11ddc49
6 changed files with 76 additions and 94 deletions
|
|
@ -1,34 +1,65 @@
|
|||
import ko from 'ko';
|
||||
import { doc, $htmlCL, elementById, leftPanelDisabled, Settings, SettingsGet } from 'Common/Globals';
|
||||
import { isArray } from 'Common/Utils';
|
||||
import { isArray, arrayLength } from 'Common/Utils';
|
||||
import { serverRequestRaw } from 'Common/Links';
|
||||
import { SaveSettingStatus } from 'Common/Enums';
|
||||
|
||||
export const ThemeStore = {
|
||||
theme: ko.observable(''),
|
||||
themes: ko.observableArray(),
|
||||
userBackgroundName: ko.observable(''),
|
||||
userBackgroundHash: ko.observable(''),
|
||||
fontSansSerif: ko.observable(''),
|
||||
fontSerif: ko.observable(''),
|
||||
fontMono: ko.observable(''),
|
||||
isMobile: ko.observable($htmlCL.contains('rl-mobile')),
|
||||
let __themeTimer = 0;
|
||||
|
||||
populate: () => {
|
||||
const themes = Settings.app('themes');
|
||||
export const
|
||||
ThemeStore = {
|
||||
theme: ko.observable(''),
|
||||
themes: ko.observableArray(),
|
||||
userBackgroundName: ko.observable(''),
|
||||
userBackgroundHash: ko.observable(''),
|
||||
fontSansSerif: ko.observable(''),
|
||||
fontSerif: ko.observable(''),
|
||||
fontMono: ko.observable(''),
|
||||
isMobile: ko.observable($htmlCL.contains('rl-mobile')),
|
||||
|
||||
ThemeStore.themes(isArray(themes) ? themes : []);
|
||||
ThemeStore.theme(SettingsGet('Theme'));
|
||||
if (!ThemeStore.isMobile()) {
|
||||
ThemeStore.userBackgroundName(SettingsGet('UserBackgroundName'));
|
||||
ThemeStore.userBackgroundHash(SettingsGet('UserBackgroundHash'));
|
||||
populate: () => {
|
||||
const themes = Settings.app('themes');
|
||||
|
||||
ThemeStore.themes(isArray(themes) ? themes : []);
|
||||
ThemeStore.theme(SettingsGet('Theme'));
|
||||
if (!ThemeStore.isMobile()) {
|
||||
ThemeStore.userBackgroundName(SettingsGet('UserBackgroundName'));
|
||||
ThemeStore.userBackgroundHash(SettingsGet('UserBackgroundHash'));
|
||||
}
|
||||
ThemeStore.fontSansSerif(SettingsGet('fontSansSerif'));
|
||||
ThemeStore.fontSerif(SettingsGet('fontSerif'));
|
||||
ThemeStore.fontMono(SettingsGet('fontMono'));
|
||||
|
||||
leftPanelDisabled(ThemeStore.isMobile());
|
||||
}
|
||||
ThemeStore.fontSansSerif(SettingsGet('fontSansSerif'));
|
||||
ThemeStore.fontSerif(SettingsGet('fontSerif'));
|
||||
ThemeStore.fontMono(SettingsGet('fontMono'));
|
||||
},
|
||||
|
||||
leftPanelDisabled(ThemeStore.isMobile());
|
||||
}
|
||||
};
|
||||
changeTheme = (value, themeTrigger = ()=>0) => {
|
||||
const themeStyle = elementById('app-theme-style'),
|
||||
clearTimer = () => {
|
||||
__themeTimer = setTimeout(() => themeTrigger(SaveSettingStatus.Idle), 1000);
|
||||
},
|
||||
url = themeStyle.dataset.href.replace(/(Admin|User)\/-\/[^/]+\//, '$1/-/' + value + '/') + 'Json/';
|
||||
|
||||
clearTimeout(__themeTimer);
|
||||
|
||||
themeTrigger(SaveSettingStatus.Saving);
|
||||
|
||||
rl.app.Remote.abort('theme').get('theme', url)
|
||||
.then(data => {
|
||||
if (2 === arrayLength(data)) {
|
||||
themeStyle.textContent = data[1];
|
||||
themeTrigger(SaveSettingStatus.Success);
|
||||
}
|
||||
clearTimer();
|
||||
}, clearTimer);
|
||||
},
|
||||
|
||||
convertThemeName = theme => theme
|
||||
.replace(/@custom$/, '')
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
||||
.trim();
|
||||
|
||||
ThemeStore.isMobile.subscribe(value => $htmlCL.toggle('rl-mobile', value));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue