Membership-name state updates

- Corrected flow definitions.
- Properly differentiate between "not yet fetched" and "no membership" as "undefined" and "<empty string>", respectively. There are GUI elements that need to know the unfetched case.
This commit is contained in:
infinite-persistence 2022-05-04 10:17:59 +08:00
parent a770e0a8a9
commit cd2998d695
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
7 changed files with 19 additions and 15 deletions

1
flow-typed/user.js vendored
View file

@ -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,
};

View file

@ -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) {

View file

@ -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,
};

View file

@ -44,7 +44,7 @@ type Props = {
adBlockerFound: ?boolean,
homepageOrder: HomepageOrder,
doOpenModal: (id: string, ?{}) => void,
hasMembership: boolean,
hasMembership: ?boolean,
};
function HomePage(props: Props) {

View file

@ -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
});
};
}

View file

@ -30,6 +30,7 @@ const defaultState: UserState = {
youtubeChannelImportErrorMessage: '',
referrerSetIsPending: false,
referrerSetError: '',
odyseeMembershipName: undefined,
odyseeMembershipsPerClaimIds: undefined,
locale: undefined,
homepageFetched: false,

View file

@ -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
// '<name>' = 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) => {