Skip to content

Commit

Permalink
feat: adjust logic for sending favorites and continue watching playli…
Browse files Browse the repository at this point in the history
…st id
  • Loading branch information
CarinaDraganJW committed May 5, 2023
1 parent b8200ad commit fbda6dc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/stores/FavoritesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const restoreFavorites = async () => {

const favorites = (playlistItems || []).map((item) => createFavorite(item));

useFavoritesStore.setState({ favorites });
useFavoritesStore.setState({ favorites, favoritesPlaylistId: favoritesList });
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/stores/FavoritesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Playlist, PlaylistItem } from '#types/playlist';
type FavoritesState = {
favorites: Favorite[];
warning: string | null;
favoritesPlaylistId: string;
hasItem: (item: PlaylistItem) => boolean;
getPlaylist: () => Playlist;
setWarning: (warning: string) => void;
Expand All @@ -16,12 +17,13 @@ type FavoritesState = {
export const useFavoritesStore = createStore<FavoritesState>('FavoritesState', (set, get) => ({
favorites: [],
warning: null,
favoritesPlaylistId: PersonalShelf.Favorites,
setWarning: (message: string | null) => set({ warning: message }),
clearWarning: () => set({ warning: null }),
hasItem: (item: PlaylistItem) => get().favorites.some((favoriteItem) => favoriteItem.mediaid === item.mediaid),
getPlaylist: () =>
({
feedid: PersonalShelf.Favorites,
feedid: get().favoritesPlaylistId || PersonalShelf.Favorites,
title: 'Favorites',
playlist: get().favorites.map(({ playlistItem }) => playlistItem),
} as Playlist),
Expand Down
1 change: 1 addition & 0 deletions src/stores/WatchHistoryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const restoreWatchHistory = async () => {
useWatchHistoryStore.setState({
watchHistory: watchHistory.filter((item): item is WatchHistoryItem => !!item?.mediaid),
playlistItemsLoaded: true,
continueWatchingPlaylistId: continueWatchingList,
});
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/stores/WatchHistoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Playlist, PlaylistItem } from '#types/playlist';
type WatchHistoryState = {
watchHistory: WatchHistoryItem[];
playlistItemsLoaded: boolean;
continueWatchingPlaylistId: string;
getItem: (item: PlaylistItem) => WatchHistoryItem | undefined;
getPlaylist: () => Playlist;
getDictionary: () => { [key: string]: number };
Expand All @@ -16,13 +17,14 @@ type WatchHistoryState = {
export const useWatchHistoryStore = createStore<WatchHistoryState>('WatchHistoryStore', (_, get) => ({
watchHistory: [],
playlistItemsLoaded: false,
continueWatchingPlaylistId: PersonalShelf.ContinueWatching,
getItem: (item: PlaylistItem) =>
get().watchHistory.find(({ mediaid, progress }) => {
return mediaid === item.mediaid && progress > VideoProgressMinMax.Min && progress < VideoProgressMinMax.Max;
}),
getPlaylist: () =>
({
feedid: PersonalShelf.ContinueWatching,
feedid: get().continueWatchingPlaylistId || PersonalShelf.ContinueWatching,
title: 'Continue watching',
playlist: get()
.watchHistory.filter(({ playlistItem, progress }) => !!playlistItem && progress > VideoProgressMinMax.Min && progress < VideoProgressMinMax.Max)
Expand Down

0 comments on commit fbda6dc

Please sign in to comment.