Whalebird-desktop-client-ma.../src/renderer/components/TimelineSpace/Cards/Toot.vue

180 lines
4.0 KiB
Vue
Raw Normal View History

<template>
<div class="toot">
<div class="icon">
<img :src="message.account.avatar" />
</div>
<div class="detail">
<div class="toot-header">
2018-03-12 11:36:13 +01:00
<div class="user">
{{ message.account.display_name }}
</div>
<div class="timestamp">
2018-03-12 12:04:30 +01:00
{{ parseDatetime(message.created_at) }}
</div>
</div>
<div class="content" v-html="message.content" @click.capture.prevent="tootClick"></div>
<div class="tool-box">
2018-03-14 14:38:42 +01:00
<el-button type="text" @click="openReply(message)">
<icon name="reply" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeReblog(message)" :class="message.reblogged ? 'reblogged' : ''">
2018-03-14 14:38:42 +01:00
<icon name="retweet" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeFavourite(message)" :class="message.favourited ? 'favourited' : ''">
<icon name="star" scale="0.9"></icon>
</el-button>
</div>
</div>
2018-03-12 11:36:13 +01:00
<div class="clearfix"></div>
<div class="fill-line"></div>
</div>
</template>
<script>
2018-03-12 12:04:30 +01:00
import moment from 'moment'
import { shell } from 'electron'
2018-03-12 12:04:30 +01:00
export default {
name: 'toot',
2018-03-12 12:04:30 +01:00
props: ['message'],
methods: {
parseDatetime (datetime) {
return moment(datetime).format('YYYY-MM-DD HH:mm:ss')
},
tootClick (e) {
const link = findLink(e.target)
if (link !== null) {
shell.openExternal(link)
}
2018-03-14 08:59:39 +01:00
},
openReply (message) {
this.$store.dispatch('TimelineSpace/NewTootModal/openReply', message)
},
2018-03-14 14:38:42 +01:00
changeReblog (message) {
if (message.reblogged) {
this.$store.dispatch('TimelineSpace/Cards/Toot/unreblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to unreblog',
type: 'error'
})
})
} else {
this.$store.dispatch('TimelineSpace/Cards/Toot/reblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to reblog',
type: 'error'
})
})
}
},
2018-03-14 09:35:44 +01:00
changeFavourite (message) {
if (message.favourited) {
this.$store.dispatch('TimelineSpace/Cards/Toot/removeFavourite', message)
.then((data) => {
this.$emit('update', data)
})
2018-03-14 09:35:44 +01:00
.catch(() => {
this.$message({
message: 'Failed to unfavourite',
type: 'error'
})
2018-03-14 08:59:39 +01:00
})
2018-03-14 09:35:44 +01:00
} else {
this.$store.dispatch('TimelineSpace/Cards/Toot/addFavourite', message)
.then((data) => {
this.$emit('update', data)
})
2018-03-14 09:35:44 +01:00
.catch(() => {
this.$message({
message: 'Failed to favourite',
type: 'error'
})
})
}
2018-03-12 12:04:30 +01:00
}
}
}
function findLink (target) {
if (target.localName === 'a') {
return target.href
}
if (target.parentNode === undefined || target.parentNode === null) {
return null
}
return findLink(target.parentNode)
}
</script>
2018-03-12 11:36:13 +01:00
<style lang="scss" scoped>
.fill-line {
height: 1px;
background-color: #f2f6fc;
margin: 4px 0;
}
.toot {
.icon {
float: left;
img {
width: 36px;
height: 36px;
border-radius: 4px;
}
}
.detail {
margin-left: 42px;
margin-right: 8px;
margin-top: 8px;
.toot-header {
.user {
float: left;
font-weight: 800;
color: #303133;
font-size: 14px;
}
.timestamp {
font-size: 14px;
text-align: right;
width: 100%;
color: #909399;
}
}
.content {
font-size: 14px;
color: #303133;
margin: 4px 0 8px;
}
.tool-box {
button {
margin: 0 8px;
padding: 0;
color: #909399;
}
.reblogged {
color: #409eff;
}
.favourited {
color: #e6a23c;
}
2018-03-12 11:36:13 +01:00
}
}
}
</style>