Skip to content

Commit

Permalink
chore: ensure backward compatibility of videos state
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Aug 31, 2022
1 parent d081523 commit 0c58882
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/store/utils/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,33 @@ export const preloadState = async () => {
if (videos) {
dispatch(
setVideos({
list: removeOutdatedVideos(videos.list, settings),
list: removeOutdatedVideos(
replaceViewedFlagWithSeen(videos.list),
settings,
),
}),
);
}
}
dispatch(setApp({ loaded: true }), shouldPersist);
};

const replaceViewedFlagWithSeen = (videos: VideoCache[]) => {
return videos.map((video) => {
const { viewed, ...flags } =
(video.flags as typeof video.flags & { viewed: boolean }) || {};
return {
...video,
flags: viewed
? {
...flags,
seen: viewed,
}
: flags,
};
});
};

const removeOutdatedVideos = (videos: VideoCache[], settings: Settings) => {
log('Removing outdated videos.');
return videos.filter(
Expand Down

0 comments on commit 0c58882

Please sign in to comment.