|
| 1 | +<script lang="ts" setup> |
| 2 | +import { NButton, NFlex, NIcon } from 'naive-ui'; |
| 3 | +import { computed, onMounted, type PropType, ref, toRefs } from 'vue'; |
| 4 | +
|
| 5 | +import IconCheckedList from '~/components/icons/IconCheckedList.vue'; |
| 6 | +import IconCloseSmall from '~/components/icons/IconCloseSmall.vue'; |
| 7 | +import IconGrid from '~/components/icons/IconGrid.vue'; |
| 8 | +import IconGridEmpty from '~/components/icons/IconGridEmpty.vue'; |
| 9 | +import IconListEmpty from '~/components/icons/IconListEmpty.vue'; |
| 10 | +import IconPlay from '~/components/icons/IconPlay.vue'; |
| 11 | +import IconPlayFilled from '~/components/icons/IconPlayFilled.vue'; |
| 12 | +
|
| 13 | +import IconTrakt from '~/components/icons/IconTrakt.vue'; |
| 14 | +import PanelButtonProgress from '~/components/views/panel/PanelButtonProgress.vue'; |
| 15 | +import { usePanelButtons } from '~/components/views/panel/use-panel-buttons'; |
| 16 | +import { |
| 17 | + type ListEntity, |
| 18 | + ListType, |
| 19 | + useListsStore, |
| 20 | + useListsStoreRefs, |
| 21 | +} from '~/stores/data/list.store'; |
| 22 | +import { useI18n } from '~/utils'; |
| 23 | +
|
| 24 | +const props = defineProps({ |
| 25 | + watched: { |
| 26 | + type: Boolean, |
| 27 | + required: false, |
| 28 | + }, |
| 29 | + watchedLoading: { |
| 30 | + type: Boolean, |
| 31 | + required: false, |
| 32 | + }, |
| 33 | + collected: { |
| 34 | + type: Boolean, |
| 35 | + required: false, |
| 36 | + }, |
| 37 | + collectedLoading: { |
| 38 | + type: Boolean, |
| 39 | + required: false, |
| 40 | + }, |
| 41 | + checkin: { |
| 42 | + type: Boolean, |
| 43 | + required: false, |
| 44 | + }, |
| 45 | + checkinProgress: { |
| 46 | + type: Number, |
| 47 | + required: false, |
| 48 | + }, |
| 49 | + checkinLoading: { |
| 50 | + type: Boolean, |
| 51 | + required: false, |
| 52 | + }, |
| 53 | + activeLists: { |
| 54 | + type: Array as PropType<ListEntity['id'][]>, |
| 55 | + required: false, |
| 56 | + }, |
| 57 | + activeLoading: { |
| 58 | + type: Boolean, |
| 59 | + required: false, |
| 60 | + }, |
| 61 | +}); |
| 62 | +
|
| 63 | +const { watched, collected, activeLoading } = toRefs(props); |
| 64 | +
|
| 65 | +const i18n = useI18n('panel', 'buttons'); |
| 66 | +
|
| 67 | +const root = ref<HTMLDivElement>(); |
| 68 | +
|
| 69 | +const { removeOptions, timeOptions } = usePanelButtons(); |
| 70 | +
|
| 71 | +const watchedOptions = computed(() => { |
| 72 | + if (watched.value) return removeOptions; |
| 73 | + return timeOptions; |
| 74 | +}); |
| 75 | +
|
| 76 | +const collectionOptions = computed(() => { |
| 77 | + if (collected.value) return removeOptions; |
| 78 | + return timeOptions; |
| 79 | +}); |
| 80 | +
|
| 81 | +const { lists, loading } = useListsStoreRefs(); |
| 82 | +const { fetchLists, getIcon } = useListsStore(); |
| 83 | +
|
| 84 | +const listsLoading = computed(() => { |
| 85 | + return loading.value || activeLoading.value; |
| 86 | +}); |
| 87 | +
|
| 88 | +const listOptions = computed(() => { |
| 89 | + return lists.value |
| 90 | + ?.filter(list => [ListType.List, ListType.Watchlist].map(String).includes(list.type)) |
| 91 | + .map(list => { |
| 92 | + return { |
| 93 | + label: list.type === ListType.Watchlist ? i18n(list.name) : list.name, |
| 94 | + value: list.id, |
| 95 | + icon: getIcon(list), |
| 96 | + }; |
| 97 | + }); |
| 98 | +}); |
| 99 | +
|
| 100 | +onMounted(() => { |
| 101 | + fetchLists(); |
| 102 | +}); |
| 103 | +</script> |
| 104 | + |
| 105 | +<template> |
| 106 | + <div ref="root" class="panel-buttons"> |
| 107 | + <!-- Checkin --> |
| 108 | + <NFlex class="button-container checkin" justify="center" align="center"> |
| 109 | + <NButton round :secondary="!checkin" type="error" :disabled="checkinLoading"> |
| 110 | + <template #icon> |
| 111 | + <NIcon |
| 112 | + class="button-icon" |
| 113 | + :component="checkin ? IconCloseSmall : IconTrakt" |
| 114 | + :style="{ |
| 115 | + '--trakt-icon-path': 'var(--color-error-lighter)', |
| 116 | + '--trakt-icon-circle': 'transparent', |
| 117 | + }" |
| 118 | + /> |
| 119 | + </template> |
| 120 | + <span>{{ i18n(`label__${ checkin ? 'cancel_checkin' : 'checkin' }`) }}</span> |
| 121 | + </NButton> |
| 122 | + </NFlex> |
| 123 | + |
| 124 | + <!-- List --> |
| 125 | + <NFlex class="button-container list" justify="center" align="center"> |
| 126 | + <PanelButtonProgress |
| 127 | + :options="listOptions" |
| 128 | + :value="activeLists" |
| 129 | + :select="{ |
| 130 | + options: listOptions, |
| 131 | + value: activeLists, |
| 132 | + multiple: true, |
| 133 | + scrollable: true, |
| 134 | + }" |
| 135 | + :icon="activeLists?.length ? IconCheckedList : IconListEmpty" |
| 136 | + :filled="!!activeLists?.length" |
| 137 | + :disabled="listsLoading" |
| 138 | + type="warning" |
| 139 | + > |
| 140 | + {{ i18n(`label__list__${ activeLists?.length ? 'update' : 'add' }`) }} |
| 141 | + </PanelButtonProgress> |
| 142 | + </NFlex> |
| 143 | + |
| 144 | + <!-- Collection --> |
| 145 | + <NFlex class="button-container collection" justify="center" align="center"> |
| 146 | + <PanelButtonProgress |
| 147 | + :select="{ |
| 148 | + options: collectionOptions, |
| 149 | + }" |
| 150 | + :icon="collected ? IconGrid : IconGridEmpty" |
| 151 | + :filled="collected" |
| 152 | + :disabled="collectedLoading" |
| 153 | + type="info" |
| 154 | + > |
| 155 | + {{ i18n(`label__collection__${ collected ? 'remove' : 'add' }`) }} |
| 156 | + </PanelButtonProgress> |
| 157 | + </NFlex> |
| 158 | + |
| 159 | + <!-- History --> |
| 160 | + <NFlex class="button-container history" justify="center" align="center"> |
| 161 | + <PanelButtonProgress |
| 162 | + :select="{ |
| 163 | + options: watchedOptions, |
| 164 | + }" |
| 165 | + :icon="watched ? IconPlayFilled : IconPlay" |
| 166 | + :filled="watched" |
| 167 | + :disabled="watchedLoading" |
| 168 | + > |
| 169 | + {{ i18n(`label__history__${ watched ? 'remove' : 'add' }`) }} |
| 170 | + </PanelButtonProgress> |
| 171 | + </NFlex> |
| 172 | + </div> |
| 173 | +</template> |
| 174 | + |
| 175 | +<style lang="scss" scoped> |
| 176 | +.panel-buttons { |
| 177 | + display: flex; |
| 178 | + flex-wrap: wrap; |
| 179 | + gap: 1.25rem 1rem; |
| 180 | + align-items: center; |
| 181 | + justify-content: center; |
| 182 | + width: 100%; |
| 183 | + margin: 0.75rem 1rem 1.25rem; |
| 184 | +
|
| 185 | + .button-container { |
| 186 | + i { |
| 187 | + margin-left: calc(0% - var(--n-icon-margin)); |
| 188 | + } |
| 189 | +
|
| 190 | + &.history, |
| 191 | + &.collection { |
| 192 | + min-width: 12.5rem; |
| 193 | + } |
| 194 | +
|
| 195 | + &.checkin, |
| 196 | + &.list { |
| 197 | + min-width: 10rem; |
| 198 | + } |
| 199 | + } |
| 200 | +} |
| 201 | +
|
| 202 | +@media (width <= 800px) { |
| 203 | + .panel-buttons { |
| 204 | + width: 80%; |
| 205 | +
|
| 206 | + .button-container { |
| 207 | + flex: 1 1 40%; |
| 208 | + } |
| 209 | + } |
| 210 | +} |
| 211 | +</style> |
0 commit comments