/
App.vue
112 lines (93 loc) · 2.69 KB
/
App.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
<template>
<v-app id="inspire">
<v-navigation-drawer v-model="drawer">
<NavigationDrawer />
</v-navigation-drawer>
<v-app-bar>
<v-app-bar-nav-icon @click="drawer = !drawer"></v-app-bar-nav-icon>
<v-toolbar-title>
<div data-testid="toolbar-title">{{ pageTitle }}</div>
</v-toolbar-title>
<v-spacer></v-spacer>
<teamplte v-if="route.name === 'LearnsetView'">
<BaseButton
text=""
icon
data-testid="edit"
variant="default"
@click="toggleModal"
>
<v-icon>mdi-pencil</v-icon>
</BaseButton>
<BaseButton
text=""
icon
data-testid="delete"
variant="default"
@click="deleteLearnset"
>
<v-icon>mdi-delete</v-icon>
</BaseButton>
<EditLearnsetModal
:learnset-title="pageTitle"
title="카드 뭉치 이름 수정하기"
ref="modal"
@edit-learnset="editLearnset"
@reset-learnset="resetLearnset"
/>
</teamplte>
</v-app-bar>
<v-main>
<router-view :key="route.path" />
</v-main>
</v-app>
</template>
<script setup lang="ts">
import NavigationDrawer from '@/components/NavigationDrawer.vue';
import BaseButton from '@/components/BaseButton.vue';
import EditLearnsetModal from '@/components/EditLearnsetModal.vue';
import { ref, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from 'vuex';
import type { MyStore } from '@/store/types';
import { MutationTypes } from '@/store/mutations';
const drawer = ref(true);
const route = useRoute();
const router = useRouter();
const store: MyStore = useStore();
const learnset = computed(() => {
const learnset = store.state.learnsets.find(
({ id }) => id === route.params.id
);
return learnset;
});
const pageTitle = computed(() => {
return learnset.value ? learnset.value.name : 'Dashboard';
});
const deleteLearnset = () => {
const deleteLearnset = confirm(
`"${pageTitle.value}" 카드 뭉치를 삭제하시겠습니까?`
);
if (deleteLearnset) {
router.push('/');
store.commit(MutationTypes.DELETE_LEARNSET, learnset.value);
}
return;
};
const modal = ref<InstanceType<typeof EditLearnsetModal> | null>(null);
const toggleModal = () => {
modal.value?.toggleModal();
};
const editLearnset = (newTitle: string) => {
if (learnset.value) {
learnset.value.name = newTitle;
store.commit(MutationTypes.UPDATE_LEARNSET, learnset.value);
}
};
const resetLearnset = () => {
if (learnset.value) {
store.commit(MutationTypes.RESET_LEARNSET, learnset.value.id);
}
};
</script>
<style scoped></style>