Skip to content

Commit 829fba1

Browse files
committed
feat(favorites): adds support to favorites list
1 parent 8c9e720 commit 829fba1

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

src/components/views/panel/MoviePanelButtons.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ const listOptions = computed(
125125
() =>
126126
lists.value
127127
?.filter(list =>
128-
[ListType.List, ListType.Watchlist].map(String).includes(list.type),
128+
[ListType.List, ListType.Watchlist, ListType.Favorites]
129+
.map(String)
130+
.includes(list.type),
129131
)
130132
.map(list => ({
131-
label: list.type === ListType.Watchlist ? i18n(list.name) : list.name,
133+
label: list.type === ListType.List ? list.name : i18n(list.name),
132134
value: list.id,
133135
icon: getIcon(list),
134136
})),

src/components/views/panel/ShowPanelButtons.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const listLoading = computed(() => {
200200
const listOptions = computed(
201201
() =>
202202
myLists.value?.map(list => ({
203-
label: list.type === ListType.Watchlist ? i18n(list.name) : list.name,
203+
label: list.type === ListType.List ? list.name : i18n(list.name),
204204
value: list.id,
205205
icon: getIcon(list),
206206
})),

src/components/views/settings/SettingsTabs.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const selectedLists = computed({
6868
type ListOption = SelectOption & { source: ListEntity; icon: Component };
6969
const listOptions = computed<ListOption[]>(() =>
7070
myLists.value.map((list, i) => ({
71-
label: list.type === ListType.Watchlist ? i18n(list.name, 'list') : list.name,
71+
label: list.type === ListType.List ? list.name : i18n(list.name, 'list'),
7272
value: list.id,
7373
source: list,
7474
icon: getIcon(list),

src/i18n/en/panel/panel-buttons.json

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"message": "Watchlist",
44
"description": "Label for the watchlist button in the panel"
55
},
6+
"panel__buttons__list_type__favorites": {
7+
"message": "Favorites",
8+
"description": "Label for the favorites button in the panel"
9+
},
610
"panel__buttons__label__checkin": {
711
"message": "Start Checkin",
812
"description": "Label for the checkin button in the panel"

src/stores/data/list.store.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
9595
};
9696

9797
const updateDictionary = (list: ListEntity, item: MinimalItem, remove?: boolean) => {
98-
if (![ListType.List, ListType.Watchlist].map(String).includes(list.type)) return;
98+
if (![ListType.List, ListType.Watchlist, ListType.Favorites].map(String).includes(list.type)) return;
9999
const _id = list.id.toString();
100100

101101
if (!listDictionary[_id]) listDictionary[_id] = {};
@@ -154,7 +154,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
154154
};
155155

156156
const { evicted } = useActivityStore();
157-
const fetchListItems = async ({ page, limit = pageSize.value, list = activeList.value }: ListQuery = {}, parallel = false) => {
157+
const fetchListItems = async ({ page, limit = pageSize.value, list = activeList.value }: ListQuery = {}, parallel = false, updateState = true) => {
158158
if (!isAuthenticated.value) {
159159
Logger.error('Cannot fetch list, user is not authenticated');
160160
return;
@@ -170,7 +170,9 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
170170
if (!parallel) loading.value = true;
171171
typeLoading[list.type] = true;
172172
listDictionaryLoading[list.id.toString()] = true;
173-
const { clearLoading } = debounceLoading(listItems, loadingPlaceholder, { clear: !page, time: 1000 });
173+
174+
let clearLoading: (() => void) | undefined;
175+
if (updateState) clearLoading = debounceLoading(listItems, loadingPlaceholder, { clear: !page, time: 1000 }).clearLoading;
174176

175177
try {
176178
const response = await fetchItems(list, { pagination: { page, limit } });
@@ -179,16 +181,18 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
179181
if ('id' in item) return item;
180182
return { ...item, id: `${page}-${index}` };
181183
});
182-
pagination.value = response.pagination ?? {};
183-
listItems.value = page ? [...listItems.value.filter(l => l.type !== ListScrollItemType.Loading), ...newData] : newData;
184+
if (updateState) {
185+
pagination.value = response.pagination ?? {};
186+
listItems.value = page ? [...listItems.value.filter(l => l.type !== ListScrollItemType.Loading), ...newData] : newData;
187+
}
184188
evicted.watchlist = false;
185189
} catch (e) {
186190
Logger.error('Failed to fetch list');
187191
NotificationService.error(`Failed to fetch list '${list}'`, e);
188-
listItems.value = listItems.value.filter(l => l.type !== ListScrollItemType.Loading);
192+
if (updateState) listItems.value = listItems.value.filter(l => l.type !== ListScrollItemType.Loading);
189193
throw e;
190194
} finally {
191-
clearLoading();
195+
clearLoading?.();
192196
if (!parallel) loading.value = false;
193197
typeLoading[list.type] = false;
194198
listDictionaryLoading[list.id.toString()] = false;
@@ -198,7 +202,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
198202
const fetchAll = async (lists: ListEntity[], query?: Omit<ListQuery, 'list'>) => {
199203
if (!lists.length) return;
200204
loading.value = true;
201-
await Promise.all(lists.map(list => fetchListItems({ list, ...query }, true)));
205+
await Promise.all(lists.map(list => fetchListItems({ list, ...query }, true, false)));
202206
loading.value = false;
203207
};
204208

@@ -257,8 +261,9 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
257261
} else if (listType === ListType.Watchlist) {
258262
await TraktService[remove ? 'remove' : 'add'].watchlist({ [`${itemType}s`]: [{ ids: itemIds }] });
259263
updateDictionary(list, { [itemType]: { ids: itemIds } }, remove);
260-
} else if (listType === 'favorites') {
264+
} else if (listType === ListType.Favorites) {
261265
await TraktService[remove ? 'remove' : 'add'].favorites({ [`${itemType}s`]: [{ ids: itemIds }] });
266+
updateDictionary(list, { [itemType]: { ids: itemIds } }, remove);
262267
} else if (listType === ListType.Collection) {
263268
if (remove) {
264269
await TraktService.remove.collection({ [`${itemType}s`]: [{ ids: itemIds }] });

src/stores/data/lists.store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ export const useListsStore = defineStore(ListsStoreConstants.Store, () => {
125125
}
126126
};
127127

128-
/** Filter favorites and collections out */
128+
/** Filter collaboration and collections out */
129129
const myLists = computed(() => {
130130
return lists.value?.filter(list => {
131-
return [ListType.List, ListType.Watchlist].map(String).includes(list.type);
131+
return [ListType.List, ListType.Watchlist, ListType.Favorites].map(String).includes(list.type);
132132
});
133133
});
134134

0 commit comments

Comments
 (0)