Sharkey/src/client/app/desktop/views/widgets/post-form.vue

129 lines
2.5 KiB
Vue
Raw Normal View History

2018-02-19 23:13:27 +02:00
<template>
<div class="mkw-post-form">
2018-02-21 18:08:49 +02:00
<template v-if="props.design == 0">
<p class="title"><fa icon="pencil-alt"/>{{ $t('title') }}</p>
2018-02-19 23:13:27 +02:00
</template>
2018-05-28 19:44:15 +03:00
<textarea :disabled="posting" v-model="text" @keydown="onKeydown" :placeholder="placeholder"></textarea>
<button @click="post" :disabled="posting">{{ $t('note') }}</button>
2018-02-19 23:13:27 +02:00
</div>
</template>
<script lang="ts">
2018-02-24 17:18:09 +02:00
import define from '../../../common/define-widget';
import i18n from '../../../i18n';
2018-02-19 23:13:27 +02:00
export default define({
name: 'post-form',
2018-02-21 08:30:03 +02:00
props: () => ({
2018-02-19 23:13:27 +02:00
design: 0
2018-02-21 08:30:03 +02:00
})
2018-02-19 23:13:27 +02:00
}).extend({
i18n: i18n('desktop/views/widgets/post-form.vue'),
2018-02-19 23:13:27 +02:00
data() {
return {
posting: false,
text: ''
};
},
2018-05-28 19:44:15 +03:00
computed: {
placeholder(): string {
2018-05-28 20:00:45 +03:00
const xs = [
this.$t('@.note-placeholders.a'),
this.$t('@.note-placeholders.b'),
this.$t('@.note-placeholders.c'),
this.$t('@.note-placeholders.d'),
this.$t('@.note-placeholders.e'),
this.$t('@.note-placeholders.f')
2018-05-28 20:00:45 +03:00
];
return xs[Math.floor(Math.random() * xs.length)];
2018-05-28 19:44:15 +03:00
}
},
2018-02-19 23:13:27 +02:00
methods: {
func() {
if (this.props.design == 1) {
this.props.design = 0;
} else {
this.props.design++;
}
2018-04-29 11:17:15 +03:00
this.save();
2018-02-19 23:13:27 +02:00
},
onKeydown(e) {
2018-07-20 20:14:24 +03:00
if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey) && !this.posting && this.text) this.post();
2018-02-19 23:13:27 +02:00
},
post() {
this.posting = true;
2018-11-09 01:13:34 +02:00
this.$root.api('notes/create', {
2018-02-19 23:13:27 +02:00
text: this.text
}).then(data => {
this.clear();
}).catch(err => {
2018-08-06 21:20:26 +03:00
alert('Something happened');
2018-02-19 23:13:27 +02:00
}).then(() => {
this.posting = false;
});
},
clear() {
this.text = '';
}
}
});
</script>
<style lang="stylus" scoped>
2018-09-26 14:19:35 +03:00
2018-03-03 06:47:55 +02:00
2018-02-19 23:13:27 +02:00
.mkw-post-form
background #fff
overflow hidden
2018-04-29 02:51:17 +03:00
border solid 1px rgba(#000, 0.075)
2018-02-19 23:13:27 +02:00
border-radius 6px
> .title
z-index 1
margin 0
padding 0 16px
line-height 42px
font-size 0.9em
font-weight bold
color #888
2018-04-29 02:51:17 +03:00
box-shadow 0 1px rgba(#000, 0.07)
2018-02-19 23:13:27 +02:00
> [data-icon]
2018-02-19 23:13:27 +02:00
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
2018-09-26 14:19:35 +03:00
color var(--primaryForeground)
background var(--primary) !important
2018-02-19 23:13:27 +02:00
outline none
border none
border-radius 4px
transition background 0.1s ease
cursor pointer
&:hover
2018-09-26 14:19:35 +03:00
background var(--primaryLighten10) !important
2018-02-19 23:13:27 +02:00
&:active
2018-09-26 14:19:35 +03:00
background var(--primaryDarken10) !important
2018-02-19 23:13:27 +02:00
transition background 0s ease
</style>