diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-05-08 17:02:09 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-05-08 17:02:09 +0200 |
commit | 1e38ec5e524c71ae89cd7d4956736494b8c13886 (patch) | |
tree | 73be43066ff504af701e1c201b209db09abdb302 /src/features/announcements/store.js | |
parent | fix debug message for announcement semver logic (diff) | |
download | ferdium-app-1e38ec5e524c71ae89cd7d4956736494b8c13886.tar.gz ferdium-app-1e38ec5e524c71ae89cd7d4956736494b8c13886.tar.zst ferdium-app-1e38ec5e524c71ae89cd7d4956736494b8c13886.zip |
fix(Announcements): Fixes issue with rendering announcments in workspaces
Diffstat (limited to 'src/features/announcements/store.js')
-rw-r--r-- | src/features/announcements/store.js | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/features/announcements/store.js b/src/features/announcements/store.js index 6e7ca1dd7..27be86144 100644 --- a/src/features/announcements/store.js +++ b/src/features/announcements/store.js | |||
@@ -8,12 +8,13 @@ import semver from 'semver'; | |||
8 | import localStorage from 'mobx-localstorage'; | 8 | import localStorage from 'mobx-localstorage'; |
9 | 9 | ||
10 | import { FeatureStore } from '../utils/FeatureStore'; | 10 | import { FeatureStore } from '../utils/FeatureStore'; |
11 | import { GA_CATEGORY_ANNOUNCEMENTS } from '.'; | 11 | import { ANNOUNCEMENTS_ROUTES, GA_CATEGORY_ANNOUNCEMENTS } from '.'; |
12 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; | 12 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; |
13 | import { announcementActions } from './actions'; | 13 | import { announcementActions } from './actions'; |
14 | import { createActionBindings } from '../utils/ActionBinding'; | 14 | import { createActionBindings } from '../utils/ActionBinding'; |
15 | import { createReactions } from '../../stores/lib/Reaction'; | 15 | import { createReactions } from '../../stores/lib/Reaction'; |
16 | import { gaEvent } from '../../lib/analytics'; | 16 | import { gaEvent } from '../../lib/analytics'; |
17 | import { matchRoute } from '../../helpers/routing-helpers'; | ||
17 | 18 | ||
18 | const LOCAL_STORAGE_KEY = 'announcements'; | 19 | const LOCAL_STORAGE_KEY = 'announcements'; |
19 | 20 | ||
@@ -22,8 +23,6 @@ const debug = require('debug')('Franz:feature:announcements:store'); | |||
22 | export class AnnouncementsStore extends FeatureStore { | 23 | export class AnnouncementsStore extends FeatureStore { |
23 | @observable targetVersion = null; | 24 | @observable targetVersion = null; |
24 | 25 | ||
25 | @observable isAnnouncementVisible = false; | ||
26 | |||
27 | @observable isFeatureActive = false; | 26 | @observable isFeatureActive = false; |
28 | 27 | ||
29 | @computed get changelog() { | 28 | @computed get changelog() { |
@@ -37,6 +36,7 @@ export class AnnouncementsStore extends FeatureStore { | |||
37 | @computed get areNewsAvailable() { | 36 | @computed get areNewsAvailable() { |
38 | const isChangelogAvailable = getChangelogRequest.wasExecuted && !!this.changelog; | 37 | const isChangelogAvailable = getChangelogRequest.wasExecuted && !!this.changelog; |
39 | const isAnnouncementAvailable = getAnnouncementRequest.wasExecuted && !!this.announcement; | 38 | const isAnnouncementAvailable = getAnnouncementRequest.wasExecuted && !!this.announcement; |
39 | console.log(isChangelogAvailable, isAnnouncementAvailable); | ||
40 | return isChangelogAvailable || isAnnouncementAvailable; | 40 | return isChangelogAvailable || isAnnouncementAvailable; |
41 | } | 41 | } |
42 | 42 | ||
@@ -67,8 +67,9 @@ export class AnnouncementsStore extends FeatureStore { | |||
67 | ])); | 67 | ])); |
68 | 68 | ||
69 | this._reactions = createReactions([ | 69 | this._reactions = createReactions([ |
70 | this._fetchAnnouncements, | 70 | this._showAnnouncementOnRouteMatch, |
71 | this._showAnnouncementToUsersWhoUpdatedApp, | 71 | this._showAnnouncementToUsersWhoUpdatedApp, |
72 | this._fetchAnnouncements, | ||
72 | ]); | 73 | ]); |
73 | this._registerReactions(this._reactions); | 74 | this._registerReactions(this._reactions); |
74 | this.isFeatureActive = true; | 75 | this.isFeatureActive = true; |
@@ -78,7 +79,6 @@ export class AnnouncementsStore extends FeatureStore { | |||
78 | super.stop(); | 79 | super.stop(); |
79 | debug('AnnouncementsStore::stop'); | 80 | debug('AnnouncementsStore::stop'); |
80 | this.isFeatureActive = false; | 81 | this.isFeatureActive = false; |
81 | this.isAnnouncementVisible = false; | ||
82 | } | 82 | } |
83 | 83 | ||
84 | // ======= HELPERS ======= // | 84 | // ======= HELPERS ======= // |
@@ -93,33 +93,23 @@ export class AnnouncementsStore extends FeatureStore { | |||
93 | // ======= ACTIONS ======= // | 93 | // ======= ACTIONS ======= // |
94 | 94 | ||
95 | @action _showAnnouncement = ({ targetVersion } = {}) => { | 95 | @action _showAnnouncement = ({ targetVersion } = {}) => { |
96 | if (!this.areNewsAvailable) return; | 96 | const { router } = this.stores; |
97 | this.targetVersion = targetVersion || this.currentVersion; | 97 | this.targetVersion = targetVersion || this.currentVersion; |
98 | this.isAnnouncementVisible = true; | ||
99 | this.actions.service.blurActive(); | ||
100 | this._updateSettings({ | 98 | this._updateSettings({ |
101 | lastSeenAnnouncementVersion: this.currentVersion, | 99 | lastSeenAnnouncementVersion: this.currentVersion, |
102 | }); | 100 | }); |
103 | const dispose = reaction( | 101 | const targetRoute = `/announcements/${this.targetVersion}`; |
104 | () => this.stores.services.active, | 102 | if (router.location.pathname !== targetRoute) { |
105 | () => { | 103 | this.stores.router.push(targetRoute); |
106 | this._hideAnnouncement(); | 104 | } |
107 | dispose(); | ||
108 | }, | ||
109 | ); | ||
110 | |||
111 | gaEvent(GA_CATEGORY_ANNOUNCEMENTS, 'show'); | 105 | gaEvent(GA_CATEGORY_ANNOUNCEMENTS, 'show'); |
112 | }; | 106 | }; |
113 | 107 | ||
114 | @action _hideAnnouncement() { | ||
115 | this.isAnnouncementVisible = false; | ||
116 | } | ||
117 | |||
118 | // ======= REACTIONS ======== | 108 | // ======= REACTIONS ======== |
119 | 109 | ||
120 | _showAnnouncementToUsersWhoUpdatedApp = () => { | 110 | _showAnnouncementToUsersWhoUpdatedApp = () => { |
121 | const { announcement, isNewUser } = this; | 111 | const { announcement, isNewUser } = this; |
122 | // Check if there is an announcement and on't show announcements to new users | 112 | // Check if there is an announcement and don't show announcements to new users |
123 | if (!announcement || isNewUser) return; | 113 | if (!announcement || isNewUser) return; |
124 | 114 | ||
125 | // Check if the user has already used current version (= has seen the announcement) | 115 | // Check if the user has already used current version (= has seen the announcement) |
@@ -140,5 +130,14 @@ export class AnnouncementsStore extends FeatureStore { | |||
140 | } else { | 130 | } else { |
141 | getAnnouncementRequest.reset(); | 131 | getAnnouncementRequest.reset(); |
142 | } | 132 | } |
133 | }; | ||
134 | |||
135 | _showAnnouncementOnRouteMatch = () => { | ||
136 | const { router } = this.stores; | ||
137 | const match = matchRoute(ANNOUNCEMENTS_ROUTES.TARGET, router.location.pathname); | ||
138 | if (match) { | ||
139 | const targetVersion = match.id; | ||
140 | this._showAnnouncement({ targetVersion }); | ||
141 | } | ||
143 | } | 142 | } |
144 | } | 143 | } |