Skip to content

Commit 35d2e3d

Browse files
committed
feat(settings): adds watching settings
1 parent f23eee1 commit 35d2e3d

File tree

6 files changed

+148
-12
lines changed

6 files changed

+148
-12
lines changed

src/components/AppComponent.vue

+2-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const onBack = () => {
5656
</script>
5757

5858
<template>
59-
<div ref="appRef" class="container">
59+
<div ref="appRef">
6060
<NDialogProvider :to="appRef">
6161
<header :class="{ open: panel }">
6262
<RouterView v-slot="{ Component }" name="navbar">
@@ -162,7 +162,7 @@ main {
162162
flex-direction: column;
163163
align-items: center;
164164
justify-content: center;
165-
min-height: calc(100% - #{layout.$header-navbar-height});
165+
min-height: calc(100dvh - #{layout.$header-navbar-height});
166166
margin-top: layout.$header-navbar-height;
167167
}
168168
@@ -173,10 +173,6 @@ footer {
173173
width: 100%;
174174
}
175175
176-
.container {
177-
height: 100%;
178-
}
179-
180176
.panel {
181177
position: relative;
182178
max-height: calc(100% - #{layout.$header-navbar-height});

src/components/views/settings/SettingsComponent.vue

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SettingsLinks from '~/components/views/settings/SettingsLinks.vue';
1010
import SettingsLogs from '~/components/views/settings/SettingsLogs.vue';
1111
import SettingsMenus from '~/components/views/settings/SettingsMenus.vue';
1212
import SettingsTabs from '~/components/views/settings/SettingsTabs.vue';
13+
import SettingsWatching from '~/components/views/settings/SettingsWatching.vue';
1314
import { useI18n } from '~/utils/i18n.utils';
1415
1516
const i18n = useI18n('settings');
@@ -25,9 +26,10 @@ const sections: Section[] = [
2526
{ title: 'menu__tabs', reference: ref(), component: SettingsTabs },
2627
{ title: 'menu__links', reference: ref(), component: SettingsLinks },
2728
{ title: 'menu__menus', reference: ref(), component: SettingsMenus },
29+
{ title: 'menu__watching', reference: ref(), component: SettingsWatching },
2830
{ title: 'menu__cache', reference: ref(), component: SettingsCache },
29-
{ title: 'menu__logs', reference: ref(), component: SettingsLogs },
3031
{ title: 'menu__export', reference: ref(), component: SettingsExport },
32+
{ title: 'menu__logs', reference: ref(), component: SettingsLogs },
3133
];
3234
3335
const focus = ref();
@@ -66,7 +68,7 @@ onDeactivated(() => {
6668
class="menu"
6769
bordered
6870
collapse-mode="width"
69-
width="5.125rem"
71+
width="6rem"
7072
:collapsed-width="0"
7173
:native-scrollbar="false"
7274
show-trigger="bar"
@@ -128,6 +130,10 @@ onDeactivated(() => {
128130
margin-bottom: 1rem;
129131
}
130132
133+
&:hover {
134+
z-index: var(--length);
135+
}
136+
131137
&.target {
132138
border-color: var(--n-color-target);
133139
}
@@ -136,10 +142,12 @@ onDeactivated(() => {
136142
.menu {
137143
@include mixin.hover-background;
138144
145+
height: calc(100dvh - #{layout.$header-navbar-height});
139146
padding: 0.5rem;
140147
}
141148
142149
.content {
150+
height: 100dvh;
143151
background: transparent;
144152
}
145153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<script lang="ts" setup>
2+
import { NSelect, NSwitch } from 'naive-ui';
3+
4+
import { ref } from 'vue';
5+
6+
import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue';
7+
import { PollingIntervals, useWatchingStoreRefs } from '~/stores/data/watching.store';
8+
import { useI18n } from '~/utils/i18n.utils';
9+
10+
const i18n = useI18n('settings', 'watching');
11+
12+
const { polling, override } = useWatchingStoreRefs();
13+
14+
const toSnakeCase = (str: string) =>
15+
str
16+
.replace(/([A-Z])/g, '_$1')
17+
.toLowerCase()
18+
.slice(1);
19+
20+
const options = Object.entries(PollingIntervals).map(([key, value]) => ({
21+
label: i18n(`label_interval_${toSnakeCase(key)}`),
22+
value,
23+
}));
24+
25+
const container = ref();
26+
</script>
27+
28+
<template>
29+
<div ref="container" class="watching-container">
30+
<!-- Polling -->
31+
<SettingsFormItem :label="i18n('label_polling_interval')">
32+
<NSelect
33+
v-model:value="polling"
34+
class="form-select"
35+
:to="container"
36+
:options="options"
37+
/>
38+
</SettingsFormItem>
39+
40+
<!-- Override -->
41+
<SettingsFormItem :label="i18n('label_override')">
42+
<NSwitch v-model:value="override" class="form-switch">
43+
<template #checked>{{ i18n('on', 'common', 'button') }}</template>
44+
<template #unchecked>{{ i18n('off', 'common', 'button') }}</template>
45+
</NSwitch>
46+
</SettingsFormItem>
47+
</div>
48+
</template>
49+
50+
<style lang="scss" scoped>
51+
.watching-container {
52+
display: flex;
53+
flex-direction: column;
54+
gap: 1.5rem;
55+
}
56+
57+
.form-select {
58+
min-width: 10rem;
59+
}
60+
</style>

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

+4
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
"settings__menu__export": {
2727
"message": "Export",
2828
"description": "Export trakt data menu item"
29+
},
30+
"settings__menu__watching": {
31+
"message": "Watching",
32+
"description": "Watching ui menu item"
2933
}
3034
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"settings__watching__label_polling_interval": {
3+
"message": "Configure polling interval for watching state.",
4+
"description": "Label for the polling interval setting."
5+
},
6+
"settings__watching__label_override": {
7+
"message": "Automatically cancel pending checkin request.",
8+
"description": "Label for the override setting."
9+
},
10+
"settings__watching__label_interval_disabled": {
11+
"message": "Disabled",
12+
"description": "Label for the disabled interval."
13+
},
14+
"settings__watching__label_interval_second": {
15+
"message": "1 second",
16+
"description": "Label for the 1 second interval."
17+
},
18+
"settings__watching__label_interval_five_seconds": {
19+
"message": "5 seconds",
20+
"description": "Label for the 5 seconds interval."
21+
},
22+
"settings__watching__label_interval_ten_seconds": {
23+
"message": "10 seconds",
24+
"description": "Label for the 10 seconds interval."
25+
},
26+
"settings__watching__label_interval_thirty_seconds": {
27+
"message": "30 seconds",
28+
"description": "Label for the 30 seconds interval."
29+
},
30+
"settings__watching__label_interval_one_minute": {
31+
"message": "1 minute",
32+
"description": "Label for the 1 minute interval."
33+
},
34+
"settings__watching__label_interval_five_minutes": {
35+
"message": "5 minutes",
36+
"description": "Label for the 5 minutes interval."
37+
},
38+
"settings__watching__label_interval_ten_minutes": {
39+
"message": "10 minutes",
40+
"description": "Label for the 10 minutes interval."
41+
},
42+
"settings__watching__label_interval_thirty_minutes": {
43+
"message": "30 minutes",
44+
"description": "Label for the 30 minutes interval."
45+
}
46+
}

src/stores/data/watching.store.ts

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineStore, storeToRefs } from 'pinia';
22

3-
import { computed, reactive, ref } from 'vue';
3+
import { computed, reactive, ref, watch } from 'vue';
44

55
import type { TraktCheckinRequest, TraktWatching } from '@dvcol/trakt-http-client/models';
66

@@ -27,8 +27,20 @@ type override = {
2727
cancel?: boolean;
2828
};
2929

30+
export const PollingIntervals = {
31+
Disabled: 0,
32+
Second: 1000,
33+
FiveSeconds: 5 * 1000,
34+
TenSeconds: 10 * 1000,
35+
ThirtySeconds: 30 * 1000,
36+
OneMinute: 60 * 1000,
37+
FiveMinutes: 5 * 60 * 1000,
38+
TenMinutes: 10 * 60 * 1000,
39+
ThirtyMinutes: 30 * 60 * 1000,
40+
} as const;
41+
3042
/** 30 seconds */
31-
const defaultPolling = 10 * 1000;
43+
const defaultPolling = PollingIntervals.TenSeconds;
3244

3345
export const useWatchingStore = defineStore(WatchingStoreConstants.Store, () => {
3446
const loading = reactive<override>({});
@@ -141,8 +153,18 @@ export const useWatchingStore = defineStore(WatchingStoreConstants.Store, () =>
141153
const initWatchingStore = async () => {
142154
await restoreState();
143155
await fetchWatching();
144-
if (interval.value) clearInterval(interval.value);
145-
interval.value = setInterval(() => fetchWatching(), polling.value);
156+
watch(
157+
polling,
158+
() => {
159+
if (interval.value) clearInterval(interval.value);
160+
if (!polling.value) return;
161+
interval.value = setInterval(() => fetchWatching(), polling.value);
162+
logger.debug('Polling interval set to', polling.value);
163+
},
164+
{
165+
immediate: true,
166+
},
167+
);
146168
};
147169

148170
return {

0 commit comments

Comments
 (0)