mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:53:24 +00:00
feat: watch history store
This commit is contained in:
@@ -19,10 +19,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@expo/metro-config": "^0.17.3",
|
||||
"@movie-web/api": "*",
|
||||
"@movie-web/colors": "*",
|
||||
"@movie-web/provider-utils": "*",
|
||||
"@movie-web/tmdb": "*",
|
||||
"@movie-web/api": "*",
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@react-native-anywhere/polyfill-base64": "0.0.1-alpha.0",
|
||||
"@react-navigation/native": "^6.1.9",
|
||||
@@ -90,7 +90,7 @@
|
||||
"babel-plugin-module-resolver": "^5.0.0",
|
||||
"eslint": "^8.56.0",
|
||||
"prettier": "^3.1.1",
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.4.3"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
|
@@ -7,6 +7,7 @@ import { createJSONStorage, persist } from "zustand/middleware";
|
||||
import type { ItemData } from "~/components/item/item";
|
||||
import type { DownloadItem } from "~/hooks/DownloadManagerContext";
|
||||
import type { ThemeStoreOption } from "~/stores/theme";
|
||||
import type { ScrapeMedia } from "@movie-web/provider-utils";
|
||||
|
||||
const storage = new MMKV();
|
||||
|
||||
@@ -97,6 +98,7 @@ export const useDownloadHistoryStore = create<
|
||||
|
||||
interface BookmarkStoreState {
|
||||
bookmarks: ItemData[];
|
||||
setBookmarks: (bookmarks: ItemData[]) => void;
|
||||
addBookmark: (item: ItemData) => void;
|
||||
removeBookmark: (item: ItemData) => void;
|
||||
isBookmarked: (item: ItemData) => boolean;
|
||||
@@ -109,6 +111,7 @@ export const useBookmarkStore = create<
|
||||
persist(
|
||||
(set, get) => ({
|
||||
bookmarks: [],
|
||||
setBookmarks: (bookmarks: ItemData[]) => set({ bookmarks }),
|
||||
addBookmark: (item: ItemData) =>
|
||||
set((state) => ({
|
||||
bookmarks: [...state.bookmarks, item],
|
||||
@@ -128,3 +131,52 @@ export const useBookmarkStore = create<
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
interface WatchHistoryItem {
|
||||
item: ItemData;
|
||||
media: ScrapeMedia;
|
||||
positionMillis: number;
|
||||
}
|
||||
|
||||
interface WatchHistoryStoreState {
|
||||
watchHistory: WatchHistoryItem[];
|
||||
setWatchHistory: (watchHistory: WatchHistoryItem[]) => void;
|
||||
addToWatchHistory: (item: ItemData, media: ScrapeMedia) => void;
|
||||
removeFromWatchHistory: (item: ItemData) => void;
|
||||
}
|
||||
|
||||
export const useWatchHistoryStore = create<
|
||||
WatchHistoryStoreState,
|
||||
[["zustand/persist", WatchHistoryStoreState]]
|
||||
>(
|
||||
persist(
|
||||
(set) => ({
|
||||
watchHistory: [],
|
||||
setWatchHistory: (watchHistory: WatchHistoryItem[]) =>
|
||||
set({ watchHistory }),
|
||||
addToWatchHistory: (item: ItemData, media: ScrapeMedia) =>
|
||||
set((state) => ({
|
||||
watchHistory: [
|
||||
...state.watchHistory.filter(
|
||||
(historyItem) => historyItem.item.id !== item.id,
|
||||
),
|
||||
{
|
||||
item,
|
||||
media,
|
||||
positionMillis: 0,
|
||||
},
|
||||
],
|
||||
})),
|
||||
removeFromWatchHistory: (item: ItemData) =>
|
||||
set((state) => ({
|
||||
watchHistory: state.watchHistory.filter(
|
||||
(historyItem) => historyItem.item.id !== item.id,
|
||||
),
|
||||
}),
|
||||
)}),
|
||||
{
|
||||
name: "watch-history",
|
||||
storage: createJSONStorage(() => zustandStorage),
|
||||
},
|
||||
),
|
||||
);
|
@@ -23,7 +23,7 @@
|
||||
"@turbo/gen": "^1.11.3",
|
||||
"prettier": "^3.1.1",
|
||||
"turbo": "^1.11.3",
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.4.3"
|
||||
},
|
||||
"prettier": "@movie-web/prettier-config",
|
||||
"pnpm": {}
|
||||
|
715
pnpm-lock.yaml
generated
715
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user