2018-03-12 17:42:47 +01:00
|
|
|
<template>
|
|
|
|
<el-dialog
|
2018-08-12 14:26:44 +02:00
|
|
|
:title="$t('modals.new_toot.title')"
|
2018-03-12 17:42:47 +01:00
|
|
|
:visible.sync="newTootModal"
|
|
|
|
width="400px"
|
2018-03-21 07:24:07 +01:00
|
|
|
class="new-toot-modal">
|
|
|
|
<el-form v-on:submit.prevent="toot">
|
2018-07-15 03:34:08 +02:00
|
|
|
<div class="spoiler" v-show="showContentWarning">
|
2018-08-12 14:26:44 +02:00
|
|
|
<el-input :placeholder="$t('modals.new_toot.cw')" v-model="spoiler"></el-input>
|
2018-05-25 01:31:41 +02:00
|
|
|
</div>
|
2018-08-06 18:09:00 +02:00
|
|
|
<Status
|
|
|
|
v-model="status"
|
|
|
|
:opened="newTootModal"
|
|
|
|
@toot="toot"
|
|
|
|
/>
|
2018-03-12 17:42:47 +01:00
|
|
|
</el-form>
|
2018-03-29 06:36:47 +02:00
|
|
|
<div class="preview">
|
2018-04-09 14:10:25 +02:00
|
|
|
<div class="image-wrapper" v-for="media in attachedMedias" v-bind:key="media.id">
|
2018-03-29 06:36:47 +02:00
|
|
|
<img :src="media.preview_url" class="preview-image" />
|
2018-03-29 08:49:39 +02:00
|
|
|
<el-button size="small" type="text" @click="removeAttachment(media)" class="remove-image"><icon name="times-circle"></icon></el-button>
|
2018-03-29 06:36:47 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-03-29 05:09:28 +02:00
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
<div class="upload-image">
|
|
|
|
<el-button size="small" type="text" @click="selectImage"><icon name="camera"></icon></el-button>
|
2018-07-05 15:15:31 +02:00
|
|
|
<input name="image" type="file" class="image-input" ref="image" @change="onChangeImage" :key="attachedMediaId"/>
|
2018-03-29 05:09:28 +02:00
|
|
|
</div>
|
2018-04-11 13:45:26 +02:00
|
|
|
<div class="privacy">
|
2018-04-11 16:12:51 +02:00
|
|
|
<el-dropdown trigger="click" @command="changeVisibility">
|
|
|
|
<el-button size="small" type="text"><icon :name="visibilityIcon"></icon></el-button>
|
2018-04-11 13:45:26 +02:00
|
|
|
<el-dropdown-menu slot="dropdown">
|
2018-08-10 17:59:48 +02:00
|
|
|
<el-dropdown-item :command="visibilityList.Public.value">
|
|
|
|
<icon name="globe" class="privacy-icon"></icon>
|
|
|
|
{{ visibilityList.Public.name }}
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item :command="visibilityList.Unlisted.value">
|
|
|
|
<icon name="unlock" class="privacy-icon"></icon>
|
|
|
|
{{ visibilityList.Unlisted.name }}
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item :command="visibilityList.Private.value">
|
|
|
|
<icon name="lock" class="privacy-icon"></icon>
|
|
|
|
{{ visibilityList.Private.name }}
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item :command="visibilityList.Direct.value">
|
|
|
|
<icon name="envelope" class="privacy-icon" scale="0.8"></icon>
|
|
|
|
{{ visibilityList.Direct.name }}
|
|
|
|
</el-dropdown-item>
|
2018-04-11 13:45:26 +02:00
|
|
|
</el-dropdown-menu>
|
|
|
|
</el-dropdown>
|
|
|
|
</div>
|
2018-07-15 03:34:08 +02:00
|
|
|
<div class="sensitive" v-show="attachedMedias.length > 0">
|
2018-05-24 16:38:24 +02:00
|
|
|
<el-button size="small" type="text" @click="changeSensitive">
|
2018-07-15 03:34:08 +02:00
|
|
|
<icon name="eye-slash" v-show="sensitive"></icon>
|
|
|
|
<icon name="eye" v-show="!sensitive"></icon>
|
2018-05-24 16:38:24 +02:00
|
|
|
</el-button>
|
|
|
|
</div>
|
2018-05-25 01:31:41 +02:00
|
|
|
<div class="content-warning">
|
|
|
|
<el-button size="small" type="text" @click="showContentWarning = !showContentWarning">
|
|
|
|
CW
|
|
|
|
</el-button>
|
|
|
|
</div>
|
2018-03-14 14:19:17 +01:00
|
|
|
<span class="text-count">{{ 500 - status.length }}</span>
|
2018-08-12 14:26:44 +02:00
|
|
|
<el-button @click="close">{{ $t('modals.new_toot.cancel') }}</el-button>
|
|
|
|
<el-button type="primary" @click="toot" v-loading="blockSubmit">{{ $t('modals.new_toot.toot') }}</el-button>
|
2018-03-29 08:49:39 +02:00
|
|
|
<div class="clearfix"></div>
|
2018-03-29 05:09:28 +02:00
|
|
|
</div>
|
2018-03-12 17:42:47 +01:00
|
|
|
</el-dialog>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-14 14:19:17 +01:00
|
|
|
import { mapState } from 'vuex'
|
2018-08-01 16:41:05 +02:00
|
|
|
import Visibility from '../../../../constants/visibility'
|
2018-08-06 18:09:00 +02:00
|
|
|
import Status from './NewToot/Status'
|
2018-03-14 14:19:17 +01:00
|
|
|
|
2018-03-12 17:42:47 +01:00
|
|
|
export default {
|
2018-03-29 04:25:35 +02:00
|
|
|
name: 'new-toot',
|
2018-08-06 18:09:00 +02:00
|
|
|
components: {
|
|
|
|
Status
|
|
|
|
},
|
2018-03-21 15:37:46 +01:00
|
|
|
data () {
|
|
|
|
return {
|
2018-08-10 17:59:48 +02:00
|
|
|
showContentWarning: false,
|
|
|
|
visibilityList: Visibility
|
2018-03-21 15:37:46 +01:00
|
|
|
}
|
|
|
|
},
|
2018-03-12 17:42:47 +01:00
|
|
|
computed: {
|
2018-03-14 14:19:17 +01:00
|
|
|
...mapState({
|
|
|
|
replyToId: (state) => {
|
2018-03-29 04:25:35 +02:00
|
|
|
if (state.TimelineSpace.Modals.NewToot.replyToMessage !== null) {
|
|
|
|
return state.TimelineSpace.Modals.NewToot.replyToMessage.id
|
2018-03-14 14:19:17 +01:00
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2018-03-29 06:05:19 +02:00
|
|
|
},
|
|
|
|
attachedMedias: state => state.TimelineSpace.Modals.NewToot.attachedMedias,
|
2018-07-05 15:15:31 +02:00
|
|
|
attachedMediaId: state => state.TimelineSpace.Modals.NewToot.attachedMediaId,
|
2018-04-11 16:12:51 +02:00
|
|
|
blockSubmit: state => state.TimelineSpace.Modals.NewToot.blockSubmit,
|
2018-04-11 16:19:25 +02:00
|
|
|
visibility: state => state.TimelineSpace.Modals.NewToot.visibility,
|
2018-05-24 16:38:24 +02:00
|
|
|
sensitive: state => state.TimelineSpace.Modals.NewToot.sensitive,
|
2018-04-11 16:12:51 +02:00
|
|
|
visibilityIcon: (state) => {
|
|
|
|
switch (state.TimelineSpace.Modals.NewToot.visibility) {
|
2018-08-01 16:41:05 +02:00
|
|
|
case Visibility.Public.value:
|
2018-04-11 16:12:51 +02:00
|
|
|
return 'globe'
|
2018-08-01 16:41:05 +02:00
|
|
|
case Visibility.Unlisted.value:
|
2018-04-11 16:12:51 +02:00
|
|
|
return 'unlock'
|
2018-08-01 16:41:05 +02:00
|
|
|
case Visibility.Private.value:
|
2018-04-11 16:12:51 +02:00
|
|
|
return 'lock'
|
2018-08-01 16:41:05 +02:00
|
|
|
case Visibility.Direct.value:
|
2018-04-11 16:12:51 +02:00
|
|
|
return 'envelope'
|
|
|
|
default:
|
|
|
|
return 'globe'
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 14:19:17 +01:00
|
|
|
}),
|
2018-03-12 17:42:47 +01:00
|
|
|
newTootModal: {
|
|
|
|
get () {
|
2018-03-29 04:25:35 +02:00
|
|
|
return this.$store.state.TimelineSpace.Modals.NewToot.modalOpen
|
2018-03-12 17:42:47 +01:00
|
|
|
},
|
|
|
|
set (value) {
|
2018-06-19 15:44:33 +02:00
|
|
|
if (value) {
|
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/openModal')
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
|
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
}
|
2018-03-14 14:19:17 +01:00
|
|
|
},
|
|
|
|
status: {
|
|
|
|
get () {
|
2018-03-29 04:25:35 +02:00
|
|
|
return this.$store.state.TimelineSpace.Modals.NewToot.status
|
2018-03-14 14:19:17 +01:00
|
|
|
},
|
|
|
|
set (value) {
|
2018-03-29 04:25:35 +02:00
|
|
|
this.$store.commit('TimelineSpace/Modals/NewToot/updateStatus', value)
|
2018-03-14 14:19:17 +01:00
|
|
|
}
|
2018-05-25 01:31:41 +02:00
|
|
|
},
|
|
|
|
spoiler: {
|
|
|
|
get () {
|
|
|
|
return this.$store.state.TimelineSpace.Modals.NewToot.spoiler
|
|
|
|
},
|
|
|
|
set (value) {
|
|
|
|
this.$store.commit('TimelineSpace/Modals/NewToot/updateSpoiler', value)
|
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
}
|
2018-03-13 00:41:03 +01:00
|
|
|
},
|
2018-04-10 16:13:43 +02:00
|
|
|
watch: {
|
|
|
|
newTootModal: function (newState, oldState) {
|
|
|
|
if (!oldState && newState) {
|
2018-05-25 01:31:41 +02:00
|
|
|
this.showContentWarning = false
|
2018-04-10 16:13:43 +02:00
|
|
|
}
|
2018-03-13 02:04:07 +01:00
|
|
|
}
|
|
|
|
},
|
2018-03-13 00:41:03 +01:00
|
|
|
methods: {
|
|
|
|
close () {
|
2018-08-04 05:09:13 +02:00
|
|
|
this.filteredAccount = []
|
2018-07-05 15:15:31 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaId')
|
2018-06-19 15:44:33 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
|
2018-03-21 15:37:46 +01:00
|
|
|
},
|
2018-03-13 00:41:03 +01:00
|
|
|
toot () {
|
2018-04-11 17:32:59 +02:00
|
|
|
if (!this.newTootModal) {
|
|
|
|
return
|
|
|
|
}
|
2018-03-14 14:19:17 +01:00
|
|
|
if (this.status.length <= 0 || this.status.length >= 500) {
|
2018-03-13 02:52:28 +01:00
|
|
|
return this.$message({
|
|
|
|
message: 'Toot length should be 1 to 500',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
}
|
2018-08-01 17:02:44 +02:00
|
|
|
const visibilityKey = Object.keys(Visibility).find((key) => {
|
|
|
|
return Visibility[key].value === this.visibility
|
|
|
|
})
|
2018-03-14 14:19:17 +01:00
|
|
|
let form = {
|
2018-04-11 16:19:25 +02:00
|
|
|
status: this.status,
|
2018-08-11 04:44:13 +02:00
|
|
|
visibility: Visibility[visibilityKey].key,
|
2018-05-25 01:31:41 +02:00
|
|
|
sensitive: this.sensitive,
|
|
|
|
spoiler_text: this.spoiler
|
2018-03-14 14:19:17 +01:00
|
|
|
}
|
|
|
|
if (this.replyToId !== null) {
|
|
|
|
form = Object.assign(form, {
|
|
|
|
in_reply_to_id: this.replyToId
|
|
|
|
})
|
|
|
|
}
|
2018-03-29 06:16:15 +02:00
|
|
|
if (this.attachedMedias.length > 0) {
|
|
|
|
if (this.attachedMedias.length > 4) {
|
|
|
|
return this.$message({
|
|
|
|
message: 'You can only attach up to 4 images',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
form = Object.assign(form, {
|
|
|
|
media_ids: this.attachedMedias.map((m) => { return m.id })
|
|
|
|
})
|
|
|
|
}
|
2018-04-09 09:49:41 +02:00
|
|
|
|
2018-03-29 04:25:35 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/postToot', form)
|
2018-03-13 00:41:03 +01:00
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not toot',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-08-01 14:32:21 +02:00
|
|
|
this.close()
|
2018-03-29 05:09:28 +02:00
|
|
|
},
|
|
|
|
selectImage () {
|
|
|
|
this.$refs.image.click()
|
|
|
|
},
|
2018-05-27 15:05:29 +02:00
|
|
|
onChangeImage (e) {
|
2018-03-29 06:05:19 +02:00
|
|
|
if (e.target.files.item(0) === null || e.target.files.item(0) === undefined) {
|
|
|
|
return
|
|
|
|
}
|
2018-05-27 15:05:29 +02:00
|
|
|
const file = e.target.files.item(0)
|
2018-06-14 02:05:03 +02:00
|
|
|
if (!file.type.includes('image') && !file.type.includes('video')) {
|
2018-03-29 06:05:19 +02:00
|
|
|
this.$message({
|
2018-06-14 02:05:03 +02:00
|
|
|
message: 'You can only attach images or videos',
|
2018-03-29 06:05:19 +02:00
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2018-05-27 15:05:29 +02:00
|
|
|
this.updateImage(file)
|
|
|
|
},
|
|
|
|
updateImage (file) {
|
2018-07-05 15:15:31 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaId')
|
2018-05-27 15:05:29 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/uploadImage', file)
|
2018-03-29 06:05:19 +02:00
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not attach the file',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-03-29 06:36:47 +02:00
|
|
|
},
|
|
|
|
removeAttachment (media) {
|
2018-03-29 08:49:39 +02:00
|
|
|
this.$store.commit('TimelineSpace/Modals/NewToot/removeMedia', media)
|
|
|
|
},
|
2018-04-11 16:12:51 +02:00
|
|
|
changeVisibility (level) {
|
2018-08-10 17:59:48 +02:00
|
|
|
this.$store.commit('TimelineSpace/Modals/NewToot/changeVisibilityValue', level)
|
2018-05-24 16:38:24 +02:00
|
|
|
},
|
|
|
|
changeSensitive () {
|
|
|
|
this.$store.commit('TimelineSpace/Modals/NewToot/changeSensitive', !this.sensitive)
|
2018-03-13 00:41:03 +01:00
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2018-03-14 09:14:47 +01:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.new-toot-modal /deep/ {
|
2018-03-12 17:42:47 +01:00
|
|
|
.el-dialog__header {
|
|
|
|
background-color: #4a5664;
|
|
|
|
|
|
|
|
.el-dialog__title {
|
|
|
|
color: #ebeef5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-dialog__body {
|
|
|
|
padding: 0;
|
|
|
|
|
2018-05-25 01:31:41 +02:00
|
|
|
.spoiler {
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 4px 0;
|
|
|
|
background-color: #4a5664;
|
|
|
|
|
|
|
|
input {
|
|
|
|
border-radius: 0;
|
2018-07-02 15:51:40 +02:00
|
|
|
font-family: 'Lato', sans-serif;
|
2018-05-28 14:13:30 +02:00
|
|
|
|
|
|
|
&::placeholder {
|
|
|
|
color: #c0c4cc;
|
|
|
|
}
|
2018-05-25 01:31:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 06:36:47 +02:00
|
|
|
.preview {
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 0 12px;
|
|
|
|
|
|
|
|
.image-wrapper {
|
|
|
|
position: relative;
|
|
|
|
display: inline-block;
|
|
|
|
|
|
|
|
.preview-image {
|
|
|
|
width: 60px;
|
2018-03-29 08:49:39 +02:00
|
|
|
margin-right: 8px;
|
2018-03-29 06:36:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.remove-image {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
2018-03-29 08:49:39 +02:00
|
|
|
padding: 0;
|
2018-03-29 06:36:47 +02:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.el-dialog__footer {
|
|
|
|
background-color: #f2f6fc;
|
2018-03-13 02:52:28 +01:00
|
|
|
|
2018-03-29 05:09:28 +02:00
|
|
|
.upload-image {
|
|
|
|
text-align: left;
|
2018-03-29 08:49:39 +02:00
|
|
|
float: left;
|
2018-03-29 05:09:28 +02:00
|
|
|
|
|
|
|
.image-input {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:45:26 +02:00
|
|
|
.privacy {
|
|
|
|
float: left;
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
2018-05-24 16:38:24 +02:00
|
|
|
.sensitive {
|
|
|
|
float: left;
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
2018-05-25 01:31:41 +02:00
|
|
|
.content-warning {
|
|
|
|
float: left;
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
|
|
span {
|
|
|
|
font-weight: 800;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 02:52:28 +01:00
|
|
|
.text-count {
|
|
|
|
padding-right: 24px;
|
|
|
|
color: #909399;
|
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-11 13:45:26 +02:00
|
|
|
|
|
|
|
.privacy-icon {
|
|
|
|
margin-right: 4px;
|
|
|
|
}
|
2018-03-12 17:42:47 +01:00
|
|
|
</style>
|