Skip to content

Commit 012243b

Browse files
committed
feat(poster): parametrize image format
1 parent 1535f59 commit 012243b

File tree

7 files changed

+94
-4
lines changed

7 files changed

+94
-4
lines changed

src/components/views/calendar/CalendarComponent.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Route } from '~/models/router.model';
1010
import { useAppStateStoreRefs } from '~/stores/app-state.store';
1111
import { useActivityStore } from '~/stores/data/activity.store';
1212
import { useCalendarStore, useCalendarStoreRefs } from '~/stores/data/calendar.store';
13+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
1314
import { useCalendar, useCenterButton } from '~/utils/calendar.utils';
1415
import { useI18n } from '~/utils/i18n.utils';
1516
import { useActiveAndDocumentVisible, watchUserChange } from '~/utils/store.utils';
@@ -33,6 +34,9 @@ const { listRef, onClick, onScrollTop, onScrollBottom, reload } = useCalendar({
3334
fetchData: fetchCalendar,
3435
});
3536
37+
const { getImageSettings } = useExtensionSettingsStore();
38+
const imageSettings = getImageSettings(Route.Calendar);
39+
3640
watch(center, (_is, _was) => {
3741
if (new Date(_is).toLocaleDateString() === new Date(_was).toLocaleDateString()) return;
3842
reload();
@@ -72,7 +76,8 @@ const { onItemClick } = usePanelItem();
7276
ref="listRef"
7377
:items="list"
7478
:loading="loading"
75-
backdrop
79+
:backdrop="imageSettings.backdrop"
80+
:poster-type="imageSettings.type"
7681
show-played
7782
show-collected
7883
show-tag-loader

src/components/views/history/HistoryComponent.vue

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useAppStateStoreRefs } from '~/stores/app-state.store';
1515
import { useActivityStore } from '~/stores/data/activity.store';
1616
import { useHistoryStore, useHistoryStoreRefs } from '~/stores/data/history.store';
1717
import { useWatchingStoreRefs } from '~/stores/data/watching.store';
18+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
1819
import { useI18n } from '~/utils/i18n.utils';
1920
import { useActiveAndDocumentVisible, watchUserChange } from '~/utils/store.utils';
2021
import { useWatchActivated } from '~/utils/vue.utils';
@@ -48,6 +49,9 @@ const { onScroll, onUpdated, onLoadMore } = useListScrollEvents(fetchHistory, {
4849
active,
4950
});
5051
52+
const { getImageSettings } = useExtensionSettingsStore();
53+
const imageSettings = getImageSettings(Route.History);
54+
5155
const { getEvicted } = useActivityStore();
5256
useWatchActivated(
5357
watch(getEvicted(Route.History), async _evicted => {
@@ -80,6 +84,8 @@ useActiveAndDocumentVisible({
8084
:loading="loading"
8185
:pagination="pagination"
8286
:page-size="pageSize"
87+
:backdrop="imageSettings.backdrop"
88+
:poster-type="imageSettings.type"
8389
show-collected
8490
show-tag-loader
8591
@on-scroll="scrolled = true"

src/components/views/progress/ProgressComponent.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useActivityStore } from '~/stores/data/activity.store';
1616
import { useProgressStore, useProgressStoreRefs } from '~/stores/data/progress.store';
1717
import { useWatchingStoreRefs } from '~/stores/data/watching.store';
1818
import { useAuthSettingsStoreRefs } from '~/stores/settings/auth.store';
19+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
1920
import { useI18n } from '~/utils/i18n.utils';
2021
import { useActiveAndDocumentVisible, watchUserChange } from '~/utils/store.utils';
2122
import { getSessionUser } from '~/utils/trakt-service.utils';
@@ -46,6 +47,9 @@ const { user } = useAuthSettingsStoreRefs();
4647
const unSub = ref<() => void>();
4748
const notification = ref<NotificationReactive>();
4849
50+
const { getImageSettings } = useExtensionSettingsStore();
51+
const imageSettings = getImageSettings(Route.Progress);
52+
4953
const { getEvicted } = useActivityStore();
5054
useWatchActivated(
5155
watch(getEvicted(Route.Progress), async _evicted => {
@@ -103,7 +107,8 @@ useActiveAndDocumentVisible({
103107
ref="listRef"
104108
:loading="loading"
105109
:items="progress"
106-
backdrop
110+
:backdrop="imageSettings.backdrop"
111+
:poster-type="imageSettings.type"
107112
hide-date
108113
show-progress
109114
show-collected

src/components/views/releases/ReleasesComponent.vue

+7
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import ListScroll from '~/components/common/list/ListScroll.vue';
99
import { useListScroll } from '~/components/common/list/use-list-scroll';
1010
1111
import { usePanelItem } from '~/components/views/panel/use-panel-item';
12+
import { Route } from '~/models/router.model';
1213
import { TraktService } from '~/services/trakt.service';
1314
import { useAppStateStoreRefs } from '~/stores/app-state.store';
1415
import { useReleasesStore, useReleasesStoreRefs } from '~/stores/data/releases.store';
16+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
1517
import { useCalendar, useCenterButton } from '~/utils/calendar.utils';
1618
import { useI18n } from '~/utils/i18n.utils';
1719
import { useActiveAndDocumentVisible, watchUserChange } from '~/utils/store.utils';
@@ -25,6 +27,9 @@ const { fetchReleases, clearState } = useReleasesStore();
2527
2628
const list = useListScroll(releases, 'date');
2729
30+
const { getImageSettings } = useExtensionSettingsStore();
31+
const imageSettings = getImageSettings(Route.Releases);
32+
2833
const { centerItem, centerIsToday, scrolledOut, recenterIcon, onScrollIntoOutOfView } =
2934
useCenterButton({ list, center });
3035
@@ -73,6 +78,8 @@ const onMovieClick = async ({ item }: { item: ListScrollItem }) => {
7378
:items="list"
7479
:loading="loading"
7580
:content-height="3"
81+
:backdrop="imageSettings.backdrop"
82+
:poster-type="imageSettings.type"
7683
hide-time
7784
overscroll="none"
7885
:scroll-into-view="centerItem?.id ? [centerItem?.id] : []"

src/components/views/search/SearchComponent.vue

+7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {
1010
useListScrollEvents,
1111
} from '~/components/common/list/use-list-scroll';
1212
import { usePanelItem } from '~/components/views/panel/use-panel-item';
13+
import { Route } from '~/models/router.model';
1314
import { useAppStateStoreRefs } from '~/stores/app-state.store';
1415
import {
1516
type SearchResult,
1617
useSearchStore,
1718
useSearchStoreRefs,
1819
} from '~/stores/data/search.store';
20+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
1921
import { useI18n } from '~/utils/i18n.utils';
2022
import { useActiveAndDocumentVisible } from '~/utils/store.utils';
2123
@@ -26,6 +28,9 @@ const { footerOpen } = useAppStateStoreRefs();
2628
const { searchResults, loading, pagination } = useSearchStoreRefs();
2729
const { fetchSearchResults } = useSearchStore();
2830
31+
const { getImageSettings } = useExtensionSettingsStore();
32+
const imageSettings = getImageSettings(Route.Search);
33+
2934
onActivated(async () => {
3035
await fetchSearchResults();
3136
});
@@ -53,6 +58,8 @@ const { onItemClick } = usePanelItem();
5358
hide-date
5459
:items="list"
5560
:loading="loading"
61+
:backdrop="imageSettings.backdrop"
62+
:poster-type="imageSettings.type"
5663
show-played
5764
show-collected
5865
@on-scroll="scrolled = true"

src/components/views/watchlist/WatchlistComponent.vue

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
useListStoreRefs,
2323
} from '~/stores/data/list.store';
2424
import { useListsStoreRefs } from '~/stores/data/lists.store';
25+
import { useExtensionSettingsStore } from '~/stores/settings/extension.store';
2526
import { useI18n } from '~/utils/i18n.utils';
2627
import { useActiveAndDocumentVisible, watchUserChange } from '~/utils/store.utils';
2728
import { useWatchActivated } from '~/utils/vue.utils';
@@ -65,6 +66,9 @@ const { onScroll, onUpdated, onLoadMore } = useListScrollEvents(fetchListItems,
6566
active,
6667
});
6768
69+
const { getImageSettings } = useExtensionSettingsStore();
70+
const imageSettings = getImageSettings(Route.Watchlist);
71+
6872
const { getEvicted } = useActivityStore();
6973
useWatchActivated(
7074
watch(getEvicted(Route.Watchlist), async _evicted => {
@@ -95,6 +99,8 @@ useActiveAndDocumentVisible({
9599
:loading="listLoading"
96100
:pagination="pagination"
97101
:page-size="pageSize"
102+
:backdrop="imageSettings.backdrop"
103+
:poster-type="imageSettings.type"
98104
show-played
99105
show-collected
100106
@on-scroll="scrolled = true"

src/stores/settings/extension.store.ts

+56-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { computed, reactive, ref, toRaw } from 'vue';
55

66
import type { ListEntity } from '~/models/list.model';
77

8+
import type { PosterItem } from '~/models/poster.model';
9+
810
import { NavbarPosition, type NavbarPositions } from '~/models/navbar-position.model';
911

1012
import { PageSize } from '~/models/page-size.model';
@@ -34,12 +36,33 @@ type RouteDictionary = Partial<Record<Route, boolean>>;
3436
const DefaultRoutes: RouteDictionary = {
3537
[Route.Progress]: false,
3638
[Route.Calendar]: true,
37-
[Route.Releases]: false,
3839
[Route.History]: true,
3940
[Route.Watchlist]: true,
41+
[Route.Releases]: false,
4042
[Route.Search]: true,
4143
};
4244

45+
type ImageTypeDictionary = Partial<Record<Route, PosterItem['type'] | 'default'>>;
46+
47+
const DefaultImageTypes: ImageTypeDictionary = {
48+
[Route.Progress]: 'default',
49+
[Route.Calendar]: 'default',
50+
[Route.History]: 'default',
51+
[Route.Watchlist]: 'default',
52+
[Route.Releases]: 'default',
53+
[Route.Search]: 'default',
54+
};
55+
56+
type ImageFormatDictionary = Partial<Record<Route, 'backdrop' | 'poster'>>;
57+
const DefaultImageFormats: ImageFormatDictionary = {
58+
[Route.Progress]: 'backdrop',
59+
[Route.Calendar]: 'backdrop',
60+
[Route.History]: 'backdrop',
61+
[Route.Watchlist]: 'poster',
62+
[Route.Releases]: 'poster',
63+
[Route.Search]: 'poster',
64+
};
65+
4366
type ExtensionSettings = {
4467
cacheRetention: CacheRetentionState;
4568
enabledRoutes: RouteDictionary;
@@ -53,6 +76,8 @@ type ExtensionSettings = {
5376
loadingHysteresis: number;
5477
navbarPosition: NavbarPositions;
5578
iconOnly: boolean;
79+
imageType: ImageTypeDictionary;
80+
imageFormat: ImageFormatDictionary;
5681
};
5782

5883
const ExtensionSettingsConstants = {
@@ -75,10 +100,14 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
75100
const loadingHysteresis = ref(-1);
76101
const navbarPosition = ref<NavbarPositions>(NavbarPosition.Auto);
77102
const iconOnly = ref(true);
103+
const imageType = reactive<ExtensionSettings['imageType']>(DefaultImageTypes);
104+
const imageFormat = reactive<ExtensionSettings['imageFormat']>(DefaultImageFormats);
78105

79106
const clearState = () => {
80107
Object.assign(cacheRetention, DefaultCacheRetention);
81108
Object.assign(routeDictionary, DefaultRoutes);
109+
Object.assign(imageType, DefaultImageTypes);
110+
Object.assign(imageFormat, DefaultImageFormats);
82111
restoreRoute.value = true;
83112
restorePanel.value = false;
84113
progressType.value = ProgressType.Show;
@@ -92,14 +121,16 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
92121
enabledRoutes: toRaw(routeDictionary),
93122
restoreRoute: restoreRoute.value,
94123
restorePanel: restorePanel.value,
95-
loadLists,
124+
loadLists: toRaw(loadLists),
96125
loadListsPageSize: loadListsPageSize.value,
97126
progressType: progressType.value,
98127
enableRatings: enableRatings.value,
99128
backgroundColor: backgroundColor.value,
100129
loadingHysteresis: loadingHysteresis.value,
101130
navbarPosition: navbarPosition.value,
102131
iconOnly: iconOnly.value,
132+
imageType: toRaw(imageType),
133+
imageFormat: toRaw(imageFormat),
103134
}),
104135
500,
105136
);
@@ -136,6 +167,8 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
136167
if (restored?.loadingHysteresis !== undefined) loadingHysteresis.value = restored.loadingHysteresis;
137168
if (restored?.navbarPosition !== undefined) navbarPosition.value = restored.navbarPosition;
138169
if (restored?.iconOnly !== undefined) iconOnly.value = restored.iconOnly;
170+
if (restored?.imageType !== undefined) Object.assign(imageType, restored.imageType);
171+
if (restored?.imageFormat !== undefined) Object.assign(imageFormat, restored.imageFormat);
139172

140173
if (!chromeRuntimeId) routeDictionary[Route.Progress] = false;
141174
};
@@ -166,6 +199,12 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
166199
saveState().catch(err => Logger.error('Failed to save enabled tab extension settings', { tab, err }));
167200
};
168201

202+
const getImageSettings = (route: Route) =>
203+
computed(() => ({
204+
type: imageType[route] === 'default' ? undefined : imageType[route],
205+
backdrop: imageFormat[route] === 'backdrop',
206+
}));
207+
169208
return {
170209
initExtensionSettingsStore,
171210
restoreDefaultTab,
@@ -266,6 +305,21 @@ export const useExtensionSettingsStore = defineStore(ExtensionSettingsConstants.
266305
saveState().catch(err => Logger.error('Failed to save icon only extension settings', { value, err }));
267306
},
268307
}),
308+
getImageSettings,
309+
imageType: computed({
310+
get: () => imageType,
311+
set: (value: ImageTypeDictionary) => {
312+
Object.assign(imageType, value);
313+
saveState().catch(err => Logger.error('Failed to save image type extension settings', { value, err }));
314+
},
315+
}),
316+
imageFormat: computed({
317+
get: () => imageFormat,
318+
set: (value: ImageFormatDictionary) => {
319+
Object.assign(imageFormat, value);
320+
saveState().catch(err => Logger.error('Failed to save image format extension settings', { value, err }));
321+
},
322+
}),
269323
};
270324
});
271325

0 commit comments

Comments
 (0)