diff options
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/announcements/components/AnnouncementScreen.js | 2 | ||||
-rw-r--r-- | src/features/announcements/index.js | 4 | ||||
-rw-r--r-- | src/features/announcements/store.js | 46 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 8 |
4 files changed, 29 insertions, 31 deletions
diff --git a/src/features/announcements/components/AnnouncementScreen.js b/src/features/announcements/components/AnnouncementScreen.js index dfce6cdd5..e7c5fe395 100644 --- a/src/features/announcements/components/AnnouncementScreen.js +++ b/src/features/announcements/components/AnnouncementScreen.js | |||
@@ -268,7 +268,7 @@ class AnnouncementScreen extends Component { | |||
268 | <div className={classes.changelog}> | 268 | <div className={classes.changelog}> |
269 | <h1 className={classes.headline}> | 269 | <h1 className={classes.headline}> |
270 | {intl.formatMessage(messages.headline, { | 270 | {intl.formatMessage(messages.headline, { |
271 | version: announcementsStore.currentVersion, | 271 | version: announcementsStore.targetVersion, |
272 | })} | 272 | })} |
273 | </h1> | 273 | </h1> |
274 | <div | 274 | <div |
diff --git a/src/features/announcements/index.js b/src/features/announcements/index.js index 4658b976f..f14e7c9a5 100644 --- a/src/features/announcements/index.js +++ b/src/features/announcements/index.js | |||
@@ -7,6 +7,10 @@ export const GA_CATEGORY_ANNOUNCEMENTS = 'Announcements'; | |||
7 | 7 | ||
8 | export const announcementsStore = new AnnouncementsStore(); | 8 | export const announcementsStore = new AnnouncementsStore(); |
9 | 9 | ||
10 | export const ANNOUNCEMENTS_ROUTES = { | ||
11 | TARGET: '/announcements/:id', | ||
12 | }; | ||
13 | |||
10 | export default function initAnnouncements(stores, actions) { | 14 | export default function initAnnouncements(stores, actions) { |
11 | // const { features } = stores; | 15 | // const { features } = stores; |
12 | 16 | ||
diff --git a/src/features/announcements/store.js b/src/features/announcements/store.js index 6e7ca1dd7..0d2b68ccf 100644 --- a/src/features/announcements/store.js +++ b/src/features/announcements/store.js | |||
@@ -2,18 +2,18 @@ import { | |||
2 | action, | 2 | action, |
3 | computed, | 3 | computed, |
4 | observable, | 4 | observable, |
5 | reaction, | ||
6 | } from 'mobx'; | 5 | } from 'mobx'; |
7 | import semver from 'semver'; | 6 | import semver from 'semver'; |
8 | import localStorage from 'mobx-localstorage'; | 7 | import localStorage from 'mobx-localstorage'; |
9 | 8 | ||
10 | import { FeatureStore } from '../utils/FeatureStore'; | 9 | import { FeatureStore } from '../utils/FeatureStore'; |
11 | import { GA_CATEGORY_ANNOUNCEMENTS } from '.'; | 10 | import { ANNOUNCEMENTS_ROUTES, GA_CATEGORY_ANNOUNCEMENTS } from '.'; |
12 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; | 11 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; |
13 | import { announcementActions } from './actions'; | 12 | import { announcementActions } from './actions'; |
14 | import { createActionBindings } from '../utils/ActionBinding'; | 13 | import { createActionBindings } from '../utils/ActionBinding'; |
15 | import { createReactions } from '../../stores/lib/Reaction'; | 14 | import { createReactions } from '../../stores/lib/Reaction'; |
16 | import { gaEvent } from '../../lib/analytics'; | 15 | import { gaEvent } from '../../lib/analytics'; |
16 | import { matchRoute } from '../../helpers/routing-helpers'; | ||
17 | 17 | ||
18 | const LOCAL_STORAGE_KEY = 'announcements'; | 18 | const LOCAL_STORAGE_KEY = 'announcements'; |
19 | 19 | ||
@@ -22,8 +22,6 @@ const debug = require('debug')('Franz:feature:announcements:store'); | |||
22 | export class AnnouncementsStore extends FeatureStore { | 22 | export class AnnouncementsStore extends FeatureStore { |
23 | @observable targetVersion = null; | 23 | @observable targetVersion = null; |
24 | 24 | ||
25 | @observable isAnnouncementVisible = false; | ||
26 | |||
27 | @observable isFeatureActive = false; | 25 | @observable isFeatureActive = false; |
28 | 26 | ||
29 | @computed get changelog() { | 27 | @computed get changelog() { |
@@ -67,8 +65,9 @@ export class AnnouncementsStore extends FeatureStore { | |||
67 | ])); | 65 | ])); |
68 | 66 | ||
69 | this._reactions = createReactions([ | 67 | this._reactions = createReactions([ |
70 | this._fetchAnnouncements, | 68 | this._showAnnouncementOnRouteMatch, |
71 | this._showAnnouncementToUsersWhoUpdatedApp, | 69 | this._showAnnouncementToUsersWhoUpdatedApp, |
70 | this._fetchAnnouncements, | ||
72 | ]); | 71 | ]); |
73 | this._registerReactions(this._reactions); | 72 | this._registerReactions(this._reactions); |
74 | this.isFeatureActive = true; | 73 | this.isFeatureActive = true; |
@@ -78,7 +77,6 @@ export class AnnouncementsStore extends FeatureStore { | |||
78 | super.stop(); | 77 | super.stop(); |
79 | debug('AnnouncementsStore::stop'); | 78 | debug('AnnouncementsStore::stop'); |
80 | this.isFeatureActive = false; | 79 | this.isFeatureActive = false; |
81 | this.isAnnouncementVisible = false; | ||
82 | } | 80 | } |
83 | 81 | ||
84 | // ======= HELPERS ======= // | 82 | // ======= HELPERS ======= // |
@@ -93,33 +91,23 @@ export class AnnouncementsStore extends FeatureStore { | |||
93 | // ======= ACTIONS ======= // | 91 | // ======= ACTIONS ======= // |
94 | 92 | ||
95 | @action _showAnnouncement = ({ targetVersion } = {}) => { | 93 | @action _showAnnouncement = ({ targetVersion } = {}) => { |
96 | if (!this.areNewsAvailable) return; | 94 | const { router } = this.stores; |
97 | this.targetVersion = targetVersion || this.currentVersion; | 95 | this.targetVersion = targetVersion || this.currentVersion; |
98 | this.isAnnouncementVisible = true; | ||
99 | this.actions.service.blurActive(); | ||
100 | this._updateSettings({ | 96 | this._updateSettings({ |
101 | lastSeenAnnouncementVersion: this.currentVersion, | 97 | lastSeenAnnouncementVersion: this.currentVersion, |
102 | }); | 98 | }); |
103 | const dispose = reaction( | 99 | const targetRoute = `/announcements/${this.targetVersion}`; |
104 | () => this.stores.services.active, | 100 | if (router.location.pathname !== targetRoute) { |
105 | () => { | 101 | this.stores.router.push(targetRoute); |
106 | this._hideAnnouncement(); | 102 | } |
107 | dispose(); | ||
108 | }, | ||
109 | ); | ||
110 | |||
111 | gaEvent(GA_CATEGORY_ANNOUNCEMENTS, 'show'); | 103 | gaEvent(GA_CATEGORY_ANNOUNCEMENTS, 'show'); |
112 | }; | 104 | }; |
113 | 105 | ||
114 | @action _hideAnnouncement() { | ||
115 | this.isAnnouncementVisible = false; | ||
116 | } | ||
117 | |||
118 | // ======= REACTIONS ======== | 106 | // ======= REACTIONS ======== |
119 | 107 | ||
120 | _showAnnouncementToUsersWhoUpdatedApp = () => { | 108 | _showAnnouncementToUsersWhoUpdatedApp = () => { |
121 | const { announcement, isNewUser } = this; | 109 | const { announcement, isNewUser } = this; |
122 | // Check if there is an announcement and on't show announcements to new users | 110 | // Check if there is an announcement and don't show announcements to new users |
123 | if (!announcement || isNewUser) return; | 111 | if (!announcement || isNewUser) return; |
124 | 112 | ||
125 | // Check if the user has already used current version (= has seen the announcement) | 113 | // Check if the user has already used current version (= has seen the announcement) |
@@ -134,11 +122,15 @@ export class AnnouncementsStore extends FeatureStore { | |||
134 | const targetVersion = this.targetVersion || this.currentVersion; | 122 | const targetVersion = this.targetVersion || this.currentVersion; |
135 | if (!targetVersion) return; | 123 | if (!targetVersion) return; |
136 | getChangelogRequest.execute(targetVersion); | 124 | getChangelogRequest.execute(targetVersion); |
137 | // We only fetch announcements for current / older versions | 125 | getAnnouncementRequest.execute(targetVersion); |
138 | if (targetVersion <= this.currentVersion) { | 126 | }; |
139 | getAnnouncementRequest.execute(targetVersion); | 127 | |
140 | } else { | 128 | _showAnnouncementOnRouteMatch = () => { |
141 | getAnnouncementRequest.reset(); | 129 | const { router } = this.stores; |
130 | const match = matchRoute(ANNOUNCEMENTS_ROUTES.TARGET, router.location.pathname); | ||
131 | if (match) { | ||
132 | const targetVersion = match.id; | ||
133 | this._showAnnouncement({ targetVersion }); | ||
142 | } | 134 | } |
143 | } | 135 | } |
144 | } | 136 | } |
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index e11513d1f..3d7043413 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -255,13 +255,15 @@ export default class WorkspacesStore extends FeatureStore { | |||
255 | _setActiveServiceOnWorkspaceSwitchReaction = () => { | 255 | _setActiveServiceOnWorkspaceSwitchReaction = () => { |
256 | if (!this.isFeatureActive) return; | 256 | if (!this.isFeatureActive) return; |
257 | if (this.activeWorkspace) { | 257 | if (this.activeWorkspace) { |
258 | const services = this.stores.services.allDisplayed; | 258 | const activeService = this.stores.services.active; |
259 | const activeService = services.find(s => s.isActive); | ||
260 | const workspaceServices = this.getWorkspaceServices(this.activeWorkspace); | 259 | const workspaceServices = this.getWorkspaceServices(this.activeWorkspace); |
261 | if (workspaceServices.length <= 0) return; | 260 | if (workspaceServices.length <= 0) return; |
262 | const isActiveServiceInWorkspace = workspaceServices.includes(activeService); | 261 | const isActiveServiceInWorkspace = workspaceServices.includes(activeService); |
263 | if (!isActiveServiceInWorkspace) { | 262 | if (!isActiveServiceInWorkspace) { |
264 | this.actions.service.setActive({ serviceId: workspaceServices[0].id }); | 263 | this.actions.service.setActive({ |
264 | serviceId: workspaceServices[0].id, | ||
265 | keepActiveRoute: true, | ||
266 | }); | ||
265 | } | 267 | } |
266 | } | 268 | } |
267 | }; | 269 | }; |