Skip to content

Commit

Permalink
feat(entitlement): prevent UI blocking while loading auth or subscrip…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ChristiaanScheermeijer committed May 23, 2022
1 parent a474b2a commit fefab30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/screens/Movie/Movie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Movie = ({ match, location }: RouteComponentProps<MovieRouteParams>): JSX.

// User, entitlement
const { user, subscription } = useAccountStore(({ user, subscription }) => ({ user, subscription }), shallow);
const { isEntitled, isMediaEntitlementLoading, mediaOffers } = useEntitlement(item);
const { isEntitled, mediaOffers } = useEntitlement(item);
const setRequestedMediaOffers = useCheckoutStore((s) => s.setRequestedMediaOffers);

// Handlers
Expand Down Expand Up @@ -93,8 +93,8 @@ const Movie = ({ match, location }: RouteComponentProps<MovieRouteParams>): JSX.

const startWatchingLabel = useMemo((): string => {
if (isEntitled) return typeof progress === 'number' ? t('continue_watching') : t('start_watching');
if (!user) return t('sign_up_to_start_watching');
if (mediaOffers.length) return t('buy');
if (!user) return t('sign_up_to_start_watching');

return t('complete_your_subscription');
}, [isEntitled, user, mediaOffers, progress, t]);
Expand Down Expand Up @@ -130,7 +130,7 @@ const Movie = ({ match, location }: RouteComponentProps<MovieRouteParams>): JSX.
}, [isEntitled, mediaOffers, setRequestedMediaOffers]);

// UI
if ((isLoading && !item) || isMediaEntitlementLoading) return <LoadingOverlay />;
if (isLoading && !item) return <LoadingOverlay />;
if ((!isLoading && error) || !item) return <ErrorPage title={t('video_not_found')} />;

const pageTitle = `${item.title} - ${siteName}`;
Expand Down
6 changes: 3 additions & 3 deletions src/screens/Series/Series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Series = ({ match, location }: RouteComponentProps<SeriesRouteParams>): JS

// User, entitlement
const { user, subscription } = useAccountStore(({ user, subscription }) => ({ user, subscription }), shallow);
const { isEntitled, isMediaEntitlementLoading, mediaOffers } = useEntitlement(item);
const { isEntitled, mediaOffers } = useEntitlement(item);

// Handlers
const goBack = () => item && seriesPlaylist && history.push(episodeURL(seriesPlaylist, item.mediaid, false));
Expand Down Expand Up @@ -98,8 +98,8 @@ const Series = ({ match, location }: RouteComponentProps<SeriesRouteParams>): JS

const startWatchingLabel = useMemo((): string => {
if (isEntitled) return typeof progress === 'number' ? t('continue_watching') : t('start_watching');
if (!user) return t('sign_up_to_start_watching');
if (mediaOffers.length) return t('buy');
if (!user) return t('sign_up_to_start_watching');

return t('complete_your_subscription');
}, [isEntitled, progress, user, mediaOffers, t]);
Expand Down Expand Up @@ -131,7 +131,7 @@ const Series = ({ match, location }: RouteComponentProps<SeriesRouteParams>): JS
}, [history, searchParams, seriesPlaylist]);

// UI
if ((!item && isLoading) || playlistIsLoading || !searchParams.has('e') || isMediaEntitlementLoading) return <LoadingOverlay />;
if ((!item && isLoading) || playlistIsLoading || !searchParams.has('e')) return <LoadingOverlay />;
if ((!isLoading && error) || !item) return <ErrorPage title={t('episode_not_found')} />;
if (playlistError || !seriesPlaylist) return <ErrorPage title={t('series_not_found')} />;

Expand Down

0 comments on commit fefab30

Please sign in to comment.