2018-03-12 17:42:47 +01:00
< template >
< el -dialog
title = "New Toot"
: 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-05-25 01:31:41 +02:00
< div class = "spoiler" v-if ="showContentWarning" >
< el -input placeholder = "Write your warning here" v-model ="spoiler" > < / el -input >
< / div >
2018-03-14 13:27:26 +01:00
< div class = "status" >
2018-05-25 01:31:41 +02:00
< textarea v-model ="status" ref="status" v-shortkey="{linux: ['ctrl', 'enter'], mac: ['meta', 'enter']}" @shortkey="toot()" autofocus placeholder="What is on your mind?" > < / textarea >
2018-03-13 02:04:07 +01:00
< / div >
2018-03-12 17:42:47 +01:00
< / e l - f o r m >
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 > < / e l - b u t t o n >
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 > < / e l - b u t t o n >
2018-03-29 08:49:39 +02:00
< input name = "image" type = "file" class = "image-input" ref = "image" @change ="updateImage" :key ="attachedImageId" / >
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 > < / e l - b u t t o n >
2018-04-11 13:45:26 +02:00
< el -dropdown -menu slot = "dropdown" >
2018-04-11 16:12:51 +02:00
< el -dropdown -item command = "public" > < icon name = "globe" class = "privacy-icon" > < / icon > Public < / e l - d r o p d o w n - i t e m >
< el -dropdown -item command = "unlisted" > < icon name = "unlock" class = "privacy-icon" > < / icon > Unlisted < / e l - d r o p d o w n - i t e m >
< el -dropdown -item command = "private" > < icon name = "lock" class = "privacy-icon" > < / icon > Private < / e l - d r o p d o w n - i t e m >
< el -dropdown -item command = "direct" > < icon name = "envelope" class = "privacy-icon" scale = "0.8" > < / icon > Direct < / e l - d r o p d o w n - i t e m >
2018-04-11 13:45:26 +02:00
< / e l - d r o p d o w n - m e n u >
< / e l - d r o p d o w n >
< / div >
2018-05-24 17:21:20 +02:00
< div class = "sensitive" v-if ="attachedMedias.length > 0" >
2018-05-24 16:38:24 +02:00
< el -button size = "small" type = "text" @click ="changeSensitive" >
< icon name = "eye-slash" v-if ="sensitive" > < / icon >
< icon name = "eye" v-else > < / icon >
< / e l - b u t t o n >
< / div >
2018-05-25 01:31:41 +02:00
< div class = "content-warning" >
< el -button size = "small" type = "text" @ click = "showContentWarning = !showContentWarning" >
CW
< / e l - b u t t o n >
< / div >
2018-03-14 14:19:17 +01:00
< span class = "text-count" > { { 500 - status . length } } < / span >
2018-03-13 00:41:03 +01:00
< el -button @click ="close" > Cancel < / el -button >
2018-03-29 06:05:19 +02:00
< el -button type = "primary" @click ="toot" v-loading ="blockSubmit" > 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
< / e l - d i a l o g >
< / template >
< script >
2018-03-14 14:19:17 +01:00
import { mapState } from 'vuex'
2018-03-12 17:42:47 +01:00
export default {
2018-03-29 04:25:35 +02:00
name : 'new-toot' ,
2018-03-21 15:37:46 +01:00
data ( ) {
return {
2018-05-25 01:31:41 +02:00
attachedImageId : 0 ,
showContentWarning : false
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-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 ) {
case 'public' :
return 'globe'
case 'unlisted' :
return 'unlock'
case 'private' :
return 'lock'
case 'direct' :
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-03-29 04:25:35 +02:00
this . $store . dispatch ( 'TimelineSpace/Modals/NewToot/changeModal' , value )
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
this . $nextTick ( function ( ) {
this . $refs . status . focus ( )
} )
}
2018-03-13 02:04:07 +01:00
}
} ,
2018-03-13 00:41:03 +01:00
methods : {
close ( ) {
2018-03-29 08:49:39 +02:00
this . resetImage ( )
2018-03-29 04:25:35 +02:00
this . $store . dispatch ( 'TimelineSpace/Modals/NewToot/changeModal' , false )
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-03-14 14:19:17 +01:00
let form = {
2018-04-11 16:19:25 +02:00
status : this . status ,
2018-05-24 16:38:24 +02:00
visibility : this . visibility ,
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
const loading = this . $loading ( {
lock : true ,
text : 'Loading' ,
spinner : 'el-icon-loading' ,
background : 'rgba(0, 0, 0, 0.7)'
} )
2018-03-29 04:25:35 +02:00
this . $store . dispatch ( 'TimelineSpace/Modals/NewToot/postToot' , form )
2018-03-13 00:41:03 +01:00
. then ( ( ) => {
2018-03-26 13:04:29 +02:00
this . close ( )
2018-04-09 09:49:41 +02:00
loading . close ( )
2018-03-13 00:41:03 +01:00
this . $message ( {
message : 'Toot' ,
type : 'success'
} )
} )
. catch ( ( ) => {
2018-04-09 09:49:41 +02:00
loading . close ( )
2018-03-13 00:41:03 +01:00
this . $message ( {
message : 'Could not toot' ,
type : 'error'
} )
} )
2018-03-29 05:09:28 +02:00
} ,
selectImage ( ) {
this . $refs . image . click ( )
} ,
2018-03-29 06:05:19 +02:00
updateImage ( e ) {
2018-03-29 08:49:39 +02:00
this . resetImage ( )
2018-03-29 06:05:19 +02:00
if ( e . target . files . item ( 0 ) === null || e . target . files . item ( 0 ) === undefined ) {
return
}
if ( ! e . target . files . item ( 0 ) . type . includes ( 'image' ) ) {
this . $message ( {
message : 'You can only attach images' ,
type : 'error'
} )
return
}
this . $store . dispatch ( 'TimelineSpace/Modals/NewToot/uploadImage' , e . target . files . item ( 0 ) )
. 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 )
} ,
resetImage ( ) {
++ this . attachedImageId
2018-04-11 16:12:51 +02:00
} ,
changeVisibility ( level ) {
this . $store . commit ( 'TimelineSpace/Modals/NewToot/changeVisibility' , 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 : # 4 a5664 ;
. el - dialog _ _title {
color : # ebeef5 ;
}
}
. el - dialog _ _body {
padding : 0 ;
2018-05-25 01:31:41 +02:00
. spoiler {
box - sizing : border - box ;
padding : 4 px 0 ;
background - color : # 4 a5664 ;
input {
border - radius : 0 ;
}
}
2018-03-14 13:27:26 +01:00
. status {
2018-03-12 17:42:47 +01:00
textarea {
2018-03-13 02:04:07 +01:00
display : block ;
padding : 5 px 15 px ;
line - height : 1.5 ;
box - sizing : border - box ;
width : 100 % ;
font - size : inherit ;
color : # 606266 ;
background - image : none ;
2018-03-12 17:42:47 +01:00
border : 0 ;
2018-03-13 02:04:07 +01:00
border - radius : 4 px ;
2018-03-12 17:42:47 +01:00
resize : none ;
height : 120 px ;
2018-03-13 02:04:07 +01:00
transition : border - color .2 s cubic - bezier ( .645 , .045 , .355 , 1 ) ;
}
textarea : focus {
outline : 0 ;
2018-03-12 17:42:47 +01:00
}
}
2018-03-29 06:36:47 +02:00
. preview {
box - sizing : border - box ;
padding : 0 12 px ;
. image - wrapper {
position : relative ;
display : inline - block ;
. preview - image {
width : 60 px ;
2018-03-29 08:49:39 +02:00
margin - right : 8 px ;
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 : 8 px ;
}
2018-05-24 16:38:24 +02:00
. sensitive {
float : left ;
margin - left : 8 px ;
}
2018-05-25 01:31:41 +02:00
. content - warning {
float : left ;
margin - left : 8 px ;
span {
font - weight : 800 ;
}
}
2018-03-13 02:52:28 +01:00
. text - count {
padding - right : 24 px ;
color : # 909399 ;
}
2018-03-12 17:42:47 +01:00
}
}
2018-04-11 13:45:26 +02:00
. privacy - icon {
margin - right : 4 px ;
}
2018-03-12 17:42:47 +01:00
< / style >