diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-06-24 21:25:05 +0200 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-06-25 05:50:00 +0530 |
commit | 2d71e61e46394d75d9f52ba1f4c273ed6d3c9cfd (patch) | |
tree | 7c0172945f962609637d03e7de885a254dbec8a4 /src/stores/UIStore.js | |
parent | chore: improve todo menu behaviour on fresh install (#359) (diff) | |
download | ferdium-app-2d71e61e46394d75d9f52ba1f4c273ed6d3c9cfd.tar.gz ferdium-app-2d71e61e46394d75d9f52ba1f4c273ed6d3c9cfd.tar.zst ferdium-app-2d71e61e46394d75d9f52ba1f4c273ed6d3c9cfd.zip |
chore: convert the last few stores to typescript
Diffstat (limited to 'src/stores/UIStore.js')
-rw-r--r-- | src/stores/UIStore.js | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js deleted file mode 100644 index 091b9b8eb..000000000 --- a/src/stores/UIStore.js +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | import { action, observable, computed, reaction } from 'mobx'; | ||
2 | import { nativeTheme } from '@electron/remote'; | ||
3 | |||
4 | import { theme, ThemeType } from '../themes'; | ||
5 | import Store from './lib/Store'; | ||
6 | |||
7 | export default class UIStore extends Store { | ||
8 | @observable showServicesUpdatedInfoBar = false; | ||
9 | |||
10 | @observable isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
11 | |||
12 | constructor(...args) { | ||
13 | super(...args); | ||
14 | |||
15 | // Register action handlers | ||
16 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); | ||
17 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); | ||
18 | this.actions.ui.toggleServiceUpdatedInfoBar.listen( | ||
19 | this._toggleServiceUpdatedInfoBar.bind(this), | ||
20 | ); | ||
21 | |||
22 | // Listen for theme change | ||
23 | nativeTheme.on('updated', () => { | ||
24 | this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
25 | this.actions.service.shareSettingsWithServiceProcess(); | ||
26 | }); | ||
27 | } | ||
28 | |||
29 | setup() { | ||
30 | reaction( | ||
31 | () => this.isDarkThemeActive, | ||
32 | () => { | ||
33 | this._setupThemeInDOM(); | ||
34 | }, | ||
35 | { fireImmediately: true }, | ||
36 | ); | ||
37 | reaction( | ||
38 | () => this.isSplitModeActive, | ||
39 | () => { | ||
40 | this._setupModeInDOM(); | ||
41 | }, | ||
42 | { fireImmediately: true }, | ||
43 | ); | ||
44 | reaction( | ||
45 | () => this.splitColumnsNo, | ||
46 | () => { | ||
47 | this._setupColumnsInDOM(); | ||
48 | }, | ||
49 | { fireImmediately: true }, | ||
50 | ); | ||
51 | } | ||
52 | |||
53 | @computed get showMessageBadgesEvenWhenMuted() { | ||
54 | const settings = this.stores.settings.all; | ||
55 | |||
56 | return ( | ||
57 | (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) || | ||
58 | !settings.app.isAppMuted | ||
59 | ); | ||
60 | } | ||
61 | |||
62 | @computed get isDarkThemeActive() { | ||
63 | const isWithAdaptableInDarkMode = | ||
64 | this.stores.settings.all.app.adaptableDarkMode && | ||
65 | this.isOsDarkThemeActive; | ||
66 | const isWithoutAdaptableInDarkMode = | ||
67 | this.stores.settings.all.app.darkMode && | ||
68 | !this.stores.settings.all.app.adaptableDarkMode; | ||
69 | const isInDarkMode = this.stores.settings.all.app.darkMode; | ||
70 | return !!( | ||
71 | isWithAdaptableInDarkMode || | ||
72 | isWithoutAdaptableInDarkMode || | ||
73 | isInDarkMode | ||
74 | ); | ||
75 | } | ||
76 | |||
77 | @computed get isSplitModeActive() { | ||
78 | return this.stores.settings.app.splitMode; | ||
79 | } | ||
80 | |||
81 | @computed get splitColumnsNo() { | ||
82 | return this.stores.settings.app.splitColumns; | ||
83 | } | ||
84 | |||
85 | @computed get theme() { | ||
86 | const themeId = | ||
87 | this.isDarkThemeActive || this.stores.settings.app.darkMode | ||
88 | ? ThemeType.dark | ||
89 | : ThemeType.default; | ||
90 | const { accentColor } = this.stores.settings.app; | ||
91 | return theme(themeId, accentColor); | ||
92 | } | ||
93 | |||
94 | // Actions | ||
95 | @action _openSettings({ path = '/settings' }) { | ||
96 | const settingsPath = path !== '/settings' ? `/settings/${path}` : path; | ||
97 | this.stores.router.push(settingsPath); | ||
98 | } | ||
99 | |||
100 | @action _closeSettings() { | ||
101 | this.stores.router.push('/'); | ||
102 | } | ||
103 | |||
104 | @action _toggleServiceUpdatedInfoBar({ visible }) { | ||
105 | let visibility = visible; | ||
106 | if (visibility === null) { | ||
107 | visibility = !this.showServicesUpdatedInfoBar; | ||
108 | } | ||
109 | this.showServicesUpdatedInfoBar = visibility; | ||
110 | } | ||
111 | |||
112 | // Reactions | ||
113 | _setupThemeInDOM() { | ||
114 | if (!this.isDarkThemeActive) { | ||
115 | document.body.classList.remove('theme__dark'); | ||
116 | } else { | ||
117 | document.body.classList.add('theme__dark'); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | _setupModeInDOM() { | ||
122 | if (!this.isSplitModeActive) { | ||
123 | document.body.classList.remove('mode__split'); | ||
124 | } else { | ||
125 | document.body.classList.add('mode__split'); | ||
126 | document.body.dataset.columns = this.splitColumnsNo; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | _setupColumnsInDOM() { | ||
131 | document.body.dataset.columns = this.splitColumnsNo; | ||
132 | } | ||
133 | } | ||