Skip to content

Commit 8b7daf5

Browse files
enejbjsnajdr
andauthored
Add: App Banner Visibility state - hide banner in sidebar and post error views (#56772)
* AppBannerVisibility: Add UI Selectors, reducers and actions * AppBannerVisibility: Add to the App Banner Component * AppBannerVisibility: Update reader Sidebar Hide the app banner when the sidebar is open * AppBannerVisibility: Update the single post App banner visibility do not show the App Banner if the post is_error * Update to use state and new names * Use getCurrentLayoutFocus selector * Try to refresh the banner state if we have post state has changed. * Only run the call if the post is loaded. * Fixup the app banner update logic Co-authored-by: Jarda Snajdr <[email protected]>
1 parent 1cce66a commit 8b7daf5

File tree

9 files changed

+66
-2
lines changed

9 files changed

+66
-2
lines changed

client/blocks/app-banner/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getPreference, isFetchingPreferences } from 'calypso/state/preferences/
2020
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
2121
import isNotificationsOpen from 'calypso/state/selectors/is-notifications-open';
2222
import { shouldDisplayTosUpdateBanner } from 'calypso/state/selectors/should-display-tos-update-banner';
23-
import { getSectionName, getSelectedSiteId } from 'calypso/state/ui/selectors';
23+
import { getSectionName, getSelectedSiteId, appBannerIsEnabled } from 'calypso/state/ui/selectors';
2424
import {
2525
ALLOWED_SECTIONS,
2626
EDITOR,
@@ -77,7 +77,7 @@ export class AppBanner extends Component {
7777
};
7878

7979
isVisible() {
80-
const { dismissedUntil, currentSection, isTosBannerVisible } = this.props;
80+
const { dismissedUntil, currentSection, isTosBannerVisible, isAppBannerEnabled } = this.props;
8181

8282
// The ToS update banner is displayed in the same position as the mobile app banner. Since the ToS update
8383
// has higher priority, we repress all other non-essential sticky banners if the ToS update banner needs to
@@ -86,6 +86,11 @@ export class AppBanner extends Component {
8686
return false;
8787
}
8888

89+
// In some cases such as error we want to hide the app banner completely.
90+
if ( ! isAppBannerEnabled ) {
91+
return false;
92+
}
93+
8994
return this.isMobile() && ! isWpMobileApp() && ! isDismissed( dismissedUntil, currentSection );
9095
}
9196

@@ -243,6 +248,7 @@ const mapStateToProps = ( state ) => {
243248
fetchingPreferences: isFetchingPreferences( state ),
244249
siteId: getSelectedSiteId( state ),
245250
isTosBannerVisible: shouldDisplayTosUpdateBanner( state ),
251+
isAppBannerEnabled: appBannerIsEnabled( state ),
246252
};
247253
};
248254

