summaryrefslogtreecommitdiff
path: root/src/client/components/notification-setting-window.vue
blob: d63a3d48a570925da00bb6a762a017b740be636c (plain)
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
<template>
<x-window ref="window" :width="400" :height="450" :no-padding="true" @closed="() => { $emit('closed'); destroyDom(); }" :with-ok-button="true" :ok-button-disabled="false" @ok="ok()">
	<template #header>{{ $t('notificationSetting') }}</template>
	<div class="vv94n3oa">
		<div v-if="showGlobalToggle">
			<mk-switch v-model="useGlobalSetting">
				{{ $t('useGlobalSetting') }}
				<template #desc>{{ $t('useGlobalSettingDesc') }}</template>
			</mk-switch>
		</div>
		<div v-if="!useGlobalSetting">
			<mk-info>{{ $t('notificationSettingDesc') }}</mk-info>
			<mk-button inline @click="disableAll">{{ $t('disableAll') }}</mk-button>
			<mk-button inline @click="enableAll">{{ $t('enableAll') }}</mk-button>
			<mk-switch v-for="type in notificationTypes" :key="type" v-model="typesMap[type]">{{ $t(`_notification._types.${type}`) }}</mk-switch>
		</div>
	</div>
</x-window>
</template>

<script lang="ts">
import Vue, { PropType } from 'vue';
import XWindow from './window.vue';
import MkSwitch from './ui/switch.vue';
import MkInfo from './ui/info.vue';
import MkButton from './ui/button.vue';
import { notificationTypes } from '../../types';

export default Vue.extend({
	components: {
		XWindow,
		MkSwitch,
		MkInfo,
		MkButton
	},

	props: {
		includingTypes: {
			// TODO: これで型に合わないものを弾いてくれるのかどうか要調査
			type: Array as PropType<typeof notificationTypes[number][]>,
			required: false,
			default: null,
		},
		showGlobalToggle: {
			type: Boolean,
			required: false,
			default: true,
		}
	},

	data() {
		return {
			typesMap: {} as Record<typeof notificationTypes[number], boolean>,
			useGlobalSetting: false,
			notificationTypes,
		};
	},

	created() {
		this.useGlobalSetting = this.includingTypes === null && this.showGlobalToggle;

		for (const type of this.notificationTypes) {
			Vue.set(this.typesMap, type, this.includingTypes === null || this.includingTypes.includes(type));
		}
	},

	methods: {
		ok() {
			const includingTypes = this.useGlobalSetting ? null : (Object.keys(this.typesMap) as typeof notificationTypes[number][])
				.filter(type => this.typesMap[type]);

			this.$emit('ok', { includingTypes });
			this.$refs.window.close();
		},

		disableAll() {
			for (const type in this.typesMap) {
				this.typesMap[type as typeof notificationTypes[number]] = false;
			}
		},

		enableAll() {
			for (const type in this.typesMap) {
				this.typesMap[type as typeof notificationTypes[number]] = true;
			}
		}
	}
});
</script>

<style lang="scss" scoped>
.vv94n3oa {
	> div {
		border-top: solid 1px var(--divider);
		padding: 24px;
	}
}
</style>