summaryrefslogtreecommitdiff
path: root/src/client/pages/settings/reaction.vue
blob: 683cf6dfbe6774ceb89f1d231f816252e4a53ba6 (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
<template>
<div class="_section">
	<div class="_card">
		<div class="_title"><Fa :icon="faLaugh"/> {{ $t('reaction') }}</div>
		<div class="_content">
			<MkInput v-model:value="reactions" style="font-family: 'Segoe UI Emoji', 'Noto Color Emoji', Roboto, HelveticaNeue, Arial, sans-serif">
				{{ $t('reaction') }}<template #desc>{{ $t('reactionSettingDescription') }} <button class="_textButton" @click="chooseEmoji">{{ $t('chooseEmoji') }}</button></template>
			</MkInput>
			<MkButton inline @click="setDefault"><Fa :icon="faUndo"/> {{ $t('default') }}</MkButton>
		</div>
		<div class="_footer">
			<MkButton @click="save()" primary inline :disabled="!changed"><Fa :icon="faSave"/> {{ $t('save') }}</MkButton>
			<MkButton inline @click="preview"><Fa :icon="faEye"/> {{ $t('preview') }}</MkButton>
		</div>
	</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { faLaugh, faSave, faEye } from '@fortawesome/free-regular-svg-icons';
import { faUndo } from '@fortawesome/free-solid-svg-icons';
import MkInput from '@/components/ui/input.vue';
import MkButton from '@/components/ui/button.vue';
import { emojiRegexWithCustom } from '../../../misc/emoji-regex';
import { defaultSettings } from '@/store';
import * as os from '@/os';

export default defineComponent({
	components: {
		MkInput,
		MkButton,
	},

	emits: ['info'],
	
	data() {
		return {
			INFO: {
				header: [{
					title: this.$t('reaction'),
					icon: faLaugh
				}]
			},
			reactions: this.$store.state.settings.reactions.join(''),
			changed: false,
			faLaugh, faSave, faEye, faUndo
		}
	},

	computed: {
		splited(): any {
			return this.reactions.match(emojiRegexWithCustom);
		},
	},

	watch: {
		reactions: {
			handler() {
				this.changed = true;
			},
			deep: true
		}
	},

	mounted() {
		this.$emit('info', this.INFO);
	},

	methods: {
		save() {
			this.$store.dispatch('settings/set', { key: 'reactions', value: this.splited });
			this.changed = false;
		},

		async preview(ev) {
			os.popup(await import('@/components/reaction-picker.vue'), {
				reactions: this.splited,
				showFocus: false,
				src: ev.currentTarget || ev.target,
			}, {}, 'closed');
		},

		setDefault() {
			this.reactions = defaultSettings.reactions.join('');
		},

		async chooseEmoji(ev) {
			os.pickEmoji(ev.currentTarget || ev.target).then(emoji => {
				this.reactions += emoji;
			});
		}
	}
});
</script>