@@ -8,12 +8,13 @@ import semver from 'semver';
88import localStorage from 'mobx-localstorage' ;
99
1010import { FeatureStore } from '../utils/FeatureStore' ;
11- import { GA_CATEGORY_ANNOUNCEMENTS } from '.' ;
11+ import { ANNOUNCEMENTS_ROUTES , GA_CATEGORY_ANNOUNCEMENTS } from '.' ;
1212import { getAnnouncementRequest , getChangelogRequest , getCurrentVersionRequest } from './api' ;
1313import { announcementActions } from './actions' ;
1414import { createActionBindings } from '../utils/ActionBinding' ;
1515import { createReactions } from '../../stores/lib/Reaction' ;
1616import { gaEvent } from '../../lib/analytics' ;
17+ import { matchRoute } from '../../helpers/routing-helpers' ;
1718
1819const LOCAL_STORAGE_KEY = 'announcements' ;
1920
@@ -22,8 +23,6 @@ const debug = require('debug')('Franz:feature:announcements:store');
2223export class AnnouncementsStore extends FeatureStore {
2324 @observable targetVersion = null ;
2425
25- @observable isAnnouncementVisible = false ;
26-
2726 @observable isFeatureActive = false ;
2827
2928 @computed get changelog ( ) {
@@ -37,6 +36,7 @@ export class AnnouncementsStore extends FeatureStore {
3736 @computed get areNewsAvailable ( ) {
3837 const isChangelogAvailable = getChangelogRequest . wasExecuted && ! ! this . changelog ;
3938 const isAnnouncementAvailable = getAnnouncementRequest . wasExecuted && ! ! this . announcement ;
39+ console . log ( isChangelogAvailable , isAnnouncementAvailable ) ;
4040 return isChangelogAvailable || isAnnouncementAvailable ;
4141 }
4242
@@ -67,8 +67,9 @@ export class AnnouncementsStore extends FeatureStore {
6767 ] ) ) ;
6868
6969 this . _reactions = createReactions ( [
70- this . _fetchAnnouncements ,
70+ this . _showAnnouncementOnRouteMatch ,
7171 this . _showAnnouncementToUsersWhoUpdatedApp ,
72+ this . _fetchAnnouncements ,
7273 ] ) ;
7374 this . _registerReactions ( this . _reactions ) ;
7475 this . isFeatureActive = true ;
@@ -78,7 +79,6 @@ export class AnnouncementsStore extends FeatureStore {
7879 super . stop ( ) ;
7980 debug ( 'AnnouncementsStore::stop' ) ;
8081 this . isFeatureActive = false ;
81- this . isAnnouncementVisible = false ;
8282 }
8383
8484 // ======= HELPERS ======= //
@@ -93,33 +93,23 @@ export class AnnouncementsStore extends FeatureStore {
9393 // ======= ACTIONS ======= //
9494
9595 @action _showAnnouncement = ( { targetVersion } = { } ) => {
96- if ( ! this . areNewsAvailable ) return ;
96+ const { router } = this . stores ;
9797 this . targetVersion = targetVersion || this . currentVersion ;
98- this . isAnnouncementVisible = true ;
99- this . actions . service . blurActive ( ) ;
10098 this . _updateSettings ( {
10199 lastSeenAnnouncementVersion : this . currentVersion ,
102100 } ) ;
103- const dispose = reaction (
104- ( ) => this . stores . services . active ,
105- ( ) => {
106- this . _hideAnnouncement ( ) ;
107- dispose ( ) ;
108- } ,
109- ) ;
110-
101+ const targetRoute = `/announcements/${ this . targetVersion } ` ;
102+ if ( router . location . pathname !== targetRoute ) {
103+ this . stores . router . push ( targetRoute ) ;
104+ }
111105 gaEvent ( GA_CATEGORY_ANNOUNCEMENTS , 'show' ) ;
112106 } ;
113107
114- @action _hideAnnouncement ( ) {
115- this . isAnnouncementVisible = false ;
116- }
117-
118108 // ======= REACTIONS ========
119109
120110 _showAnnouncementToUsersWhoUpdatedApp = ( ) => {
121111 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
123113 if ( ! announcement || isNewUser ) return ;
124114
125115 // Check if the user has already used current version (= has seen the announcement)
@@ -140,5 +130,14 @@ export class AnnouncementsStore extends FeatureStore {
140130 } else {
141131 getAnnouncementRequest . reset ( ) ;
142132 }
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+ }
143142 }
144143}
0 commit comments