Skip to content

Commit 8d60081

Browse files
committed
fix(list): key element with date as there might be re-releases
1 parent b294659 commit 8d60081

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/components/common/list/use-list-scroll.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ export const computeNewArray = <T extends ListScrollSourceItemWithDate<D>, D ext
247247
if (!_item.getPosterQuery) _item.getPosterQuery = getPosterQuery(item, _item.type);
248248
if (!_item.getProgressQuery) _item.getProgressQuery = getProgressQuery(item);
249249

250-
_item.key = `${_item.type}-${_item.id}`;
251250
_item.date = getDate(item, array, index, dateFn);
251+
_item.key = `${_item.type}-${_item.id}-${_item.date?.current?.getTime()}`;
252252
_item.meta = {
253253
source: item,
254254
ids: {

src/models/pagination.model.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import type { TmdbApiPagination } from '@dvcol/tmdb-http-client/dist/models/tmdb-client.model';
21
import type { TraktClientPagination } from '@dvcol/trakt-http-client/models';
32

4-
export type StorePagination = Partial<TraktClientPagination> | Partial<TmdbApiPagination>;
5-
export type LoadedStorePagination<T extends TraktClientPagination | TmdbApiPagination> = T &
6-
('pageCount' extends keyof T ? { page: number; pageCount: number } : { page: number; total_pages: number });
3+
export type StorePagination = Partial<TraktClientPagination>;
74

8-
export const pageLoaded = <T extends TraktClientPagination | TmdbApiPagination>(pagination?: T) => {
5+
export const pageLoaded = (pagination?: StorePagination) => {
96
if (!pagination) return false;
10-
const { page, pageCount, total_pages } = pagination;
11-
const _total = total_pages ?? pageCount;
12-
if (page === undefined || _total === undefined) return false;
13-
if (_total === 0) return true;
14-
return page >= _total;
7+
const { page, pageCount: total } = pagination;
8+
if (page === undefined || total === undefined) return false;
9+
if (total === 0) return true;
10+
return page >= total;
1511
};
1612

17-
export const pageNotLoaded = <T extends TraktClientPagination | TmdbApiPagination>(pagination?: T) => {
13+
export const pageNotLoaded = (pagination?: StorePagination) => {
1814
return !pageLoaded(pagination);
1915
};

src/stores/data/ratings.store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { defineStore, storeToRefs } from 'pinia';
1010
import { computed, reactive, ref } from 'vue';
1111

1212
import { PageSize } from '~/models/page-size.model';
13-
import { pageLoaded, type StorePagination } from '~/models/pagination.model';
13+
import { pageLoaded, pageNotLoaded, type StorePagination } from '~/models/pagination.model';
1414

1515
import { ErrorService } from '~/services/error.service';
1616
import { Logger } from '~/services/logger.service';
@@ -229,7 +229,7 @@ export const useRatingsStore = defineStore(RatingsStoreConstants.Store, () => {
229229

230230
const loadRatings = async <T extends TraktRatingTypes>(type: T, id: string): Promise<TraktRatingsReturn<T> | undefined> => {
231231
while (
232-
!pageLoaded(paginations[type]) &&
232+
pageNotLoaded(paginations[type]) &&
233233
!getLoading(type) &&
234234
!getRatings(type, id) &&
235235
shouldRetry(errors[JSON.stringify(getQuery(type))], { error: `Ratings for ${type} - ${id.toString()}` })

0 commit comments

Comments
 (0)