summaryrefslogtreecommitdiff
path: root/src/client/components/page/page.post.vue
blob: 010a96c855757c93fb130fd032225bfa30a4fa27 (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
<template>
<div class="ngbfujlo">
	<mk-textarea class="textarea" :value="text" readonly></mk-textarea>
	<mk-button primary @click="post()" :disabled="posting || posted">{{ posted ? $t('posted-from-post-form') : $t('post-from-post-form') }}</mk-button>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import i18n from '../../i18n';
import MkTextarea from '../ui/textarea.vue';
import MkButton from '../ui/button.vue';

export default Vue.extend({
	i18n,
	components: {
		MkTextarea,
		MkButton,
	},
	props: {
		value: {
			required: true
		},
		script: {
			required: true
		}
	},
	data() {
		return {
			text: this.script.interpolate(this.value.text),
			posted: false,
			posting: false,
		};
	},
	watch: {
		'script.vars': {
			handler() {
				this.text = this.script.interpolate(this.value.text);
			},
			deep: true
		}
	},
	methods: {
		post() {
			this.posting = true;
			this.$root.api('notes/create', {
				text: this.text,
			}).then(() => {
				this.posted = true;
				this.$root.dialog({
					type: 'success',
					iconOnly: true, autoClose: true
				});
			});
		}
	}
});
</script>

<style lang="scss" scoped>
.ngbfujlo {
	padding: 0 32px 32px 32px;
	border: solid 2px var(--divider);
	border-radius: 6px;

	@media (max-width: 600px) {
		padding: 0 16px 16px 16px;

		> .textarea {
			margin-top: 16px;
			margin-bottom: 16px;
		}
	}
}
</style>