Skip to content

Commit 750ee44

Browse files
committed
feat(panel): adds watched history toggle support
1 parent 0157df6 commit 750ee44

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

src/components/views/panel/MoviePanel.vue

+23-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '~/components/views/panel/use-panel-buttons';
1515
import { ResolveExternalLinks } from '~/settings/external.links';
1616
import {
17+
DefaultListId,
1718
DefaultLists,
1819
type ListEntity,
1920
ListType,
@@ -93,6 +94,16 @@ const collectionLoading = computed(() => {
9394
}).value;
9495
});
9596
97+
const watchedLoading = computed(() => {
98+
if (loadingWatched.value) return true;
99+
if (movieId.value === undefined) return true;
100+
return isItemListLoading({
101+
listType: ListType.History,
102+
itemType: 'movie',
103+
itemId: movieId.value,
104+
}).value;
105+
});
106+
96107
const activeLists = computed(() => {
97108
if (movieId?.value === undefined) return;
98109
return lists.value
@@ -133,8 +144,17 @@ const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) =>
133144
const onWatchedUpdate = async (value: PanelButtonsOptions, date?: number) => {
134145
if (!movie.value?.ids) return;
135146
136-
// TODO : implement add/remove from history
137-
// addToOrRemoveFromList(DefaultLists.Watchlist, `${panelType.value}s`, activeItem.value.ids);
147+
await addToOrRemoveFromList({
148+
list: {
149+
id: DefaultListId.History,
150+
type: ListType.History,
151+
name: 'list_type__history',
152+
},
153+
itemType: 'movie',
154+
itemIds: movie.value?.ids,
155+
date,
156+
remove: value === PanelButtonsOption.Remove,
157+
});
138158
139159
const _id = movie.value?.ids?.trakt;
140160
if (_id === undefined) return;
@@ -179,7 +199,7 @@ const { openTab } = useExtensionSettingsStore();
179199

180200
<MoviePanelButtons
181201
:watched="watched"
182-
:watched-loading="loadingWatched"
202+
:watched-loading="watchedLoading"
183203
:collected="collected"
184204
:collected-loading="collectionLoading"
185205
:active-loading="listLoading"

src/components/views/panel/ShowPanel.vue

+29-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '~/components/views/panel/use-panel-buttons';
1515
import { ResolveExternalLinks } from '~/settings/external.links';
1616
import {
17+
DefaultListId,
1718
DefaultLists,
1819
type ListEntity,
1920
ListType,
@@ -65,12 +66,6 @@ const watchedProgress = computed(() => {
6566
if (!showId?.value) return;
6667
return getShowWatchedProgress(showId.value).value;
6768
});
68-
69-
const watchedLoading = computed(() => {
70-
if (!showId?.value) return;
71-
return getShowProgressLoading(showId.value).value;
72-
});
73-
7469
const collectionProgress = computed(() => {
7570
if (!showId?.value) return;
7671
return getShowCollectionProgress(showId.value).value;
@@ -188,11 +183,27 @@ const activeItemCollectionLoading = computed(() => {
188183
});
189184
190185
const collectionLoading = computed(() => {
191-
if (!showId?.value) return;
192186
if (activeItemCollectionLoading.value) return true;
187+
if (!showId?.value) return true;
193188
return getShowCollectionLoading(showId.value).value;
194189
});
195190
191+
const activeItemWatchedLoading = computed(() => {
192+
const _id = activeItem.value?.ids?.trakt;
193+
if (_id === undefined) return;
194+
return isItemListLoading({
195+
listType: ListType.History,
196+
itemType: panelType.value,
197+
itemId: _id,
198+
}).value;
199+
});
200+
201+
const watchedLoading = computed(() => {
202+
if (activeItemWatchedLoading.value) return true;
203+
if (!showId?.value) return true;
204+
return getShowProgressLoading(showId.value).value;
205+
});
206+
196207
const activeLists = computed(() => {
197208
const _id = activeItem?.value?.ids?.trakt;
198209
const _type = panelType.value;
@@ -246,8 +257,17 @@ const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) =>
246257
const onWatchedUpdate = async (value: PanelButtonsOptions, date?: number) => {
247258
if (!panelType.value || !activeItem.value?.ids) return;
248259
249-
// TODO : implement add/remove from history
250-
// addToOrRemoveFromList(DefaultLists.Watchlist, `${panelType.value}s`, activeItem.value.ids);
260+
await addToOrRemoveFromList({
261+
list: {
262+
id: DefaultListId.History,
263+
type: ListType.History,
264+
name: 'list_type__history',
265+
},
266+
itemType: panelType.value,
267+
itemIds: activeItem.value.ids,
268+
date,
269+
remove: value === PanelButtonsOption.Remove,
270+
});
251271
if (!showId.value) return;
252272
await fetchShowProgress(showId.value, { force: true });
253273
};

src/stores/data/list.store.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const ListType = {
3333
Collection: 'collection',
3434
Watchlist: 'watchlist',
3535
Favorites: 'favorites',
36+
History: 'history',
3637
} as const;
3738

3839
export type ListTypes = (typeof ListType)[keyof typeof ListType];
@@ -42,14 +43,15 @@ export const DefaultListId = {
4243
Favorites: 'favorites',
4344
MovieCollection: 'movie-collection',
4445
ShowCollection: 'show-collection',
46+
History: 'history',
4547
} as const;
4648

4749
export type DefaultListIds = (typeof DefaultListId)[keyof typeof DefaultListId];
4850

4951
export type ListEntity = {
5052
type: ListTypes;
51-
name: string;
5253
id: number | string | DefaultListIds;
54+
name: string;
5355
owner?: TraktUser;
5456
scope?: 'movies' | 'shows';
5557
};
@@ -270,11 +272,11 @@ export const useListStore = defineStore('data.list', () => {
270272

271273
let response;
272274

273-
if (list.type === 'watchlist') {
275+
if (list.type === ListType.Watchlist) {
274276
response = await TraktService.watchlist(query);
275-
} else if (list.type === 'favorites') {
277+
} else if (list.type === ListType.Favorites) {
276278
response = await TraktService.favorites(query);
277-
} else if (list.type === 'collection' && list.scope) {
279+
} else if (list.type === ListType.Collection && list.scope) {
278280
response = await TraktService.collection({
279281
...query,
280282
type: list.scope,
@@ -317,7 +319,7 @@ export const useListStore = defineStore('data.list', () => {
317319
date?: Date | string | number;
318320
remove?: boolean;
319321
}) => {
320-
const listId = list.id.toString();
322+
const listId = list.id?.toString();
321323
const listType = list.type;
322324
const userId = list.owner?.username;
323325

@@ -340,7 +342,14 @@ export const useListStore = defineStore('data.list', () => {
340342
typeLoading[listType] = true;
341343

342344
try {
343-
if (listType === ListType.Watchlist) {
345+
if (listType === ListType.History) {
346+
if (remove) {
347+
await TraktService.remove.history({ [`${itemType}s`]: [{ ids: itemIds }] });
348+
} else {
349+
const _date = date ? new Date(date).toISOString() : undefined;
350+
await TraktService.add.history({ [`${itemType}s`]: [{ watched_at: _date, ids: itemIds }] });
351+
}
352+
} else if (listType === ListType.Watchlist) {
344353
await TraktService[remove ? 'remove' : 'add'].watchlist({ [`${itemType}s`]: [{ ids: itemIds }] });
345354
updateDictionary(list, { [itemType]: { ids: itemIds } }, remove);
346355
} else if (listType === 'favorites') {

0 commit comments

Comments
 (0)