client/blocks/reader-full-post/index.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import getCurrentStream from 'calypso/state/selectors/get-reader-current-stream'
7878
import isFeedWPForTeams from 'calypso/state/selectors/is-feed-wpforteams';
7979
import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams';
8080
import { getReaderTeams } from 'calypso/state/teams/selectors';
81+
import { disableAppBanner, enableAppBanner } from 'calypso/state/ui/actions';
8182
import ReaderFullPostHeader from './header';
8283
import ReaderFullPostContentPlaceholder from './placeholders/content';
8384
import ReaderFullPostUnavailable from './unavailable';
@@ -108,6 +109,7 @@ export class FullPostView extends Component {
108109
this.hasSentPageView = false;
109110
this.hasLoaded = false;
110111
this.attemptToSendPageView();
112+
this.maybeDisableAppBanner();
111113

112114
this.checkForCommentAnchor();
113115

@@ -131,6 +133,7 @@ export class FullPostView extends Component {
131133
this.hasSentPageView = false;
132134
this.hasLoaded = false;
133135
this.attemptToSendPageView();
136+
this.maybeDisableAppBanner();
134137
}
135138

136139
if ( this.props.shouldShowComments && ! prevProps.shouldShowComments ) {
@@ -143,6 +146,13 @@ export class FullPostView extends Component {
143146
if ( this.hasCommentAnchor && ! this.hasScrolledToCommentAnchor ) {
144147
this.scrollToComments();
145148
}
149+
150+
// Check if we just finished loading the post and enable the app banner when there's no error
151+
const finishedLoading = prevProps.post?._state === 'pending' && ! this.props.post?._state;
152+
const isError = this.props.post?.is_error;
153+
if ( finishedLoading && ! isError ) {
154+
this.props.enableAppBanner();
155+
}
146156
}
147157

148158
componentWillUnmount() {
@@ -153,6 +163,7 @@ export class FullPostView extends Component {
153163
KeyboardShortcuts.off( 'move-selection-up', this.goToPreviousPost );
154164
// Remove WPiFrameResize listener.
155165
this.stopResize?.();
166+
this.props.enableAppBanner(); // reset the app banner
156167
}
157168

158169
handleBack = ( event ) => {
@@ -297,6 +308,17 @@ export class FullPostView extends Component {
297308
}
298309
};
299310

311+
maybeDisableAppBanner = () => {
312+
const { post, site } = this.props;
313+
314+
// disable the banner while the post is loading and when it failed to load
315+
const isLoading = post?._state === 'pending';
316+
const isError = post?.is_error || site?.is_error;
317+
if ( isLoading || isError ) {
318+
this.props.disableAppBanner();
319+
}
320+
};
321+
300322
goToNextPost = () => {
301323
if ( this.props.nextPost ) {
302324
showSelectedPost( { postKey: this.props.nextPost } );
@@ -624,6 +646,8 @@ export default connect(
624646
return props;
625647
},
626648
{
649+
disableAppBanner,
650+
enableAppBanner,
627651
markPostSeen,
628652
setViewingFullPostKey,
629653
unsetViewingFullPostKey,

client/state/action-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ export const MARKETPLACE_RESET_PURCHASE_FLOW = 'MARKETPLACE_RESET_PURCHASE_FLOW'
542542
export const MARKETPLACE_SITE_TRANSFER_STATE_CHANGE = 'MARKETPLACE_SITE_TRANSFER_STATE_CHANGE';
543543
export const MARKETPLACE_SITE_TRANSFER_PLUGIN_INSTALL = 'MARKETPLACE_SITE_TRANSFER_PLUGIN_INSTALL';
544544
export const MASTERBAR_TOGGLE_VISIBILITY = 'MASTERBAR_TOGGLE_VISIBILITY';
545+
export const APP_BANNER_TOGGLE_VISIBILITY = 'APP_BANNER_TOGGLE_VISIBILITY';
545546
export const MEDIA_CLEAR_SITE = 'MEDIA_CLEAR_SITE';
546547
export const MEDIA_DELETE = 'MEDIA_DELETE';
547548
export const MEDIA_ERRORS_CLEAR = 'MEDIA_ERRORS_CLEAR';

client/state/ui/actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*/
44
export { setSection, setSectionLoading } from '../section/actions';
55
export { setSelectedSiteId, setAllSitesSelected } from './set-sites';
6+
export { disableAppBanner, enableAppBanner } from '../app-banner-visibility/actions';
67
export { showMasterbar, hideMasterbar } from '../masterbar-visibility/actions';
78
export { toggleNotificationsPanel } from './notifications';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { APP_BANNER_TOGGLE_VISIBILITY } from 'calypso/state/action-types';
2+
3+
import 'calypso/state/ui/init';
4+
5+
/**
6+
* Hide the AppBanner.
7+
*
8+
* @returns {object} Action object
9+
*/
10+
export const disableAppBanner = () => ( { type: APP_BANNER_TOGGLE_VISIBILITY, isVisible: false } );
11+
12+
/**
13+
* Show the AppBanner.
14+
*
15+
* @returns {object} Action object
16+
*/
17+
export const enableAppBanner = () => ( { type: APP_BANNER_TOGGLE_VISIBILITY, isVisible: true } );
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { APP_BANNER_TOGGLE_VISIBILITY } from 'calypso/state/action-types';
2+
3+
export default ( state = true, { type, isVisible } ) =>
4+
type === APP_BANNER_TOGGLE_VISIBILITY ? isVisible : state;

client/state/ui/reducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from 'calypso/state/action-types';
77
import { combineReducers, withSchemaValidation } from 'calypso/state/utils';
88
import actionLog from './action-log/reducer';
9+
import appBannerVisibility from './app-banner-visibility/reducer';
910
import checkout from './checkout/reducer';
1011
import language from './language/reducer';
1112
import layoutFocus from './layout-focus/reducer';
@@ -71,6 +72,7 @@ export function isNotificationsOpen( state = false, { type } ) {
7172

7273
const reducer = combineReducers( {
7374
actionLog,
75+
appBannerVisibility,
7476
checkout,
7577
isSectionLoading,
7678
isNotificationsOpen,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'calypso/state/ui/init';
2+
import { getCurrentLayoutFocus } from 'calypso/state/ui/layout-focus/selectors';
3+
4+
export default function isAppBannerEnabled( state ) {
5+
// since on mobile the sidebar layout focus take up the whole "Page" we never want to show the App Banner
6+
// when the side bar in in focus.
7+
return state.ui.appBannerVisibility && getCurrentLayoutFocus( state ) !== 'sidebar';
8+
}

client/state/ui/selectors/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { default as getSectionName } from './get-section-name';
66
export { default as getSectionGroup } from './get-section-group';
77
export { default as isSiteSection } from './is-site-section';
88
export { default as isSectionLoading } from './is-section-loading';
9+
export { default as appBannerIsEnabled } from './app-banner-is-visible';
910
export { default as masterbarIsVisible } from './masterbar-is-visible';
1011
export { default as getSidebarIsCollapsed } from './sidebar-visibility';

0 commit comments

Comments
 (0)