diff options
Diffstat (limited to 'src/features/todos')
-rw-r--r-- | src/features/todos/index.js | 2 | ||||
-rw-r--r-- | src/features/todos/store.js | 79 |
2 files changed, 48 insertions, 33 deletions
diff --git a/src/features/todos/index.js b/src/features/todos/index.js index 55956d1d7..573190881 100644 --- a/src/features/todos/index.js +++ b/src/features/todos/index.js | |||
@@ -3,8 +3,6 @@ import TodoStore from './store'; | |||
3 | 3 | ||
4 | const debug = require('debug')('Ferdi:feature:todos'); | 4 | const debug = require('debug')('Ferdi:feature:todos'); |
5 | 5 | ||
6 | export const GA_CATEGORY_TODOS = 'Todos'; | ||
7 | |||
8 | export const todosStore = new TodoStore(); | 6 | export const todosStore = new TodoStore(); |
9 | 7 | ||
10 | export default function initTodos(stores, actions) { | 8 | export default function initTodos(stores, actions) { |
diff --git a/src/features/todos/store.js b/src/features/todos/store.js index f283c1e59..ec06c279d 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js | |||
@@ -1,9 +1,5 @@ | |||
1 | import { ThemeType } from '@meetfranz/theme'; | 1 | import { ThemeType } from '@meetfranz/theme'; |
2 | import { | 2 | import { computed, action, observable } from 'mobx'; |
3 | computed, | ||
4 | action, | ||
5 | observable, | ||
6 | } from 'mobx'; | ||
7 | import localStorage from 'mobx-localstorage'; | 3 | import localStorage from 'mobx-localstorage'; |
8 | 4 | ||
9 | import { todoActions } from './actions'; | 5 | import { todoActions } from './actions'; |
@@ -44,12 +40,13 @@ export default class TodoStore extends FeatureStore { | |||
44 | } | 40 | } |
45 | 41 | ||
46 | @computed get isTodosPanelForceHidden() { | 42 | @computed get isTodosPanelForceHidden() { |
47 | const { isAnnouncementShown } = this.stores.announcements; | 43 | return !this.isFeatureEnabledByUser; |
48 | return !this.isFeatureEnabledByUser || isAnnouncementShown; | ||
49 | } | 44 | } |
50 | 45 | ||
51 | @computed get isTodosPanelVisible() { | 46 | @computed get isTodosPanelVisible() { |
52 | if (this.settings.isTodosPanelVisible === undefined) return DEFAULT_TODOS_VISIBLE; | 47 | if (this.settings.isTodosPanelVisible === undefined) { |
48 | return DEFAULT_TODOS_VISIBLE; | ||
49 | } | ||
53 | return this.settings.isTodosPanelVisible; | 50 | return this.settings.isTodosPanelVisible; |
54 | } | 51 | } |
55 | 52 | ||
@@ -66,7 +63,10 @@ export default class TodoStore extends FeatureStore { | |||
66 | } | 63 | } |
67 | 64 | ||
68 | @computed get isUsingPredefinedTodoServer() { | 65 | @computed get isUsingPredefinedTodoServer() { |
69 | return this.stores && this.stores.settings.app.predefinedTodoServer !== CUSTOM_TODO_SERVICE; | 66 | return ( |
67 | this.stores && | ||
68 | this.stores.settings.app.predefinedTodoServer !== CUSTOM_TODO_SERVICE | ||
69 | ); | ||
70 | } | 70 | } |
71 | 71 | ||
72 | @computed get todoUrl() { | 72 | @computed get todoUrl() { |
@@ -79,12 +79,17 @@ export default class TodoStore extends FeatureStore { | |||
79 | } | 79 | } |
80 | 80 | ||
81 | @computed get isTodoUrlValid() { | 81 | @computed get isTodoUrlValid() { |
82 | return !this.isUsingPredefinedTodoServer || isValidExternalURL(this.todoUrl); | 82 | return ( |
83 | !this.isUsingPredefinedTodoServer || isValidExternalURL(this.todoUrl) | ||
84 | ); | ||
83 | } | 85 | } |
84 | 86 | ||
85 | @computed get todoRecipeId() { | 87 | @computed get todoRecipeId() { |
86 | if (this.isFeatureEnabledByUser && this.isUsingPredefinedTodoServer | 88 | if ( |
87 | && this.todoUrl in TODO_SERVICE_RECIPE_IDS) { | 89 | this.isFeatureEnabledByUser && |
90 | this.isUsingPredefinedTodoServer && | ||
91 | this.todoUrl in TODO_SERVICE_RECIPE_IDS | ||
92 | ) { | ||
88 | return TODO_SERVICE_RECIPE_IDS[this.todoUrl]; | 93 | return TODO_SERVICE_RECIPE_IDS[this.todoUrl]; |
89 | } | 94 | } |
90 | return null; | 95 | return null; |
@@ -99,16 +104,21 @@ export default class TodoStore extends FeatureStore { | |||
99 | 104 | ||
100 | // ACTIONS | 105 | // ACTIONS |
101 | 106 | ||
102 | this._registerActions(createActionBindings([ | 107 | this._registerActions( |
103 | [todoActions.resize, this._resize], | 108 | createActionBindings([ |
104 | [todoActions.toggleTodosPanel, this._toggleTodosPanel], | 109 | [todoActions.resize, this._resize], |
105 | [todoActions.setTodosWebview, this._setTodosWebview], | 110 | [todoActions.toggleTodosPanel, this._toggleTodosPanel], |
106 | [todoActions.handleHostMessage, this._handleHostMessage], | 111 | [todoActions.setTodosWebview, this._setTodosWebview], |
107 | [todoActions.handleClientMessage, this._handleClientMessage], | 112 | [todoActions.handleHostMessage, this._handleHostMessage], |
108 | [todoActions.toggleTodosFeatureVisibility, this._toggleTodosFeatureVisibility], | 113 | [todoActions.handleClientMessage, this._handleClientMessage], |
109 | [todoActions.openDevTools, this._openDevTools], | 114 | [ |
110 | [todoActions.reload, this._reload], | 115 | todoActions.toggleTodosFeatureVisibility, |
111 | ])); | 116 | this._toggleTodosFeatureVisibility, |
117 | ], | ||
118 | [todoActions.openDevTools, this._openDevTools], | ||
119 | [todoActions.reload, this._reload], | ||
120 | ]), | ||
121 | ); | ||
112 | 122 | ||
113 | // REACTIONS | 123 | // REACTIONS |
114 | 124 | ||
@@ -133,7 +143,7 @@ export default class TodoStore extends FeatureStore { | |||
133 | 143 | ||
134 | // ========== PRIVATE METHODS ========= // | 144 | // ========== PRIVATE METHODS ========= // |
135 | 145 | ||
136 | _updateSettings = (changes) => { | 146 | _updateSettings = changes => { |
137 | localStorage.setItem('todos', { | 147 | localStorage.setItem('todos', { |
138 | ...this.settings, | 148 | ...this.settings, |
139 | ...changes, | 149 | ...changes, |
@@ -162,7 +172,7 @@ export default class TodoStore extends FeatureStore { | |||
162 | } | 172 | } |
163 | }; | 173 | }; |
164 | 174 | ||
165 | @action _handleHostMessage = (message) => { | 175 | @action _handleHostMessage = message => { |
166 | debug('_handleHostMessage', message); | 176 | debug('_handleHostMessage', message); |
167 | if (message.action === 'todos:create') { | 177 | if (message.action === 'todos:create') { |
168 | this.webview.send(IPC.TODOS_HOST_CHANNEL, message); | 178 | this.webview.send(IPC.TODOS_HOST_CHANNEL, message); |
@@ -172,11 +182,18 @@ export default class TodoStore extends FeatureStore { | |||
172 | @action _handleClientMessage = ({ channel, message = {} }) => { | 182 | @action _handleClientMessage = ({ channel, message = {} }) => { |
173 | debug('_handleClientMessage', channel, message); | 183 | debug('_handleClientMessage', channel, message); |
174 | switch (message.action) { | 184 | switch (message.action) { |
175 | case 'todos:initialized': this._onTodosClientInitialized(); break; | 185 | case 'todos:initialized': |
176 | case 'todos:goToService': this._goToService(message.data); break; | 186 | this._onTodosClientInitialized(); |
187 | break; | ||
188 | case 'todos:goToService': | ||
189 | this._goToService(message.data); | ||
190 | break; | ||
177 | default: | 191 | default: |
178 | debug('Other message received', channel, message); | 192 | debug('Other message received', channel, message); |
179 | console.log('this.stores.services.isTodosServiceAdded', this.stores.services.isTodosServiceAdded); | 193 | console.log( |
194 | 'this.stores.services.isTodosServiceAdded', | ||
195 | this.stores.services.isTodosServiceAdded, | ||
196 | ); | ||
180 | if (this.stores.services.isTodosServiceAdded) { | 197 | if (this.stores.services.isTodosServiceAdded) { |
181 | this.actions.service.handleIPCMessage({ | 198 | this.actions.service.handleIPCMessage({ |
182 | serviceId: this.stores.services.isTodosServiceAdded.id, | 199 | serviceId: this.stores.services.isTodosServiceAdded.id, |
@@ -189,7 +206,7 @@ export default class TodoStore extends FeatureStore { | |||
189 | 206 | ||
190 | _handleNewWindowEvent = ({ url }) => { | 207 | _handleNewWindowEvent = ({ url }) => { |
191 | this.actions.app.openExternalUrl({ url }); | 208 | this.actions.app.openExternalUrl({ url }); |
192 | } | 209 | }; |
193 | 210 | ||
194 | @action _toggleTodosFeatureVisibility = () => { | 211 | @action _toggleTodosFeatureVisibility = () => { |
195 | debug('_toggleTodosFeatureVisibility'); | 212 | debug('_toggleTodosFeatureVisibility'); |
@@ -204,14 +221,14 @@ export default class TodoStore extends FeatureStore { | |||
204 | 221 | ||
205 | const webview = document.querySelector('#todos-panel webview'); | 222 | const webview = document.querySelector('#todos-panel webview'); |
206 | if (webview) webview.openDevTools(); | 223 | if (webview) webview.openDevTools(); |
207 | } | 224 | }; |
208 | 225 | ||
209 | _reload = () => { | 226 | _reload = () => { |
210 | debug('_reload'); | 227 | debug('_reload'); |
211 | 228 | ||
212 | const webview = document.querySelector('#todos-panel webview'); | 229 | const webview = document.querySelector('#todos-panel webview'); |
213 | if (webview) webview.reload(); | 230 | if (webview) webview.reload(); |
214 | } | 231 | }; |
215 | 232 | ||
216 | // Todos client message handlers | 233 | // Todos client message handlers |
217 | 234 | ||
@@ -291,5 +308,5 @@ export default class TodoStore extends FeatureStore { | |||
291 | }); | 308 | }); |
292 | } | 309 | } |
293 | } | 310 | } |
294 | } | 311 | }; |
295 | } | 312 | } |