diff --git a/src/backend/accounts/import.ts b/src/backend/accounts/import.ts index d7dd6a23..e106f902 100644 --- a/src/backend/accounts/import.ts +++ b/src/backend/accounts/import.ts @@ -6,7 +6,7 @@ import { AccountWithToken } from "@/stores/auth"; import { BookmarkInput } from "./bookmarks"; import { ProgressInput } from "./progress"; import { SettingsInput } from "./settings"; -import { WatchHistoryInput, watchHistoryItemsToInputs } from "./watchHistory"; +import { WatchHistoryInput } from "./watchHistory"; export function importProgress( url: string, diff --git a/src/hooks/auth/useMigration.ts b/src/hooks/auth/useMigration.ts index 165a42bc..f0df3b3a 100644 --- a/src/hooks/auth/useMigration.ts +++ b/src/hooks/auth/useMigration.ts @@ -18,13 +18,13 @@ import { importSettings, importWatchHistory, } from "@/backend/accounts/import"; -import { watchHistoryItemsToInputs } from "@/backend/accounts/watchHistory"; // import { getLoginChallengeToken, loginAccount } from "@/backend/accounts/login"; import { progressMediaItemToInputs } from "@/backend/accounts/progress"; import { getRegisterChallengeToken, registerAccount, } from "@/backend/accounts/register"; +import { watchHistoryItemsToInputs } from "@/backend/accounts/watchHistory"; // import { removeSession } from "@/backend/accounts/sessions"; // import { getSettings } from "@/backend/accounts/settings"; // import { @@ -186,7 +186,14 @@ export function useMigration() { bytesToBase64(keys.seed), ); - await importData(backendUrl, account, progress, watchHistory, bookmarks, groupOrder); + await importData( + backendUrl, + account, + progress, + watchHistory, + bookmarks, + groupOrder, + ); return account; }, diff --git a/src/pages/migration/MigrationDownload.tsx b/src/pages/migration/MigrationDownload.tsx index 76c279d5..24058d97 100644 --- a/src/pages/migration/MigrationDownload.tsx +++ b/src/pages/migration/MigrationDownload.tsx @@ -108,7 +108,7 @@ export function MigrationDownloadPage() { console.error("Error during data download:", error); setStatus("error"); } - }, [ + }, [ bookmarks, progress, watchHistory, @@ -174,13 +174,16 @@ export function MigrationDownloadPage() {
- + {t("migration.preview.items.watchHistory")}
- {Object.keys(persistedWatchHistory.items || watchHistory).length} + { + Object.keys(persistedWatchHistory.items || watchHistory) + .length + }
diff --git a/src/pages/migration/MigrationUpload.tsx b/src/pages/migration/MigrationUpload.tsx index fd6b304e..3723a60f 100644 --- a/src/pages/migration/MigrationUpload.tsx +++ b/src/pages/migration/MigrationUpload.tsx @@ -10,8 +10,8 @@ import { importSettings, importWatchHistory, } from "@/backend/accounts/import"; -import { watchHistoryItemsToInputs } from "@/backend/accounts/watchHistory"; import { progressMediaItemToInputs } from "@/backend/accounts/progress"; +import { watchHistoryItemsToInputs } from "@/backend/accounts/watchHistory"; import { Button } from "@/components/buttons/Button"; import { Icon, Icons } from "@/components/Icon"; import { SettingsCard } from "@/components/layout/SettingsCard"; @@ -157,7 +157,10 @@ export function MigrationUploadPage() { typeof item.watchedAt === "number" ? item.watchedAt : Date.now(), - completed: typeof item.completed === "boolean" ? item.completed : false, + completed: + typeof item.completed === "boolean" + ? item.completed + : false, episodeId: item.episodeId, seasonId: item.seasonId, seasonNumber: item.seasonNumber, @@ -214,7 +217,9 @@ export function MigrationUploadPage() { uploadedData.watchHistory && Object.keys(uploadedData.watchHistory).length > 0 ) { - const watchHistoryInputs = watchHistoryItemsToInputs(uploadedData.watchHistory); + const watchHistoryInputs = watchHistoryItemsToInputs( + uploadedData.watchHistory, + ); importPromises.push( importWatchHistory(backendUrl, user.account, watchHistoryInputs), ); @@ -296,6 +301,7 @@ export function MigrationUploadPage() { }, [ replaceBookmarks, replaceProgress, + replaceWatchHistory, uploadedData, user.account, handleBackendImport, @@ -494,6 +500,7 @@ export function MigrationUploadPage() { uploadedData, replaceBookmarks, replaceProgress, + replaceWatchHistory, setGroupOrder, preferencesStore, subtitleStore, @@ -639,7 +646,7 @@ export function MigrationUploadPage() {
- + {t("migration.preview.items.watchHistory")} diff --git a/src/stores/progress/index.ts b/src/stores/progress/index.ts index 70ca5059..8cea9847 100644 --- a/src/stores/progress/index.ts +++ b/src/stores/progress/index.ts @@ -142,7 +142,9 @@ export const useProgressStore = create( watched: 0, }; - const wasCompleted = item.progress.duration > 0 && item.progress.watched / item.progress.duration > 0.9; + const wasCompleted = + item.progress.duration > 0 && + item.progress.watched / item.progress.duration > 0.9; item.progress = { ...progress }; // Update watch history only if becoming completed @@ -178,7 +180,9 @@ export const useProgressStore = create( }; const episodeItem = item.episodes[meta.episode.tmdbId]; - const wasCompleted = episodeItem.progress.duration > 0 && episodeItem.progress.watched / episodeItem.progress.duration > 0.9; + const wasCompleted = + episodeItem.progress.duration > 0 && + episodeItem.progress.watched / episodeItem.progress.duration > 0.9; episodeItem.progress = { ...progress }; // Update watch history only if becoming completed diff --git a/src/stores/watchHistory/index.ts b/src/stores/watchHistory/index.ts index f6c36070..7e0b3092 100644 --- a/src/stores/watchHistory/index.ts +++ b/src/stores/watchHistory/index.ts @@ -76,7 +76,8 @@ export const useWatchHistoryStore = create( // Only add/update if this is a completion or if the item doesn't exist yet const existingItem = s.items[key]; - const shouldUpdate = !existingItem || (completed && !existingItem.completed); + const shouldUpdate = + !existingItem || (completed && !existingItem.completed); if (!shouldUpdate) return; @@ -128,7 +129,9 @@ export const useWatchHistoryStore = create( // add to updateQueue updateId += 1; s.updateQueue.push({ - tmdbId: existingItem.episodeId ? existingItem.seasonId || id.split("-")[0] : id, + tmdbId: existingItem.episodeId + ? existingItem.seasonId || id.split("-")[0] + : id, title: existingItem.title, year: existingItem.year, poster: existingItem.poster,