diff --git a/flow-typed/user.js b/flow-typed/user.js index ce2c70acf..410f007ca 100644 --- a/flow-typed/user.js +++ b/flow-typed/user.js @@ -64,6 +64,7 @@ declare type UserState ={ youtubeChannelImportErrorMessage: string, referrerSetIsPending: boolean, referrerSetError: string, + odyseeMembershipName: ?string, // undefined: not fetched, '': no membership odyseeMembershipsPerClaimIds: ?{ [string]: string }, locale: ?LocaleInfo, }; diff --git a/ui/component/headerMenuButtons/view.jsx b/ui/component/headerMenuButtons/view.jsx index ffe52fd24..a2da8cb20 100644 --- a/ui/component/headerMenuButtons/view.jsx +++ b/ui/component/headerMenuButtons/view.jsx @@ -19,7 +19,7 @@ type HeaderMenuButtonProps = { user: ?User, handleThemeToggle: (boolean, string) => void, doOpenModal: (string, {}) => void, - odyseeMembership: string, + odyseeMembership: ?string, }; export default function HeaderMenuButtons(props: HeaderMenuButtonProps) { diff --git a/ui/component/sideNavigation/view.jsx b/ui/component/sideNavigation/view.jsx index 318150348..335a8d822 100644 --- a/ui/component/sideNavigation/view.jsx +++ b/ui/component/sideNavigation/view.jsx @@ -138,7 +138,7 @@ type Props = { user: ?User, homepageData: any, doClearClaimSearch: () => void, - odyseeMembership: string, + odyseeMembership: ?string, odyseeMembershipByUri: (uri: string) => string, doFetchLastActiveSubs: (force?: boolean, count?: number) => void, }; diff --git a/ui/page/home/view.jsx b/ui/page/home/view.jsx index a8edd0dd8..667fc6303 100644 --- a/ui/page/home/view.jsx +++ b/ui/page/home/view.jsx @@ -44,7 +44,7 @@ type Props = { adBlockerFound: ?boolean, homepageOrder: HomepageOrder, doOpenModal: (id: string, ?{}) => void, - hasMembership: boolean, + hasMembership: ?boolean, }; function HomePage(props: Props) { diff --git a/ui/redux/actions/user.js b/ui/redux/actions/user.js index c4599514c..54b61514c 100644 --- a/ui/redux/actions/user.js +++ b/ui/redux/actions/user.js @@ -155,7 +155,7 @@ export function doCheckUserOdyseeMemberships(user) { dispatch({ type: ACTIONS.ADD_ODYSEE_MEMBERSHIP_DATA, - data: { user, odyseeMembershipName: highestMembershipRanking }, + data: { user, odyseeMembershipName: highestMembershipRanking || '' }, // '' = none; `undefined` = not fetched }); }; } diff --git a/ui/redux/reducers/user.js b/ui/redux/reducers/user.js index 3afa092f0..7c7371a18 100644 --- a/ui/redux/reducers/user.js +++ b/ui/redux/reducers/user.js @@ -30,6 +30,7 @@ const defaultState: UserState = { youtubeChannelImportErrorMessage: '', referrerSetIsPending: false, referrerSetError: '', + odyseeMembershipName: undefined, odyseeMembershipsPerClaimIds: undefined, locale: undefined, homepageFetched: false, diff --git a/ui/redux/selectors/user.js b/ui/redux/selectors/user.js index cd1a3732d..dd877e93b 100644 --- a/ui/redux/selectors/user.js +++ b/ui/redux/selectors/user.js @@ -106,30 +106,32 @@ export const selectYouTubeImportError = (state) => selectState(state).youtubeCha export const selectSetReferrerPending = (state) => selectState(state).referrerSetIsPending; export const selectSetReferrerError = (state) => selectState(state).referrerSetError; +// undefined = not fetched +// '' = no membership +// '' = membership name export const selectOdyseeMembershipName = (state) => selectState(state).odyseeMembershipName; +/** + * @param state + * @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise. + */ export const selectOdyseeMembershipIsPremiumPlus = (state) => { - const odyseeMembershipName = selectState(state).odyseeMembershipName; - if (!odyseeMembershipName) return undefined; - return selectState(state).odyseeMembershipName === 'Premium+'; + const name = selectOdyseeMembershipName(state); + return name === undefined ? undefined : name === 'Premium+'; }; /** - * selectHasOdyseeMembership - * * @param state - * @returns 'undefined' if not yet fetched; boolean otherwise. + * @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise. */ export const selectHasOdyseeMembership = (state) => { // @if process.env.NODE_ENV!='production' const override = window.localStorage.getItem('hasMembershipOverride'); - if (override) { - return override === 'true'; - } + if (override) return override === 'true'; // @endif - const membership = selectOdyseeMembershipName(state); - return membership === undefined ? membership : Boolean(membership); + const name = selectOdyseeMembershipName(state); + return name === undefined ? undefined : Boolean(name); }; export const selectYouTubeImportVideosComplete = createSelector(selectState, (state) => {