Skip to content

Commit 88429b2

Browse files
committed
feat(list): source played status from history when no progress available
1 parent 6152459 commit 88429b2

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

src/components/common/list/ListItemPanel.vue

+26-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import IconPlayFilled from '~/components/icons/IconPlayFilled.vue';
2121
import { type ListScrollItem, type ShowProgress } from '~/models/list-scroll.model';
2222
2323
import { ProgressType } from '~/models/progress-type.model';
24+
import { useHistoryStore } from '~/stores/data/history.store';
2425
import { useMovieStore } from '~/stores/data/movie.store';
2526
import { useShowStore } from '~/stores/data/show.store';
2627
import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store';
@@ -119,22 +120,43 @@ const collection = computed<ShowProgress | undefined>(() => {
119120
});
120121
121122
const { getMovieWatched, getMovieCollected } = useMovieStore();
123+
const { getMovieHistory, getEpisodeHistory } = useHistoryStore();
124+
125+
const movieHistory = computed(() => {
126+
if (!showPlayed.value) return;
127+
const _item = item?.value;
128+
if (_item?.type !== 'movie') return;
129+
if (!_item?.meta?.ids?.movie?.trakt) return;
130+
return !!getMovieHistory(_item.meta.ids.movie.trakt)?.value;
131+
});
132+
133+
const episodeHistory = computed(() => {
134+
if (!showPlayed.value) return;
135+
const _item = item?.value;
136+
if (_item?.type !== 'episode') return;
137+
if (!_item?.meta?.ids?.episode?.trakt) return;
138+
return !!getEpisodeHistory(_item.meta.ids.episode.trakt)?.value;
139+
});
122140
123141
const played = computed(() => {
124142
if (!showPlayed.value) return false;
125143
const _item = item?.value;
126144
if (_item?.type === 'movie' && _item?.meta?.ids?.movie?.trakt) {
127-
return getMovieWatched(_item.meta.ids.movie.trakt)?.value;
145+
const _watched = getMovieWatched(_item.meta.ids.movie.trakt)?.value;
146+
if (_watched !== undefined) return _watched;
147+
return movieHistory.value;
128148
}
129149
if (_item?.type !== 'episode') return false;
130150
const _progress = progress.value;
131-
if (!_progress) return false;
151+
if (!_progress) return episodeHistory.value;
132152
const _season = _item.meta?.number?.season;
133153
const _episode = _item.meta?.number?.episode;
134-
if (!_season || !_episode) return false;
135-
return _progress.seasons
154+
if (!_season || !_episode) return episodeHistory.value;
155+
const _watched = _progress.seasons
136156
?.find(s => s.number === _season)
137157
?.episodes?.find(e => e.number === _episode)?.completed;
158+
if (_watched !== undefined) return _watched;
159+
return episodeHistory.value;
138160
});
139161
140162
const collected = computed(() => {

src/stores/data/history.store.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { TraktApiExtended, type TraktClientPagination, type TraktHistory, type TraktHistoryGetQuery } from '@dvcol/trakt-http-client/models';
1+
import { TraktApiExtended } from '@dvcol/trakt-http-client/models';
2+
23
import { defineStore, storeToRefs } from 'pinia';
34
import { computed, reactive, ref, watch } from 'vue';
45

6+
import type { TraktApiIds, TraktClientPagination, TraktHistory, TraktHistoryGetQuery } from '@dvcol/trakt-http-client/models';
7+
58
import type { ErrorDictionary } from '~/utils/retry.utils';
69

710
import { PageSize } from '~/models/page-size.model';
@@ -13,6 +16,13 @@ import { storage } from '~/utils/browser/browser-storage.utils';
1316
import { debounceLoading, useBelowThreshold, useLoadingPlaceholder, useSearchFilter } from '~/utils/store.utils';
1417
import { clearProxy } from '~/utils/vue.utils';
1518

19+
type IdDictionary = Record<string, Partial<TraktApiIds>>;
20+
21+
type HistoryDictionary = {
22+
movie?: IdDictionary;
23+
episode?: IdDictionary;
24+
};
25+
1626
const HistoryStoreConstants = {
1727
Store: 'data.history',
1828
} as const;
@@ -29,6 +39,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
2939
const loading = ref(true);
3040
const pageSize = ref(PageSize.p100);
3141
const history = ref<TraktHistory[]>([]);
42+
const historyDictionary = reactive<HistoryDictionary>({});
3243
const pagination = ref<TraktClientPagination>();
3344
const extended = ref(false);
3445

@@ -66,6 +77,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
6677
historyStart.value = undefined;
6778
historyEnd.value = undefined;
6879
clearProxy(historyErrors);
80+
clearProxy(historyDictionary);
6981
};
7082

7183
const belowThreshold = useBelowThreshold(threshold, pagination);
@@ -117,6 +129,10 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
117129
await saveState();
118130
};
119131

132+
const getHistory = (id: number, type: TraktHistory['type']) => computed(() => historyDictionary[type]?.[id]);
133+
const getMovieHistory = (id: number) => getHistory(id, 'movie');
134+
const getEpisodeHistory = (id: number) => getHistory(id, 'episode');
135+
120136
const initHistoryStore = async () => {
121137
await restoreState();
122138

@@ -125,6 +141,19 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
125141
searchHistory.value = '';
126142
await saveState();
127143
});
144+
145+
watch(history, newHistory => {
146+
clearProxy(historyDictionary);
147+
newHistory?.forEach(h => {
148+
if (h.type === 'movie' && 'movie' in h) {
149+
if (!historyDictionary.movie) historyDictionary.movie = {};
150+
historyDictionary.movie[h.movie.ids.trakt] = h.movie.ids;
151+
} else if (h.type === 'episode' && 'episode' in h) {
152+
if (!historyDictionary.episode) historyDictionary.episode = {};
153+
historyDictionary.episode[h.episode.ids.trakt] = h.episode.ids;
154+
}
155+
});
156+
});
128157
};
129158

130159
return {
@@ -141,6 +170,9 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
141170
historyStart,
142171
historyEnd,
143172
setHistoryRange,
173+
getHistory,
174+
getMovieHistory,
175+
getEpisodeHistory,
144176
clearState,
145177
initHistoryStore,
146178
extended: computed({

0 commit comments

Comments
 (0)