Skip to content

Commit 04bf36b

Browse files
committed
feat(panel): load selected lists on movie panel open
1 parent 0a8f4a5 commit 04bf36b

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/components/views/panel/MoviePanel.vue

+40-16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
useListStore,
2424
} from '~/stores/data/list.store';
2525
import { useMovieStore, useMovieStoreRefs } from '~/stores/data/movie.store';
26+
import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store';
2627
import { useLinksStore } from '~/stores/settings/links.store';
2728
import { useI18n } from '~/utils/i18n.utils';
2829
@@ -75,22 +76,22 @@ const collectedDate = computed(() => {
7576
return getMovieCollectedDate(movieId.value)?.value;
7677
});
7778
78-
onMounted(() => {
79-
watch(
80-
movieId,
81-
id => {
82-
fetchMovie(id);
83-
},
84-
{ immediate: true },
85-
);
86-
fetchMovieWatched();
87-
fetchMovieCollected();
79+
const { myLists } = useListsStoreRefs();
80+
const {
81+
isListTypeLoading,
82+
isItemInList,
83+
isItemListLoading,
84+
addToOrRemoveFromList,
85+
fetchAll,
86+
} = useListStore();
87+
88+
const { loadLists, loadListsPageSize } = useExtensionSettingsStoreRefs();
89+
90+
const shouldFetchLists = computed(() => {
91+
if (!myLists.value?.length) return false;
92+
return loadLists.value;
8893
});
8994
90-
const { lists } = useListsStoreRefs();
91-
const { isListTypeLoading, isItemInList, isItemListLoading, addToOrRemoveFromList } =
92-
useListStore();
93-
9495
const listLoading = computed(
9596
() =>
9697
isListTypeLoading(ListType.Watchlist).value || isListTypeLoading(ListType.List).value,
@@ -118,15 +119,15 @@ const watchedLoading = computed(() => {
118119
119120
const activeLists = computed(() => {
120121
if (movieId?.value === undefined) return;
121-
return lists.value
122+
return myLists.value
122123
?.filter(list => isItemInList(list.id, 'movie', movieId.value).value)
123124
.map(list => list.id);
124125
});
125126
126127
const onListUpdate = async (value: ListEntity['id'], remove: boolean) => {
127128
if (!movie.value?.ids) return;
128129
129-
const _list = lists.value.find(list => list.id === value);
130+
const _list = myLists.value.find(list => list.id === value);
130131
if (!_list) return;
131132
132133
await addToOrRemoveFromList({
@@ -204,6 +205,29 @@ const titleUrl = computed(() => {
204205
});
205206
206207
const { openTab } = useLinksStore();
208+
209+
onMounted(() => {
210+
watch(
211+
movieId,
212+
id => {
213+
fetchMovie(id);
214+
},
215+
{ immediate: true },
216+
);
217+
fetchMovieWatched();
218+
fetchMovieCollected();
219+
220+
if (shouldFetchLists.value) {
221+
fetchAll(
222+
myLists.value.filter(
223+
_active => loadLists.value?.find(_list => _list.id === _active.id),
224+
),
225+
{
226+
limit: loadListsPageSize.value,
227+
},
228+
);
229+
}
230+
});
207231
</script>
208232

209233
<template>

0 commit comments

Comments
 (0)