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

323 lines
8.1 KiB
Vue
Raw Normal View History

<template>
<div class="toot" tabIndex="0" :style="theme">
<div class="icon">
2018-03-29 15:41:28 +02:00
<img :src="originalMessage(message).account.avatar" @click="openUser(originalMessage(message).account)"/>
</div>
<div class="detail" v-on:dblclick="openDetail(message)">
<div class="toot-header">
2018-03-29 15:41:28 +02:00
<div class="user" @click="openUser(originalMessage(message).account)">
{{ username(originalMessage(message).account) }}
</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="attachments">
<div class="media" v-for="media in originalMessage(message).media_attachments">
<img :src="media.preview_url" @click="openImage(media.url)"/>
</div>
2018-04-04 12:56:00 +02:00
<div class="clearfix"></div>
</div>
<div class="reblogger" v-if="message.reblog !== null">
2018-03-14 15:09:04 +01:00
<icon name="retweet"></icon>
<span class="reblogger-icon" @click="openUser(message.account)">
2018-03-14 15:09:04 +01:00
<img :src="message.account.avatar" />
</span>
<span class="reblogger-name" @click="openUser(message.account)">
{{ username(message.account) }}
2018-03-14 15:09:04 +01:00
</span>
</div>
<div class="tool-box">
<el-button type="text" @click="openReply(message)" class="reply">
2018-03-14 14:38:42 +01:00
<icon name="reply" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeReblog(originalMessage(message))" :class="originalMessage(message).reblogged ? 'reblogged' : 'reblog'">
2018-03-14 14:38:42 +01:00
<icon name="retweet" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeFavourite(originalMessage(message))" :class="originalMessage(message).favourited ? 'favourited' : 'favourite'">
2018-03-14 14:38:42 +01:00
<icon name="star" scale="0.9"></icon>
</el-button>
<el-button type="text" v-popover="{ name: message.id }">
2018-04-10 05:32:16 +02:00
<icon name="ellipsis-h" scale="0.9"></icon>
</el-button>
2018-04-13 16:42:00 +02:00
<popover :name="message.id" :width="120" class="action-pop-over">
2018-04-10 06:19:20 +02:00
<ul class="toot-menu">
<li role="button" @click="openDetail(message)">
2018-04-10 06:19:20 +02:00
View Toot Detail
</li>
</ul>
</popover>
</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'
import { mapState } from 'vuex'
2018-03-12 12:04:30 +01:00
export default {
name: 'toot',
2018-03-12 12:04:30 +01:00
props: ['message'],
computed: {
...mapState({
theme: (state) => {
return {
'--theme-primary-color': state.App.theme.primary_color,
'--theme-selected-background-color': state.App.theme.selected_background_color,
'--theme-border-color': state.App.theme.border_color
}
}
})
},
2018-03-12 12:04:30 +01:00
methods: {
originalMessage (message) {
2018-03-14 15:09:04 +01:00
if (message.reblog !== null) {
return message.reblog
2018-03-14 15:09:04 +01:00
} else {
return message
2018-03-14 15:09:04 +01:00
}
},
username (account) {
if (account.display_name !== '') {
return account.display_name
} else {
return account.username
}
},
2018-03-12 12:04:30 +01:00
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/Modals/NewToot/openReply', message)
},
openDetail (message) {
this.$store.dispatch('TimelineSpace/Contents/SideBar/openTootComponent')
this.$store.dispatch('TimelineSpace/Contents/SideBar/TootDetail/changeToot', message)
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true)
},
2018-03-14 14:38:42 +01:00
changeReblog (message) {
if (message.reblogged) {
this.$store.dispatch('TimelineSpace/Contents/Cards/Toot/unreblog', message)
2018-03-14 14:38:42 +01:00
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to unreblog',
type: 'error'
})
})
} else {
this.$store.dispatch('TimelineSpace/Contents/Cards/Toot/reblog', message)
2018-03-14 14:38:42 +01:00
.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/Contents/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/Contents/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'
})
})
}
},
openImage (url) {
this.$store.dispatch('TimelineSpace/Modals/ImageViewer/openModal', url)
2018-03-29 15:41:28 +02:00
},
openUser (account) {
this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent')
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account)
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true)
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
}
if (target.parentNode.getAttribute('class') === 'toot') {
return null
}
return findLink(target.parentNode)
}
</script>
2018-03-12 11:36:13 +01:00
<style lang="scss" scoped>
.toot {
--theme-primary-color: #303133;
--theme-border-color: #ebeef5;
padding: 4px 0 0 16px;
2018-03-12 11:36:13 +01:00
.icon {
float: left;
img {
width: 36px;
height: 36px;
border-radius: 4px;
cursor: pointer;
2018-03-12 11:36:13 +01:00
}
}
.detail {
margin: 0 8px 0 42px;
2018-03-12 11:36:13 +01:00
.toot-header {
.user {
float: left;
font-weight: 800;
color: var(--theme-primary-color);
2018-03-12 11:36:13 +01:00
font-size: 14px;
cursor: pointer;
2018-03-12 11:36:13 +01:00
}
.timestamp {
font-size: 14px;
text-align: right;
width: 100%;
color: #909399;
}
}
.content {
font-size: 14px;
color: var(--theme-primary-color);
2018-03-12 11:36:13 +01:00
margin: 4px 0 8px;
2018-03-24 02:00:35 +01:00
word-wrap: break-word;
2018-03-12 11:36:13 +01:00
}
.attachments {
.media {
2018-04-04 12:56:00 +02:00
float: left;
margin-right: 8px;
img {
cursor: zoom-in;
2018-04-04 02:06:41 +02:00
max-width: 200px;
max-height: 200px;
border-radius: 8px;
}
}
}
2018-03-14 15:09:04 +01:00
.reblogger {
color: #909399;
.reblogger-icon {
img {
width: 16px;
height: 16px;
border-radius: 2px;
cursor: pointer;
2018-03-14 15:09:04 +01:00
}
}
.reblogger-name {
font-size: 12px;
cursor: pointer;
2018-03-14 15:09:04 +01:00
}
}
2018-03-12 11:36:13 +01:00
.tool-box {
button {
margin: 0 8px;
padding: 0;
color: #909399;
}
.reblogged {
color: #409eff;
}
.favourited {
color: #e6a23c;
}
2018-04-10 06:19:20 +02:00
.toot-menu{
padding: 0;
font-size: 0.8em;
margin-left: 0.5em;
list-style-type: none;
text-align: center;
li{
padding-bottom: 0.5em;
border-bottom: 1px solid #ddd;
&:hover{
cursor: pointer;
}
2018-04-10 06:19:20 +02:00
&:last-child{
border: 0;
padding: 0;
}
}
}
2018-03-12 11:36:13 +01:00
}
.reply:hover,
.reblog:hover,
.favourite:hover {
color: #409eff;
}
2018-03-12 11:36:13 +01:00
}
.fill-line {
height: 1px;
background-color: var(--theme-border-color);
margin: 4px 0 0;
}
2018-04-13 16:42:00 +02:00
.action-pop-over {
color: #303133;
}
2018-03-12 11:36:13 +01:00
}
.toot:focus {
--theme-selected-background-color: #f2f6fc;
background-color: var(--theme-selected-background-color);
outline: 0;
}
2018-03-12 11:36:13 +01:00
</style>