Skip to content

Commit 6c8e08e

Browse files
committed
feat(list): change caching strategy and adds today indicator
1 parent 4063e40 commit 6c8e08e

File tree

8 files changed

+58
-23
lines changed

8 files changed

+58
-23
lines changed

src/components/common/list/ListItem.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ const nextHasHead = computed(
9797
);
9898
const date = computed(() => item?.value?.date?.current);
9999
100+
const isToday = computed(
101+
() => date.value?.toLocaleDateString() === new Date().toLocaleDateString(),
102+
);
103+
100104
const year = new Date().getFullYear();
101105
const sameYear = computed(() => date.value?.getFullYear() === year);
102106
const loading = computed(() => item?.value?.loading);
@@ -163,7 +167,7 @@ const onClick = () => emit('onItemClick', { item: item?.value });
163167
<NFlex
164168
v-if="!hideDate"
165169
class="header"
166-
:class="{ hover }"
170+
:class="{ hover, today: isToday }"
167171
vertical
168172
justify="flex-start"
169173
align="center"
@@ -250,11 +254,15 @@ const onClick = () => emit('onItemClick', { item: item?.value });
250254
color: var(--n-text-color);
251255
font-size: 14px;
252256
border-top: 1px solid var(--border-grey);
257+
transition: color 0.2s var(--n-bezier);
258+
will-change: color;
259+
260+
&.today {
261+
color: var(--color-warning);
262+
}
253263
254264
&.hover {
255265
color: var(--trakt-red);
256-
transition: color 0.2s var(--n-bezier);
257-
will-change: color;
258266
}
259267
260268
.month {

src/components/common/list/ListItemPanel.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ const progress = computed<ShowProgress | undefined>(() => {
8080
if (item?.value?.progress) return item.value?.progress;
8181
if (item?.value?.progressRef) return item.value?.progressRef.value;
8282
if (!item?.value?.getProgressQuery) return;
83-
const id = item.value?.getProgressQuery();
83+
const { id, cacheOptions } = item.value?.getProgressQuery() ?? {};
8484
if (!id) return;
85-
return getShowWatchedProgress(id).value;
85+
return getShowWatchedProgress(id, cacheOptions).value;
8686
});
8787
8888
const innerContainer = ref();

src/components/views/panel/PanelButtonProgress.vue

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const renderLabel = (option: SelectOption & { icon: Component }) => [
162162
</ProgressTooltip>
163163

164164
<NModal
165-
v-if="false"
166165
v-model:show="showPicker"
167166
:to="root"
168167
:style="{

src/models/list-scroll.model.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { TraktPerson } from '~/models/trakt/trakt-people.model';
1010
import type { BaseTraktProgress, BaseTraktProgressEpisode, BaseTraktProgressSeason } from '~/models/trakt/trakt-progress.model';
1111
import type { TraktSeason } from '~/models/trakt/trakt-season.model';
1212
import type { TraktShow } from '~/models/trakt/trakt-show.model';
13+
import type { BaseCacheOption } from '~/services/common/base-client';
1314

1415
export type VirtualListRef = VirtualListInst & InstanceType<typeof NVirtualList>;
1516
export type VirtualListProps = {
@@ -90,7 +91,7 @@ export type ListScrollItem<T = Record<string, any>> = Omit<PosterItem, 'type'> &
9091

9192
progress?: ShowProgress;
9293
progressRef?: Ref<ShowProgress | undefined>;
93-
getProgressQuery?: () => string | number | undefined;
94+
getProgressQuery?: () => { id: string | number | undefined; cacheOptions?: BaseCacheOption };
9495

9596
meta?: T;
9697

src/services/trakt.service.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { TraktWatchlistGetQuery } from '~/models/trakt/trakt-watchlist.mode
1919
import type { SettingsAuth, UserSetting } from '~/models/trakt-service.model';
2020
import type { TvdbApiResponse } from '~/models/tvdb/tvdb-client.model';
2121

22-
import { getCachedFunction, type TypedResponse } from '~/services/common/base-client';
22+
import { type BaseCacheOption, getCachedFunction, type TypedResponse } from '~/services/common/base-client';
2323
import { LoadingBarService } from '~/services/loading-bar.service';
2424
import { tmdbApi } from '~/services/tmdb-client/api/tmdb-api.endpoints';
2525
import { TmdbClient } from '~/services/tmdb-client/clients/tmdb-client';
@@ -61,7 +61,10 @@ export class TraktService {
6161

6262
static {
6363
this.caches = {
64-
trakt: new ChromeCacheStore<TraktApiResponse>({ prefix: 'trakt-cache' }),
64+
trakt: new ChromeCacheStore<TraktApiResponse>({
65+
prefix: 'trakt-cache',
66+
retention: CacheRetention.Week,
67+
}),
6568
tvdb: new ChromeCacheStore<TvdbApiResponse>({
6669
prefix: 'tvdb-cache',
6770
retention: CacheRetention.Year,
@@ -82,6 +85,10 @@ export class TraktService {
8285
this.caches.tvdb.prefix = `tvdb-cache-${user}`;
8386
}
8487

88+
static changeRetention(retention: number) {
89+
this.caches.trakt.retention = retention;
90+
}
91+
8592
private static async saveAuth(
8693
auth: SettingsAuth = this.auth,
8794
prev: SettingsAuth = useAuthSettingsStore().auth,
@@ -314,8 +321,12 @@ export class TraktService {
314321
},
315322

316323
show: {
317-
async watched(showId: string | number) {
318-
const response = await TraktService.traktClient.shows.progress.watched.cached({ id: showId, specials: true, count_specials: false });
324+
async watched(showId: string | number, cacheOption?: BaseCacheOption) {
325+
const response = await TraktService.traktClient.shows.progress.watched.cached(
326+
{ id: showId, specials: true, count_specials: false },
327+
undefined,
328+
cacheOption,
329+
);
319330
return response.json() as Promise<TraktWatchedProgress>;
320331
},
321332

src/stores/data/progress.store.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type ListScrollItem, type ListScrollSourceItem } from '~/models/list-sc
99
import { type ProgressItem } from '~/models/progress.model';
1010
import { NotificationService } from '~/services/notification.service';
1111
import { TraktService } from '~/services/trakt.service';
12+
import { CacheRetention } from '~/utils/cache.utils';
1213
import { debounceLoading, useLoadingPlaceholder } from '~/utils/store.utils';
1314

1415
type ProgressListItem = Omit<ListScrollItem, 'posterRef' | 'progressRef'>;
@@ -42,7 +43,12 @@ export const progressToListItem = (progress: ProgressItem, index: number): Progr
4243
title: getTitle({ show, episode }),
4344
content: getContent({ show, episode }),
4445
poster,
45-
getProgressQuery: () => show?.ids?.trakt,
46+
getProgressQuery: () => ({
47+
id: show?.ids?.trakt,
48+
cacheOptions: {
49+
retention: CacheRetention.Day,
50+
},
51+
}),
4652
date: {
4753
current: new Date(progress.firstAired),
4854
},

src/stores/data/show.store.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type { TraktCollectionProgress, TraktWatchedProgress } from '~/models/tra
77
import type { TraktSeasonExtended } from '~/models/trakt/trakt-season.model';
88
import type { TraktShowExtended } from '~/models/trakt/trakt-show.model';
99

10+
import type { BaseCacheOption } from '~/services/common/base-client';
11+
1012
import { type ShowProgress, ShowProgressType } from '~/models/list-scroll.model';
1113
import { NotificationService } from '~/services/notification.service';
1214
import { TraktService } from '~/services/trakt.service';
@@ -95,7 +97,7 @@ export const useShowStore = defineStore('data.show', () => {
9597
}
9698
};
9799

98-
const fetchShowProgress = async (id: string) => {
100+
const fetchShowProgress = async (id: string, cacheOption?: BaseCacheOption) => {
99101
if (showWatchedProgressLoading[id]) {
100102
console.warn('Already fetching show progress', id);
101103
return;
@@ -105,7 +107,7 @@ export const useShowStore = defineStore('data.show', () => {
105107

106108
showWatchedProgressLoading[id] = true;
107109
try {
108-
showsWatchedProgress[id] = await TraktService.progress.show.watched(id);
110+
showsWatchedProgress[id] = await TraktService.progress.show.watched(id, cacheOption);
109111
} catch (e) {
110112
console.error('Failed to fetch show progress', id);
111113
throw e;
@@ -234,8 +236,10 @@ export const useShowStore = defineStore('data.show', () => {
234236
});
235237

236238
const getShowProgressLoading = (id: number | string) => computed(() => showWatchedProgressLoading[id.toString()]);
237-
const getShowWatchedProgress = (id: number | string) => {
238-
if (!showsWatchedProgress[id.toString()] && !showWatchedProgressLoading[id.toString()]) fetchShowProgress(id.toString()).catch(console.error);
239+
const getShowWatchedProgress = (id: number | string, cacheOptions?: BaseCacheOption) => {
240+
if (!showsWatchedProgress[id.toString()] && !showWatchedProgressLoading[id.toString()]) {
241+
fetchShowProgress(id.toString(), cacheOptions).catch(console.error);
242+
}
239243
return computed(() => {
240244
const progress = showsWatchedProgress[id.toString()];
241245
if (!progress) return undefined;

src/styles/base.scss

+13-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
--vt-c-text-light-2: rgb(60 60 60 / 66%);
1616
--vt-c-text-dark-1: var(--vt-c-white);
1717
--vt-c-text-dark-2: rgb(235 235 235 / 64%);
18-
18+
1919
/* background color variables */
2020
--bg-blur: 1px;
2121
--bg-blur-20: 20px;
@@ -28,7 +28,11 @@
2828
--bg-black-70: rgba(0 0 0 / 70%);
2929
--bg-black-80: rgba(0 0 0 / 80%);
3030
--bg-black-90: rgba(0 0 0 / 90%);
31-
--bg-gradient-60-90: linear-gradient(to right, var(--bg-color-60) 5%, var(--bg-color-90));
31+
--bg-gradient-60-90: linear-gradient(
32+
to right,
33+
var(--bg-color-60) 5%,
34+
var(--bg-color-90)
35+
);
3236
--bg-red: rgba(255 222 223);
3337
--bg-red-20: rgba(255 222 223 / 20%);
3438
--bg-red-30: rgba(255 222 223 / 30%);
@@ -39,7 +43,7 @@
3943
--bg-color-primary: rgb(24 42 36);
4044
--bg-color-primary-80: rgba(24 42 36 / 80%);
4145
--bg-color-info: rgb(22 35 42);
42-
--bg-color-info-80: rgb(22 35 42 / 80%);
46+
--bg-color-info-80: rgb(22 35 42 / 80%);
4347
--bg-color-warning: rgb(43 37 25);
4448
--bg-color-warning-80: rgb(43 37 25 / 80%);
4549
--bg-color-error: rgb(45 27 28);
@@ -52,7 +56,7 @@
5256
--border-grey: rgb(70 70 70);
5357
--border-white: rgb(255 255 255 / 20%);
5458
--primary-color: #63e2b7;
55-
--primary-color-lighter: #7fe7c4;
59+
--primary-color-lighter: #7fe7c4;
5660
--primary-color-disabled: #548272;
5761
--primary-color-dark: color-mix(in srgb, var(--primary-color) 40%, black 60%);
5862
--primary-color-focus: rgba(99 226 183 / 10%);
@@ -67,10 +71,13 @@
6771

6872
/* trakt.tv brand color */
6973
--trakt-red: #ed1c24;
70-
--trakt-red-dark: #ba080f;
74+
--trakt-red-dark: #b7000D;
75+
--trakt-red-darker: #80000a;
76+
--trakt-red-light:#ff5c62;
77+
--trakt-red-lighter: #e98b8b;
7178

7279
/* Transforms */
73-
--n-bezier: cubic-bezier(.4, 0, .2, 1);
80+
--n-bezier: cubic-bezier(0.4, 0, 0.2, 1);
7481

7582
/* Bow shadows */
7683
--image-box-shadow: 0 0 20px 9px rgb(255 255 255 / 10%);
@@ -139,4 +146,3 @@
139146
}
140147
*/
141148
}
142-

0 commit comments

Comments
 (0)