mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 09:45:33 +00:00
fix groups (collections) not syncing correctly
This commit is contained in:
parent
3b4b891535
commit
1c05f99b3e
2 changed files with 38 additions and 8 deletions
|
|
@ -29,6 +29,8 @@ export interface BookmarkUpdateItem {
|
|||
poster?: string;
|
||||
type?: "show" | "movie";
|
||||
group?: string[];
|
||||
/** Groups before modification - used to sync removals to Trakt lists */
|
||||
previousGroup?: string[];
|
||||
favoriteEpisodes?: string[];
|
||||
action: "delete" | "add";
|
||||
}
|
||||
|
|
@ -115,6 +117,7 @@ export const useBookmarkStore = create(
|
|||
},
|
||||
addBookmarkWithGroups(meta, groups) {
|
||||
set((s) => {
|
||||
const existingBookmark = s.bookmarks[meta.tmdbId];
|
||||
updateId += 1;
|
||||
const item: BookmarkUpdateItem = {
|
||||
id: updateId.toString(),
|
||||
|
|
@ -125,6 +128,7 @@ export const useBookmarkStore = create(
|
|||
year: meta.releaseYear,
|
||||
poster: meta.poster,
|
||||
group: groups,
|
||||
previousGroup: existingBookmark?.group,
|
||||
};
|
||||
s.updateQueue.push(item);
|
||||
s.traktUpdateQueue.push(item);
|
||||
|
|
@ -245,13 +249,13 @@ export const useBookmarkStore = create(
|
|||
set((s) => {
|
||||
const { modifiedBookmarks, result: modificationResult } =
|
||||
modifyBookmarks(s.bookmarks, bookmarkIds, options);
|
||||
s.bookmarks = modifiedBookmarks;
|
||||
result = modificationResult;
|
||||
|
||||
// Add to update queue for modified bookmarks
|
||||
// Add to update queue for modified bookmarks (capture previousGroup before overwriting)
|
||||
if (result.hasChanges) {
|
||||
result.modifiedIds.forEach((bookmarkId) => {
|
||||
const bookmark = s.bookmarks[bookmarkId];
|
||||
const originalBookmark = s.bookmarks[bookmarkId];
|
||||
const bookmark = modifiedBookmarks[bookmarkId];
|
||||
if (bookmark) {
|
||||
updateId += 1;
|
||||
const item: BookmarkUpdateItem = {
|
||||
|
|
@ -263,6 +267,7 @@ export const useBookmarkStore = create(
|
|||
poster: bookmark.poster,
|
||||
type: bookmark.type,
|
||||
group: bookmark.group,
|
||||
previousGroup: originalBookmark?.group,
|
||||
favoriteEpisodes: bookmark.favoriteEpisodes,
|
||||
};
|
||||
s.updateQueue.push(item);
|
||||
|
|
@ -270,6 +275,8 @@ export const useBookmarkStore = create(
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
s.bookmarks = modifiedBookmarks;
|
||||
});
|
||||
|
||||
return result;
|
||||
|
|
@ -285,13 +292,13 @@ export const useBookmarkStore = create(
|
|||
set((s) => {
|
||||
const { modifiedBookmarks, result: modificationResult } =
|
||||
modifyBookmarksByGroup(s.bookmarks, options);
|
||||
s.bookmarks = modifiedBookmarks;
|
||||
result = modificationResult;
|
||||
|
||||
// Add to update queue for modified bookmarks
|
||||
// Add to update queue for modified bookmarks (capture previousGroup before overwriting)
|
||||
if (result.hasChanges) {
|
||||
result.modifiedIds.forEach((bookmarkId) => {
|
||||
const bookmark = s.bookmarks[bookmarkId];
|
||||
const originalBookmark = s.bookmarks[bookmarkId];
|
||||
const bookmark = modifiedBookmarks[bookmarkId];
|
||||
if (bookmark) {
|
||||
updateId += 1;
|
||||
const item: BookmarkUpdateItem = {
|
||||
|
|
@ -303,6 +310,7 @@ export const useBookmarkStore = create(
|
|||
poster: bookmark.poster,
|
||||
type: bookmark.type,
|
||||
group: bookmark.group,
|
||||
previousGroup: originalBookmark?.group,
|
||||
favoriteEpisodes: bookmark.favoriteEpisodes,
|
||||
};
|
||||
s.updateQueue.push(item);
|
||||
|
|
@ -310,6 +318,8 @@ export const useBookmarkStore = create(
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
s.bookmarks = modifiedBookmarks;
|
||||
});
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -70,8 +70,28 @@ export function TraktBookmarkSyncer() {
|
|||
|
||||
if (item.action === "add") {
|
||||
await traktService.addToWatchlist(contentData);
|
||||
if (hasLists && item.group?.length) {
|
||||
for (const groupName of item.group) {
|
||||
if (hasLists) {
|
||||
const newGroups = item.group ?? [];
|
||||
const prevGroups = item.previousGroup ?? [];
|
||||
|
||||
// Remove from Trakt lists that the bookmark no longer belongs to
|
||||
const groupsToRemove = prevGroups.filter(
|
||||
(g) => !newGroups.includes(g),
|
||||
);
|
||||
for (const groupName of groupsToRemove) {
|
||||
const list = await findListByName(slug!, groupName);
|
||||
if (list) {
|
||||
await traktService.removeFromList(slug!, listId(list), [
|
||||
contentData,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to Trakt lists that are new
|
||||
const groupsToAdd = newGroups.filter(
|
||||
(g) => !prevGroups.includes(g),
|
||||
);
|
||||
for (const groupName of groupsToAdd) {
|
||||
const list = await ensureListExists(slug!, groupName);
|
||||
if (list) {
|
||||
await traktService.addToList(slug!, listId(list), [
|
||||
|
|
|
|||
Loading…
Reference in a new issue