|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <v-list> |
| 4 | + <v-list-item class="contrast-1"> |
| 5 | + <v-list-item-content> |
| 6 | + <v-list-item-title class="text-uppercase">{{ $t('common.reorder') }}</v-list-item-title> |
| 7 | + </v-list-item-content> |
| 8 | + <v-list-item-action class="ma-0"> |
| 9 | + <v-btn icon @click.stop.capture.prevent="dismiss"> |
| 10 | + <v-icon>mdi-close</v-icon> |
| 11 | + </v-btn> |
| 12 | + </v-list-item-action> |
| 13 | + </v-list-item> |
| 14 | + |
| 15 | + <v-list-item class="text--disabled"> |
| 16 | + <v-list-item-icon> |
| 17 | + <v-icon>mdi-home</v-icon> |
| 18 | + </v-list-item-icon> |
| 19 | + <v-list-item-content> |
| 20 | + <v-list-item-title>{{ $t('navigation.home') }}</v-list-item-title> |
| 21 | + </v-list-item-content> |
| 22 | + </v-list-item> |
| 23 | + |
| 24 | + <draggable |
| 25 | + v-model="localItems" |
| 26 | + v-bind="dragOptions" |
| 27 | + handle=".handle" |
| 28 | + > |
| 29 | + <template v-for="(l, index) in localItems"> |
| 30 | + <v-hover :key="index" |
| 31 | + v-slot="{ hover }" |
| 32 | + :disabled="!l.unpinned" |
| 33 | + > |
| 34 | + <v-list-item> |
| 35 | + <v-list-item-icon> |
| 36 | + <v-icon class="handle">mdi-drag-horizontal-variant</v-icon> |
| 37 | + </v-list-item-icon> |
| 38 | + <v-list-item-content> |
| 39 | + <v-list-item-title class="handle">{{ l.name }}</v-list-item-title> |
| 40 | + </v-list-item-content> |
| 41 | + <v-list-item-icon> |
| 42 | + <v-btn icon v-if="!l.unpinned" @click.stop.capture.prevent="unpin(l.id)" x-small> |
| 43 | + <v-icon>mdi-pin</v-icon> |
| 44 | + </v-btn> |
| 45 | + <v-btn icon v-if="hover && l.unpinned" @click.stop.capture.prevent="pin(l.id)" x-small> |
| 46 | + <v-icon>mdi-pin-off</v-icon> |
| 47 | + </v-btn> |
| 48 | + </v-list-item-icon> |
| 49 | + </v-list-item> |
| 50 | + </v-hover> |
| 51 | + </template> |
| 52 | + </draggable> |
| 53 | + </v-list> |
| 54 | + </div> |
| 55 | +</template> |
| 56 | + |
| 57 | +<script lang="ts"> |
| 58 | +import Vue from 'vue' |
| 59 | +import draggable from 'vuedraggable' |
| 60 | +import {LibraryDto} from '@/types/komga-libraries' |
| 61 | +import {ClientSettingLibraryUpdate} from '@/types/komga-clientsettings' |
| 62 | +
|
| 63 | +export default Vue.extend({ |
| 64 | + name: 'ReorderLibraries', |
| 65 | + components: {draggable}, |
| 66 | + data: () => { |
| 67 | + return { |
| 68 | + localItems: [] as LibraryDto[], |
| 69 | + unwatch: false, |
| 70 | + } |
| 71 | + }, |
| 72 | + computed: { |
| 73 | + dragOptions(): any { |
| 74 | + return { |
| 75 | + animation: 200, |
| 76 | + // group: 'item-cards', |
| 77 | + ghostClass: 'ghost', |
| 78 | + } |
| 79 | + }, |
| 80 | + }, |
| 81 | + mounted() { |
| 82 | + this.localItems = this.$store.getters.getLibraries |
| 83 | + }, |
| 84 | + watch: { |
| 85 | + localItems: { |
| 86 | + handler(val: LibraryDto[]) { |
| 87 | + const newSettings = val.map((it, index) => ({ |
| 88 | + libraryId: it.id, |
| 89 | + patch: { |
| 90 | + order: index, |
| 91 | + }, |
| 92 | + } as ClientSettingLibraryUpdate)) |
| 93 | +
|
| 94 | + this.$store.dispatch('updateLibrariesSettings', newSettings) |
| 95 | + }, |
| 96 | + immediate: true, |
| 97 | + }, |
| 98 | + }, |
| 99 | + methods: { |
| 100 | + dismiss() { |
| 101 | + this.$emit('dismiss') |
| 102 | + }, |
| 103 | + unpin(libraryId: string) { |
| 104 | + this.$store.dispatch('updateLibrarySetting', { |
| 105 | + libraryId: libraryId, |
| 106 | + patch: { |
| 107 | + unpinned: true, |
| 108 | + }, |
| 109 | + } as ClientSettingLibraryUpdate) |
| 110 | + this.localItems.find(it => it.id == libraryId).unpinned = true |
| 111 | + }, |
| 112 | + pin(libraryId: string) { |
| 113 | + this.$store.dispatch('updateLibrarySetting', { |
| 114 | + libraryId: libraryId, |
| 115 | + patch: { |
| 116 | + unpinned: false, |
| 117 | + }, |
| 118 | + } as ClientSettingLibraryUpdate) |
| 119 | + this.localItems.find(it => it.id == libraryId).unpinned = false |
| 120 | + }, |
| 121 | + }, |
| 122 | +}) |
| 123 | +</script> |
| 124 | + |
| 125 | +<style scoped> |
| 126 | +.handle { |
| 127 | + cursor: grab !important; |
| 128 | +} |
| 129 | +
|
| 130 | +.ghost { |
| 131 | + opacity: 0.5; |
| 132 | + background: #c8ebfb; |
| 133 | +} |
| 134 | +</style> |
0 commit comments