2023-10-17 16:14:46 +02:00
|
|
|
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;
|
2023-10-30 21:29:02 +01:00
|
|
|
year?: number;
|
2023-10-17 16:14:46 +02:00
|
|
|
poster?: string;
|
|
|
|
type: "show" | "movie";
|
2023-10-17 17:04:03 +02:00
|
|
|
updatedAt: number;
|
2023-10-17 16:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ProgressStore {
|
|
|
|
bookmarks: Record<string, BookmarkMediaItem>;
|
|
|
|
addBookmark(meta: PlayerMeta): void;
|
|
|
|
removeBookmark(id: string): void;
|
2023-10-30 21:29:02 +01:00
|
|
|
replaceBookmarks(items: Record<string, BookmarkMediaItem>): void;
|
2023-10-17 16:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-10-17 17:04:03 +02:00
|
|
|
updatedAt: Date.now(),
|
2023-10-17 16:14:46 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2023-10-30 21:29:02 +01:00
|
|
|
replaceBookmarks(items: Record<string, BookmarkMediaItem>) {
|
|
|
|
set((s) => {
|
|
|
|
s.bookmarks = items;
|
|
|
|
});
|
|
|
|
},
|
2023-10-17 16:14:46 +02:00
|
|
|
})),
|
|
|
|
{
|
|
|
|
name: "__MW::bookmarks",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|