-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): many accessibility optimisations
fix(a11y): prevent double ids on inputs by requiring a name feat(a11y): apply aria-modal attribute and move header landmark (#48) feat(a11y): update button role and html structure of account and player pages (#47) feat(a11y): add correct text markups and aria attributes (#46) feat(home): add (geo) error message when all playlists are empty feat(a11y): add form error announcement feat(a11y): add solid header background color to ensure accessibility feat(a11y): implement aria-invalid and aria-described by to inputs on error feat(project): add google fonts from env vars feat: keyboard accessible LayoutGrid feat: optimize featured shelf slider for accessibility feat(a11y): accessible sidebar & <main> landmark feat(a11y): enhance dialog and modals accessibility fix(a11y): alt text for images for EPG fix(a11y): empty alt for image because of adjacent text alternative fix(a11y): fix arrow keys for offer radio buttons fix(a11y): skiplink first element feat(a11y): improve html structure for VideoListItem fix(e2e): cardgrid card navigation feat(a11y): apply lang attribute to custom fields feat(a11y): accessible focus outline
- Loading branch information
1 parent
7ace580
commit 0cc3463
Showing
176 changed files
with
3,128 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { PersonalShelf, PersonalShelves, PLAYLIST_LIMIT } from '@jwp/ott-common/src/constants'; | ||
import ApiService from '@jwp/ott-common/src/services/ApiService'; | ||
import { getModule } from '@jwp/ott-common/src/modules/container'; | ||
import { useFavoritesStore } from '@jwp/ott-common/src/stores/FavoritesStore'; | ||
import { useWatchHistoryStore } from '@jwp/ott-common/src/stores/WatchHistoryStore'; | ||
import { generatePlaylistPlaceholder } from '@jwp/ott-common/src/utils/collection'; | ||
import { isTruthyCustomParamValue } from '@jwp/ott-common/src/utils/common'; | ||
import { isScheduledOrLiveMedia } from '@jwp/ott-common/src/utils/liveEvent'; | ||
import type { Content } from '@jwp/ott-common/types/config'; | ||
import type { Playlist } from '@jwp/ott-common/types/playlist'; | ||
import { useQueries, useQueryClient } from 'react-query'; | ||
|
||
const placeholderData = generatePlaylistPlaceholder(30); | ||
|
||
type UsePlaylistResult = { | ||
data: Playlist | undefined; | ||
isLoading: boolean; | ||
isSuccess?: boolean; | ||
error?: unknown; | ||
}[]; | ||
|
||
const usePlaylists = (content: Content[], rowsToLoad: number | undefined = undefined) => { | ||
const page_limit = PLAYLIST_LIMIT.toString(); | ||
const queryClient = useQueryClient(); | ||
const apiService = getModule(ApiService); | ||
|
||
const favorites = useFavoritesStore((state) => state.getPlaylist()); | ||
const watchHistory = useWatchHistoryStore((state) => state.getPlaylist()); | ||
|
||
const playlistQueries = useQueries( | ||
content.map(({ contentId, type }, index) => ({ | ||
enabled: !!contentId && (!rowsToLoad || rowsToLoad > index) && !PersonalShelves.some((pType) => pType === type), | ||
queryKey: ['playlist', contentId], | ||
queryFn: async () => { | ||
const playlist = await apiService.getPlaylistById(contentId, { page_limit }); | ||
|
||
// This pre-caches all playlist items and makes navigating a lot faster. | ||
playlist?.playlist?.forEach((playlistItem) => { | ||
queryClient.setQueryData(['media', playlistItem.mediaid], playlistItem); | ||
}); | ||
|
||
return playlist; | ||
}, | ||
placeholderData: !!contentId && placeholderData, | ||
refetchInterval: (data: Playlist | undefined) => { | ||
if (!data) return false; | ||
|
||
const autoRefetch = isTruthyCustomParamValue(data.refetch) || data.playlist.some(isScheduledOrLiveMedia); | ||
|
||
return autoRefetch ? 1000 * 30 : false; | ||
}, | ||
retry: false, | ||
})), | ||
); | ||
|
||
const result: UsePlaylistResult = content.map(({ type }, index) => { | ||
if (type === PersonalShelf.Favorites) return { data: favorites, isLoading: false, isSuccess: true }; | ||
if (type === PersonalShelf.ContinueWatching) return { data: watchHistory, isLoading: false, isSuccess: true }; | ||
|
||
const { data, isLoading, isSuccess, error } = playlistQueries[index]; | ||
|
||
return { | ||
data, | ||
isLoading, | ||
isSuccess, | ||
error, | ||
}; | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export default usePlaylists; |
Oops, something went wrong.