|
| 1 | +<script lang="ts" setup> |
| 2 | +import { NButton, NFormItem, NIcon, NSelect } from 'naive-ui'; |
| 3 | +
|
| 4 | +import { reactive, ref } from 'vue'; |
| 5 | +
|
| 6 | +import IconRestore from '~/components/icons/IconRestore.vue'; |
| 7 | +import { NotificationService } from '~/services/notification.service'; |
| 8 | +import { TraktService } from '~/services/trakt.service'; |
| 9 | +import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store'; |
| 10 | +import { useI18n } from '~/utils'; |
| 11 | +import { CacheRetention } from '~/utils/cache.utils'; |
| 12 | +
|
| 13 | +const i18n = useI18n('settings', 'cache'); |
| 14 | +
|
| 15 | +const { traktCacheRetention, tmdbCacheRetention } = useExtensionSettingsStoreRefs(); |
| 16 | +
|
| 17 | +const cacheOptions = Object.entries(CacheRetention).map(([key, value]) => ({ |
| 18 | + label: key, |
| 19 | + value, |
| 20 | +})); |
| 21 | +
|
| 22 | +const loading = reactive({}); |
| 23 | +
|
| 24 | +const onClick = async (fn: () => Promise<void>, index: number) => { |
| 25 | + loading[index] = true; |
| 26 | +
|
| 27 | + try { |
| 28 | + await fn(); |
| 29 | + NotificationService.message.success(i18n('evict_success')); |
| 30 | + } catch (error) { |
| 31 | + console.error('Failed to evict cache.', error); |
| 32 | + NotificationService.error(i18n('evict_failure'), error); |
| 33 | + } finally { |
| 34 | + loading[index] = false; |
| 35 | + } |
| 36 | +}; |
| 37 | +
|
| 38 | +const evictScopes = [ |
| 39 | + { label: i18n('evict_images'), click: TraktService.evict.tmdb }, |
| 40 | + { |
| 41 | + label: i18n('evict_progress'), |
| 42 | + click: () => |
| 43 | + Promise.all([ |
| 44 | + TraktService.evict.progress.movies(), |
| 45 | + TraktService.evict.progress.shows(), |
| 46 | + TraktService.evict.collection.movies(), |
| 47 | + TraktService.evict.collection.shows(), |
| 48 | + ]), |
| 49 | + }, |
| 50 | + { label: i18n('evict_calendar'), click: TraktService.evict.calendar }, |
| 51 | + { label: i18n('evict_history'), click: TraktService.evict.history }, |
| 52 | + { |
| 53 | + label: i18n('evict_lists'), |
| 54 | + click: () => |
| 55 | + Promise.all([ |
| 56 | + TraktService.evict.watchlist(), |
| 57 | + TraktService.evict.favorites(), |
| 58 | + TraktService.evict.list(), |
| 59 | + TraktService.evict.lists(), |
| 60 | + TraktService.evict.collection.movies(), |
| 61 | + TraktService.evict.collection.shows(), |
| 62 | + ]), |
| 63 | + }, |
| 64 | + { label: i18n('evict_search'), click: TraktService.evict.search }, |
| 65 | + { label: i18n('evict_shows'), click: TraktService.evict.shows }, |
| 66 | + { label: i18n('evict_seasons'), click: TraktService.evict.seasons }, |
| 67 | + { label: i18n('evict_episodes'), click: TraktService.evict.episodes }, |
| 68 | + { label: i18n('evict_movies'), click: TraktService.evict.movies }, |
| 69 | + { label: i18n('evict_people'), click: TraktService.evict.people }, |
| 70 | +].map((item, index) => ({ ...item, click: () => onClick(item.click, index) })); |
| 71 | +
|
| 72 | +const container = ref(); |
| 73 | +</script> |
| 74 | + |
| 75 | +<template> |
| 76 | + <div ref="container" class="cache-container"> |
| 77 | + <NFormItem |
| 78 | + class="form-row" |
| 79 | + :label="i18n('label_retention_trakt')" |
| 80 | + :show-feedback="false" |
| 81 | + label-placement="left" |
| 82 | + > |
| 83 | + <NSelect |
| 84 | + v-model:value="traktCacheRetention" |
| 85 | + class="form-select" |
| 86 | + :to="container" |
| 87 | + :options="cacheOptions" |
| 88 | + /> |
| 89 | + </NFormItem> |
| 90 | + <NFormItem |
| 91 | + class="form-row" |
| 92 | + :label="i18n('label_retention_images')" |
| 93 | + :show-feedback="false" |
| 94 | + label-placement="left" |
| 95 | + > |
| 96 | + <NSelect |
| 97 | + v-model:value="tmdbCacheRetention" |
| 98 | + :to="container" |
| 99 | + :options="cacheOptions" |
| 100 | + /> |
| 101 | + </NFormItem> |
| 102 | + |
| 103 | + <NFormItem |
| 104 | + v-for="({ label, click }, index) in evictScopes" |
| 105 | + :key="index" |
| 106 | + class="form-row" |
| 107 | + :show-feedback="false" |
| 108 | + label-placement="left" |
| 109 | + > |
| 110 | + <template #label> |
| 111 | + <span class="from-label">{{ label }}</span> |
| 112 | + </template> |
| 113 | + <NButton |
| 114 | + class="evict-button" |
| 115 | + type="warning" |
| 116 | + secondary |
| 117 | + :loading="loading[index]" |
| 118 | + @click="click" |
| 119 | + > |
| 120 | + <span>{{ i18n('evict', 'common', 'button') }}</span> |
| 121 | + <template #icon> |
| 122 | + <NIcon :component="IconRestore" /> |
| 123 | + </template> |
| 124 | + </NButton> |
| 125 | + </NFormItem> |
| 126 | + </div> |
| 127 | +</template> |
| 128 | + |
| 129 | +<style lang="scss" scoped> |
| 130 | +.cache-container { |
| 131 | + display: flex; |
| 132 | + flex-direction: column; |
| 133 | + gap: 1.5rem; |
| 134 | +} |
| 135 | +
|
| 136 | +.evict-button { |
| 137 | + i { |
| 138 | + margin-left: calc(0% - var(--n-icon-margin)); |
| 139 | + } |
| 140 | +} |
| 141 | +
|
| 142 | +.form-select { |
| 143 | + min-width: 10rem; |
| 144 | +} |
| 145 | +
|
| 146 | +.from-label { |
| 147 | + color: var(--white-70); |
| 148 | + font-weight: 600; |
| 149 | + font-size: 1rem; |
| 150 | + transition: color 0.3s var(--n-bezier); |
| 151 | +} |
| 152 | +
|
| 153 | +.form-row { |
| 154 | + display: flex; |
| 155 | + flex: 1 1 auto; |
| 156 | + justify-content: space-between; |
| 157 | +
|
| 158 | + &:hover { |
| 159 | + .from-label { |
| 160 | + color: var(--white-mute); |
| 161 | + } |
| 162 | + } |
| 163 | +} |
| 164 | +</style> |
0 commit comments