Skip to content

Commit c4c2268

Browse files
committed
feat(history): adds settings to load history on startup
1 parent 8d27ba8 commit c4c2268

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

src/components/views/settings/SettingsTabs.vue

+33-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ onBeforeMount(() => {
7676
fetchLists();
7777
});
7878
79-
const { pageSize: historyPageSize } = useHistoryStoreRefs();
79+
const { pageSize: historyPageSize, init } = useHistoryStoreRefs();
8080
const { pageSize: listPageSize } = useListStoreRefs();
8181
const { pageSize: searchPageSize } = useSearchStoreRefs();
8282
const { pageSize: ratingPageSize } = useRatingsStoreRefs();
@@ -155,7 +155,12 @@ const container = ref();
155155
</SettingsFormItem>
156156

157157
<!-- Enable tabs -->
158-
<template v-for="[route, state] of enabledTabs" :key="route">
158+
<div
159+
v-for="[route, state] of enabledTabs"
160+
:key="route"
161+
class="tab-group"
162+
:class="{ collapsed: !state }"
163+
>
159164
<SettingsFormItem
160165
:label="i18n(`label_route_${route}`)"
161166
:warning="
@@ -219,7 +224,21 @@ const container = ref();
219224
<template #unchecked>{{ i18n('off', 'common', 'button') }}</template>
220225
</NSwitch>
221226
</SettingsFormItem>
222-
</template>
227+
228+
<!-- History init -->
229+
<SettingsFormItem
230+
v-if="route === Route.History"
231+
:label="i18n('label_history_init')"
232+
:class="{ show: state }"
233+
class="hidden-form-item"
234+
:warning="init ? i18n('label_init_warning') : undefined"
235+
>
236+
<NSwitch v-model:value="init" class="form-switch">
237+
<template #checked>{{ i18n('on', 'common', 'button') }}</template>
238+
<template #unchecked>{{ i18n('off', 'common', 'button') }}</template>
239+
</NSwitch>
240+
</SettingsFormItem>
241+
</div>
223242

224243
<!-- Enable Ratings -->
225244
<SettingsFormItem
@@ -309,6 +328,17 @@ const container = ref();
309328
padding: 0 0.5rem;
310329
font-size: 0.75rem;
311330
}
331+
332+
.tab-group {
333+
display: flex;
334+
flex-direction: column;
335+
gap: 1.5rem;
336+
transition: gap 0.3s var(--n-bezier);
337+
338+
&.collapsed {
339+
gap: 0;
340+
}
341+
}
312342
}
313343
314344
.form-select {

src/i18n/en/settings/settings-tabs.json

+8
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,13 @@
102102
"settings__tabs__label_extended_warning": {
103103
"message": "This may increase page load times significantly.",
104104
"description": "Warning message for the 'Fetch extended data' setting"
105+
},
106+
"settings__tabs__label_history_init": {
107+
"message": "Fetch history data on startup",
108+
"description": "Label for the 'Fetch history data on startup' setting"
109+
},
110+
"settings__tabs__label_init_warning": {
111+
"message": "This may increase application startup time.",
112+
"description": "Warning message for the 'Fetch history data on startup' setting"
105113
}
106114
}

src/stores/data/history.store.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ErrorService } from '~/services/error.service';
1212
import { Logger } from '~/services/logger.service';
1313
import { NotificationService } from '~/services/notification.service';
1414
import { TraktService } from '~/services/trakt.service';
15+
import { useAuthSettingsStoreRefs } from '~/stores/settings/auth.store';
1516
import { storage } from '~/utils/browser/browser-storage.utils';
1617
import { debounceLoading, useBelowThreshold, useLoadingPlaceholder, useSearchFilter } from '~/utils/store.utils';
1718
import { clearProxy } from '~/utils/vue.utils';
@@ -29,9 +30,10 @@ const HistoryStoreConstants = {
2930

3031
type HistoryState = {
3132
pageSize: number;
33+
extended: boolean;
34+
init: boolean;
3235
historyStart?: Date | number;
3336
historyEnd?: Date | number;
34-
extended?: boolean;
3537
};
3638

3739
export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
@@ -42,6 +44,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
4244
const historyDictionary = reactive<HistoryDictionary>({});
4345
const pagination = ref<TraktClientPagination>();
4446
const extended = ref(false);
47+
const init = ref(false);
4548

4649
const searchHistory = ref('');
4750

@@ -59,6 +62,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
5962
historyStart: historyStart.value?.getTime(),
6063
historyEnd: historyEnd.value?.getTime(),
6164
extended: extended.value,
65+
init: init.value,
6266
});
6367

6468
const restoreState = async () => {
@@ -68,6 +72,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
6872
if (restored?.historyStart) historyStart.value = new Date(restored.historyStart);
6973
if (restored?.historyEnd) historyEnd.value = new Date(restored.historyEnd);
7074
if (restored?.extended) extended.value = restored.extended;
75+
if (restored?.init) init.value = restored.init;
7176
};
7277

7378
const clearState = () => {
@@ -133,6 +138,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
133138
const getMovieHistory = (id: number) => getHistory(id, 'movie');
134139
const getEpisodeHistory = (id: number) => getHistory(id, 'episode');
135140

141+
const { isAuthenticated } = useAuthSettingsStoreRefs();
136142
const initHistoryStore = async () => {
137143
await restoreState();
138144

@@ -154,6 +160,10 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
154160
}
155161
});
156162
});
163+
164+
if (!init.value) return;
165+
if (!isAuthenticated.value) return;
166+
await fetchHistory();
157167
};
158168

159169
return {
@@ -182,6 +192,14 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
182192
saveState().catch(e => Logger.error('Failed to save history extended state', e));
183193
},
184194
}),
195+
init: computed({
196+
get: () => init.value,
197+
set: (value: boolean) => {
198+
init.value = value;
199+
saveState().catch(e => Logger.error('Failed to save history init state', e));
200+
if (value) return fetchHistory();
201+
},
202+
}),
185203
};
186204
});
187205

0 commit comments

Comments
 (0)