-
Notifications
You must be signed in to change notification settings - Fork 309
/
PresetManageDialog.vue
125 lines (111 loc) · 3.72 KB
/
PresetManageDialog.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<template>
<QDialog :modelValue="props.openDialog" @update:modelValue="updateOpenDialog">
<QCard class="setting-card q-pa-md dialog-card">
<QCardSection>
<div class="text-h5">プリセット管理</div>
</QCardSection>
<QCardActions class="q-px-md q-py-sm">
<div class="full-width row wrap justify-between">
<QList bordered separator class="col-sm-grow">
<Draggable
:modelValue="previewPresetList"
itemKey="key"
@update:modelValue="reorderPreset"
>
<template #item="{ element: item }">
<QItem>
<QItemSection>{{ item.name }}</QItemSection>
<QSpace />
<QItemSection avatar>
<QBtn
icon="delete"
flat
color="display"
@click="deletePreset(item.key)"
></QBtn>
</QItemSection>
</QItem>
</template>
</Draggable>
<QItem v-if="presetList.length === 0">
<QItemSection class="display">
プリセットがありません
</QItemSection>
</QItem>
</QList>
</div>
</QCardActions>
</QCard>
</QDialog>
</template>
<script setup lang="ts">
import { computed, ref } from "vue";
import Draggable from "vuedraggable";
import { useStore } from "@/store";
import { useDefaultPreset } from "@/composables/useDefaultPreset";
import { Preset, PresetKey } from "@/type/preload";
const props = defineProps<{
openDialog: boolean;
}>();
const emit = defineEmits<{
(e: "update:openDialog", val: boolean): void;
}>();
const updateOpenDialog = (isOpen: boolean) => emit("update:openDialog", isOpen);
const store = useStore();
const { isDefaultPresetKey } = useDefaultPreset();
const presetItems = computed(() => store.state.presetItems);
const presetKeys = computed(() => store.state.presetKeys);
const presetList = computed(() =>
presetKeys.value
.filter((key) => presetItems.value[key] != undefined)
.filter((key) => !isDefaultPresetKey(key))
.map((key) => ({
key,
...presetItems.value[key],
})),
);
const isPreview = ref(false);
const previewPresetKeys = ref(store.state.presetKeys);
const previewPresetList = computed(() =>
isPreview.value
? previewPresetKeys.value
.filter((key) => presetItems.value[key] != undefined)
.filter((key) => !isDefaultPresetKey(key))
.map((key) => ({
key,
...presetItems.value[key],
}))
: presetList.value,
);
const reorderPreset = (featurePresetList: (Preset & { key: PresetKey })[]) => {
const newPresetKeys = featurePresetList.map((item) => item.key);
previewPresetKeys.value = newPresetKeys;
isPreview.value = true;
// デフォルトプリセットは表示するlistから除外しているので、末尾に追加しておかないと失われる
const defaultPresetKeys = presetKeys.value.filter(isDefaultPresetKey);
void store.actions
.SAVE_PRESET_ORDER({
presetKeys: [...newPresetKeys, ...defaultPresetKeys],
})
.finally(() => (isPreview.value = false));
};
const deletePreset = async (key: PresetKey) => {
const result = await store.actions.SHOW_WARNING_DIALOG({
title: "プリセットを削除しますか?",
message: `プリセット "${presetItems.value[key].name}" を削除します。`,
actionName: "削除する",
isWarningColorButton: true,
});
if (result === "OK") {
await store.actions.DELETE_PRESET({
presetKey: key,
});
}
};
</script>
<style scoped lang="scss">
.dialog-card {
width: 700px;
max-width: 80vw;
}
</style>