summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/widgets/post-form.vue
blob: 3c4ade0e81b68843f81839dce4efaea600ee7289 (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
<template>
<div class="mkw-post-form">
	<template v-if="props.design == 0">
		<p class="title">%fa:pencil-alt%%i18n:@title%</p>
	</template>
	<textarea :disabled="posting" v-model="text" @keydown="onKeydown" :placeholder="placeholder"></textarea>
	<button @click="post" :disabled="posting">%i18n:@note%</button>
</div>
</template>

<script lang="ts">
import define from '../../../common/define-widget';
export default define({
	name: 'post-form',
	props: () => ({
		design: 0
	})
}).extend({
	data() {
		return {
			posting: false,
			text: ''
		};
	},
	computed: {
		placeholder(): string {
			const xs = [
				'%i18n:common.note-placeholders.a%',
				'%i18n:common.note-placeholders.b%',
				'%i18n:common.note-placeholders.c%',
				'%i18n:common.note-placeholders.d%',
				'%i18n:common.note-placeholders.e%',
				'%i18n:common.note-placeholders.f%'
			];
			return xs[Math.floor(Math.random() * xs.length)];
		}
	},
	methods: {
		func() {
			if (this.props.design == 1) {
				this.props.design = 0;
			} else {
				this.props.design++;
			}
			this.save();
		},
		onKeydown(e) {
			if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey)) this.post();
		},
		post() {
			this.posting = true;

			(this as any).api('notes/create', {
				text: this.text
			}).then(data => {
				this.clear();
			}).catch(err => {
				alert('失敗した');
			}).then(() => {
				this.posting = false;
			});
		},
		clear() {
			this.text = '';
		}
	}
});
</script>

<style lang="stylus" scoped>
@import '~const.styl'

.mkw-post-form
	background #fff
	overflow hidden
	border solid 1px rgba(#000, 0.075)
	border-radius 6px

	> .title
		z-index 1
		margin 0
		padding 0 16px
		line-height 42px
		font-size 0.9em
		font-weight bold
		color #888
		box-shadow 0 1px rgba(#000, 0.07)

		> [data-fa]
			margin-right 4px

	> textarea
		display block
		width 100%
		max-width 100%
		min-width 100%
		padding 16px
		margin-bottom 28px + 16px
		border none
		border-bottom solid 1px #eee

	> button
		display block
		position absolute
		bottom 8px
		right 8px
		margin 0
		padding 0 10px
		height 28px
		color $theme-color-foreground
		background $theme-color !important
		outline none
		border none
		border-radius 4px
		transition background 0.1s ease
		cursor pointer

		&:hover
			background lighten($theme-color, 10%) !important

		&:active
			background darken($theme-color, 10%) !important
			transition background 0s ease

</style>