mirror of
https://github.com/movie-web/movie-web.git
synced 2025-01-30 03:16:52 +01:00
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
|
import { create } from "zustand";
|
||
|
import { persist } from "zustand/middleware";
|
||
|
import { immer } from "zustand/middleware/immer";
|
||
|
|
||
|
import { PlayerMeta } from "@/stores/player/slices/source";
|
||
|
|
||
|
export interface BookmarkMediaItem {
|
||
|
title: string;
|
||
|
year: number;
|
||
|
poster?: string;
|
||
|
type: "show" | "movie";
|
||
|
}
|
||
|
|
||
|
export interface ProgressStore {
|
||
|
bookmarks: Record<string, BookmarkMediaItem>;
|
||
|
addBookmark(meta: PlayerMeta): void;
|
||
|
removeBookmark(id: string): void;
|
||
|
}
|
||
|
|
||
|
// TODO add migration from previous bookmark store
|
||
|
export const useBookmarkStore = create(
|
||
|
persist(
|
||
|
immer<ProgressStore>((set) => ({
|
||
|
bookmarks: {},
|
||
|
removeBookmark(id) {
|
||
|
set((s) => {
|
||
|
delete s.bookmarks[id];
|
||
|
});
|
||
|
},
|
||
|
addBookmark(meta) {
|
||
|
set((s) => {
|
||
|
s.bookmarks[meta.tmdbId] = {
|
||
|
type: meta.type,
|
||
|
title: meta.title,
|
||
|
year: meta.releaseYear,
|
||
|
poster: meta.poster,
|
||
|
};
|
||
|
});
|
||
|
},
|
||
|
})),
|
||
|
{
|
||
|
name: "__MW::bookmarks",
|
||
|
}
|
||
|
)
|
||
|
);
|