summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/settings/reaction.vue
blob: a188ba353dfa47eaf23dc716d693bfcdc89d0cac (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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<div class="_formRoot">
	<FromSlot class="_formBlock">
		<template #label>{{ $ts.reactionSettingDescription }}</template>
		<div v-panel style="border-radius: 6px;">
			<XDraggable v-model="reactions" class="zoaiodol" :item-key="item => item" animation="150" delay="100" delay-on-touch-only="true">
				<template #item="{element}">
					<button class="_button item" @click="remove(element, $event)">
						<MkEmoji :emoji="element" :normal="true"/>
					</button>
				</template>
				<template #footer>
					<button class="_button add" @click="chooseEmoji"><i class="fas fa-plus"></i></button>
				</template>
			</XDraggable>
		</div>
		<template #caption>{{ $ts.reactionSettingDescription2 }} <button class="_textButton" @click="preview">{{ $ts.preview }}</button></template>
	</FromSlot>

	<FormRadios v-model="reactionPickerSize" class="_formBlock">
		<template #label>{{ $ts.size }}</template>
		<option :value="1">{{ $ts.small }}</option>
		<option :value="2">{{ $ts.medium }}</option>
		<option :value="3">{{ $ts.large }}</option>
	</FormRadios>
	<FormRadios v-model="reactionPickerWidth" class="_formBlock">
		<template #label>{{ $ts.numberOfColumn }}</template>
		<option :value="1">5</option>
		<option :value="2">6</option>
		<option :value="3">7</option>
		<option :value="4">8</option>
		<option :value="5">9</option>
	</FormRadios>
	<FormRadios v-model="reactionPickerHeight" class="_formBlock">
		<template #label>{{ $ts.height }}</template>
		<option :value="1">{{ $ts.small }}</option>
		<option :value="2">{{ $ts.medium }}</option>
		<option :value="3">{{ $ts.large }}</option>
		<option :value="4">{{ $ts.large }}+</option>
	</FormRadios>

	<FormSwitch v-model="reactionPickerUseDrawerForMobile" class="_formBlock">
		{{ $ts.useDrawerReactionPickerForMobile }}
		<template #caption>{{ $ts.needReloadToApply }}</template>
	</FormSwitch>

	<FormSection>
		<div style="display: flex; gap: var(--margin); flex-wrap: wrap;">
			<FormButton inline @click="preview"><i class="fas fa-eye"></i> {{ $ts.preview }}</FormButton>
			<FormButton inline danger @click="setDefault"><i class="fas fa-undo"></i> {{ $ts.default }}</FormButton>
		</div>
	</FormSection>
</div>
</template>

<script lang="ts" setup>
import { watch } from 'vue';
import XDraggable from 'vuedraggable';
import FormInput from '@/components/form/input.vue';
import FormRadios from '@/components/form/radios.vue';
import FromSlot from '@/components/form/slot.vue';
import FormButton from '@/components/ui/button.vue';
import FormSection from '@/components/form/section.vue';
import FormSwitch from '@/components/form/switch.vue';
import * as os from '@/os';
import { defaultStore } from '@/store';
import * as symbols from '@/symbols';
import { i18n } from '@/i18n';

let reactions = $ref(JSON.parse(JSON.stringify(defaultStore.state.reactions)));

const reactionPickerSize = $computed(defaultStore.makeGetterSetter('reactionPickerSize'));
const reactionPickerWidth = $computed(defaultStore.makeGetterSetter('reactionPickerWidth'));
const reactionPickerHeight = $computed(defaultStore.makeGetterSetter('reactionPickerHeight'));
const reactionPickerUseDrawerForMobile = $computed(defaultStore.makeGetterSetter('reactionPickerUseDrawerForMobile'));

function save() {
	defaultStore.set('reactions', reactions);
}

function remove(reaction, ev: MouseEvent) {
	os.popupMenu([{
		text: i18n.ts.remove,
		action: () => {
			reactions = reactions.filter(x => x !== reaction);
		}
	}], ev.currentTarget ?? ev.target);
}

function preview(ev: MouseEvent) {
	os.popup(import('@/components/emoji-picker-dialog.vue'), {
		asReactionPicker: true,
		src: ev.currentTarget ?? ev.target,
	}, {}, 'closed');
}

async function setDefault() {
	const { canceled } = await os.confirm({
		type: 'warning',
		text: i18n.ts.resetAreYouSure,
	});
	if (canceled) return;

	reactions = JSON.parse(JSON.stringify(defaultStore.def.reactions.default));
}

function chooseEmoji(ev: MouseEvent) {
	os.pickEmoji(ev.currentTarget ?? ev.target, {
		showPinned: false
	}).then(emoji => {
		if (!reactions.includes(emoji)) {
			reactions.push(emoji);
		}
	});
}

watch($$(reactions), () => {
	save();
}, {
	deep: true,
});

defineExpose({
	[symbols.PAGE_INFO]: {
		title: i18n.ts.reaction,
		icon: 'fas fa-laugh',
		action: {
			icon: 'fas fa-eye',
			handler: preview,
		},
		bg: 'var(--bg)',
	},
});
</script>

<style lang="scss" scoped>
.zoaiodol {
	padding: 12px;
	font-size: 1.1em;

	> .item {
		display: inline-block;
		padding: 8px;
		cursor: move;
	}

	> .add {
		display: inline-block;
		padding: 8px;
	}
}
</style>