Skip to content

Commit

Permalink
fix(Announcements): Fixes issue with rendering announcments in worksp…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
DominikGuzei committed May 8, 2019
1 parent 6cdcafe commit 1e38ec5
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/theme/src/themes/dark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const workspaces = merge({}, defaultStyles.workspaces, {
});

// Announcements
export const announcements = merge({}, defaultStyles.workspaces, {
export const announcements = merge({}, defaultStyles.announcements, {
spotlight: {
background: legacyStyles.darkThemeGrayDark,
},
Expand Down
1 change: 1 addition & 0 deletions src/actions/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ServiceModel from '../models/Service';
export default {
setActive: {
serviceId: PropTypes.string.isRequired,
keepActiveRoute: PropTypes.bool,
},
blurActive: {},
setActiveNext: {},
Expand Down
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import SubscriptionPopupScreen from './containers/subscription/SubscriptionPopup
import WorkspacesScreen from './features/workspaces/containers/WorkspacesScreen';
import EditWorkspaceScreen from './features/workspaces/containers/EditWorkspaceScreen';
import { WORKSPACES_ROUTES } from './features/workspaces';
import AnnouncementScreen from './features/announcements/components/AnnouncementScreen';
import { ANNOUNCEMENTS_ROUTES } from './features/announcements';

// Add Polyfills
smoothScroll.polyfill();
Expand Down Expand Up @@ -73,6 +75,7 @@ window.addEventListener('load', () => {
<I18N>
<Router history={history}>
<Route path="/" component={AppLayoutContainer}>
<Route path={ANNOUNCEMENTS_ROUTES.TARGET} component={AnnouncementScreen} />
<Route path="/settings" component={SettingsWindow}>
<IndexRedirect to="/settings/recipes" />
<Route path="/settings/recipes" component={RecipesScreen} />
Expand Down
5 changes: 1 addition & 4 deletions src/components/layout/AppLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class AppLayout extends Component {
areRequiredRequestsLoading: PropTypes.bool.isRequired,
darkMode: PropTypes.bool.isRequired,
isDelayAppScreenVisible: PropTypes.bool.isRequired,
isAnnouncementVisible: PropTypes.bool.isRequired,
};

static defaultProps = {
Expand Down Expand Up @@ -117,7 +116,6 @@ class AppLayout extends Component {
areRequiredRequestsLoading,
darkMode,
isDelayAppScreenVisible,
isAnnouncementVisible,
} = this.props;

const { intl } = this.context;
Expand Down Expand Up @@ -197,12 +195,11 @@ class AppLayout extends Component {
{isDelayAppScreenVisible && (<DelayApp />)}
<BasicAuth />
<ShareFranz />
{isAnnouncementVisible && (<AnnouncementScreen />)}
{services}
{children}
</div>
</div>
</div>
{children}
</div>
</ErrorBoundary>
);
Expand Down
1 change: 0 additions & 1 deletion src/containers/layout/AppLayoutContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export default @inject('stores', 'actions') @observer class AppLayoutContainer e
areRequiredRequestsLoading={requests.areRequiredRequestsLoading}
darkMode={settings.all.app.darkMode}
isDelayAppScreenVisible={delayAppState.isDelayAppScreenVisible}
isAnnouncementVisible={announcementsStore.isAnnouncementVisible}
>
{React.Children.count(children) > 0 ? children : null}
</AppLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class AnnouncementScreen extends Component {
<div className={classes.changelog}>
<h1 className={classes.headline}>
{intl.formatMessage(messages.headline, {
version: announcementsStore.currentVersion,
version: announcementsStore.targetVersion,
})}
</h1>
<div
Expand Down
4 changes: 4 additions & 0 deletions src/features/announcements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const GA_CATEGORY_ANNOUNCEMENTS = 'Announcements';

export const announcementsStore = new AnnouncementsStore();

export const ANNOUNCEMENTS_ROUTES = {
TARGET: '/announcements/:id',
};

export default function initAnnouncements(stores, actions) {
// const { features } = stores;

Expand Down
41 changes: 20 additions & 21 deletions src/features/announcements/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import semver from 'semver';
import localStorage from 'mobx-localstorage';

import { FeatureStore } from '../utils/FeatureStore';
import { GA_CATEGORY_ANNOUNCEMENTS } from '.';
import { ANNOUNCEMENTS_ROUTES, GA_CATEGORY_ANNOUNCEMENTS } from '.';
import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api';
import { announcementActions } from './actions';
import { createActionBindings } from '../utils/ActionBinding';
import { createReactions } from '../../stores/lib/Reaction';
import { gaEvent } from '../../lib/analytics';
import { matchRoute } from '../../helpers/routing-helpers';

const LOCAL_STORAGE_KEY = 'announcements';

Expand All @@ -22,8 +23,6 @@ const debug = require('debug')('Franz:feature:announcements:store');
export class AnnouncementsStore extends FeatureStore {
@observable targetVersion = null;

@observable isAnnouncementVisible = false;

@observable isFeatureActive = false;

@computed get changelog() {
Expand All @@ -37,6 +36,7 @@ export class AnnouncementsStore extends FeatureStore {
@computed get areNewsAvailable() {
const isChangelogAvailable = getChangelogRequest.wasExecuted && !!this.changelog;
const isAnnouncementAvailable = getAnnouncementRequest.wasExecuted && !!this.announcement;
console.log(isChangelogAvailable, isAnnouncementAvailable);
return isChangelogAvailable || isAnnouncementAvailable;
}

Expand Down Expand Up @@ -67,8 +67,9 @@ export class AnnouncementsStore extends FeatureStore {
]));

this._reactions = createReactions([
this._fetchAnnouncements,
this._showAnnouncementOnRouteMatch,
this._showAnnouncementToUsersWhoUpdatedApp,
this._fetchAnnouncements,
]);
this._registerReactions(this._reactions);
this.isFeatureActive = true;
Expand All @@ -78,7 +79,6 @@ export class AnnouncementsStore extends FeatureStore {
super.stop();
debug('AnnouncementsStore::stop');
this.isFeatureActive = false;
this.isAnnouncementVisible = false;
}

// ======= HELPERS ======= //
Expand All @@ -93,33 +93,23 @@ export class AnnouncementsStore extends FeatureStore {
// ======= ACTIONS ======= //

@action _showAnnouncement = ({ targetVersion } = {}) => {
if (!this.areNewsAvailable) return;
const { router } = this.stores;
this.targetVersion = targetVersion || this.currentVersion;
this.isAnnouncementVisible = true;
this.actions.service.blurActive();
this._updateSettings({
lastSeenAnnouncementVersion: this.currentVersion,
});
const dispose = reaction(
() => this.stores.services.active,
() => {
this._hideAnnouncement();
dispose();
},
);

const targetRoute = `/announcements/${this.targetVersion}`;
if (router.location.pathname !== targetRoute) {
this.stores.router.push(targetRoute);
}
gaEvent(GA_CATEGORY_ANNOUNCEMENTS, 'show');
};

@action _hideAnnouncement() {
this.isAnnouncementVisible = false;
}

// ======= REACTIONS ========

_showAnnouncementToUsersWhoUpdatedApp = () => {
const { announcement, isNewUser } = this;
// Check if there is an announcement and on't show announcements to new users
// Check if there is an announcement and don't show announcements to new users
if (!announcement || isNewUser) return;

// Check if the user has already used current version (= has seen the announcement)
Expand All @@ -140,5 +130,14 @@ export class AnnouncementsStore extends FeatureStore {
} else {
getAnnouncementRequest.reset();
}
};

_showAnnouncementOnRouteMatch = () => {
const { router } = this.stores;
const match = matchRoute(ANNOUNCEMENTS_ROUTES.TARGET, router.location.pathname);
if (match) {
const targetVersion = match.id;
this._showAnnouncement({ targetVersion });
}
}
}
8 changes: 5 additions & 3 deletions src/features/workspaces/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,15 @@ export default class WorkspacesStore extends FeatureStore {
_setActiveServiceOnWorkspaceSwitchReaction = () => {
if (!this.isFeatureActive) return;
if (this.activeWorkspace) {
const services = this.stores.services.allDisplayed;
const activeService = services.find(s => s.isActive);
const activeService = this.stores.services.active;
const workspaceServices = this.getWorkspaceServices(this.activeWorkspace);
if (workspaceServices.length <= 0) return;
const isActiveServiceInWorkspace = workspaceServices.includes(activeService);
if (!isActiveServiceInWorkspace) {
this.actions.service.setActive({ serviceId: workspaceServices[0].id });
this.actions.service.setActive({
serviceId: workspaceServices[0].id,
keepActiveRoute: true,
});
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ export default class ServicesStore extends Store {
gaEvent('Service', 'clear cache');
}

@action _setActive({ serviceId }) {
@action _setActive({ serviceId, keepActiveRoute }) {
if (!keepActiveRoute) this.stores.router.push('/');
const service = this.one(serviceId);

this.all.forEach((s, index) => {
Expand Down

0 comments on commit 1e38ec5

Please sign in to comment.