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, youtubeChannelImportErrorMessage: string,
referrerSetIsPending: boolean, referrerSetIsPending: boolean,
referrerSetError: string, referrerSetError: string,
odyseeMembershipName: ?string, // undefined: not fetched, '': no membership
odyseeMembershipsPerClaimIds: ?{ [string]: string }, odyseeMembershipsPerClaimIds: ?{ [string]: string },
locale: ?LocaleInfo, locale: ?LocaleInfo,
}; };

View file

@ -19,7 +19,7 @@ type HeaderMenuButtonProps = {
user: ?User, user: ?User,
handleThemeToggle: (boolean, string) => void, handleThemeToggle: (boolean, string) => void,
doOpenModal: (string, {}) => void, doOpenModal: (string, {}) => void,
odyseeMembership: string, odyseeMembership: ?string,
}; };
export default function HeaderMenuButtons(props: HeaderMenuButtonProps) { export default function HeaderMenuButtons(props: HeaderMenuButtonProps) {

View file

@ -138,7 +138,7 @@ type Props = {
user: ?User, user: ?User,
homepageData: any, homepageData: any,
doClearClaimSearch: () => void, doClearClaimSearch: () => void,
odyseeMembership: string, odyseeMembership: ?string,
odyseeMembershipByUri: (uri: string) => string, odyseeMembershipByUri: (uri: string) => string,
doFetchLastActiveSubs: (force?: boolean, count?: number) => void, doFetchLastActiveSubs: (force?: boolean, count?: number) => void,
}; };

View file

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

View file

@ -155,7 +155,7 @@ export function doCheckUserOdyseeMemberships(user) {
dispatch({ dispatch({
type: ACTIONS.ADD_ODYSEE_MEMBERSHIP_DATA, 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: '', youtubeChannelImportErrorMessage: '',
referrerSetIsPending: false, referrerSetIsPending: false,
referrerSetError: '', referrerSetError: '',
odyseeMembershipName: undefined,
odyseeMembershipsPerClaimIds: undefined, odyseeMembershipsPerClaimIds: undefined,
locale: undefined, locale: undefined,
homepageFetched: false, homepageFetched: false,

View file

@ -106,30 +106,32 @@ export const selectYouTubeImportError = (state) => selectState(state).youtubeCha
export const selectSetReferrerPending = (state) => selectState(state).referrerSetIsPending; export const selectSetReferrerPending = (state) => selectState(state).referrerSetIsPending;
export const selectSetReferrerError = (state) => selectState(state).referrerSetError; export const selectSetReferrerError = (state) => selectState(state).referrerSetError;
// undefined = not fetched
// '' = no membership
// '<name>' = membership name
export const selectOdyseeMembershipName = (state) => selectState(state).odyseeMembershipName; export const selectOdyseeMembershipName = (state) => selectState(state).odyseeMembershipName;
/**
* @param state
* @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise.
*/
export const selectOdyseeMembershipIsPremiumPlus = (state) => { export const selectOdyseeMembershipIsPremiumPlus = (state) => {
const odyseeMembershipName = selectState(state).odyseeMembershipName; const name = selectOdyseeMembershipName(state);
if (!odyseeMembershipName) return undefined; return name === undefined ? undefined : name === 'Premium+';
return selectState(state).odyseeMembershipName === 'Premium+';
}; };
/** /**
* selectHasOdyseeMembership
*
* @param state * @param state
* @returns 'undefined' if not yet fetched; boolean otherwise. * @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise.
*/ */
export const selectHasOdyseeMembership = (state) => { export const selectHasOdyseeMembership = (state) => {
// @if process.env.NODE_ENV!='production' // @if process.env.NODE_ENV!='production'
const override = window.localStorage.getItem('hasMembershipOverride'); const override = window.localStorage.getItem('hasMembershipOverride');
if (override) { if (override) return override === 'true';
return override === 'true';
}
// @endif // @endif
const membership = selectOdyseeMembershipName(state); const name = selectOdyseeMembershipName(state);
return membership === undefined ? membership : Boolean(membership); return name === undefined ? undefined : Boolean(name);
}; };
export const selectYouTubeImportVideosComplete = createSelector(selectState, (state) => { export const selectYouTubeImportVideosComplete = createSelector(selectState, (state) => {