pinafore/routes/_components/status/StatusToolbar.html

135 lines
4.4 KiB
HTML
Raw Normal View History

<div class="status-toolbar {{isStatusInOwnThread ? 'status-in-own-thread' : ''}}">
2018-01-28 21:51:48 +01:00
<IconButton
label="Reply"
href="#fa-reply"
2018-03-08 03:04:20 +01:00
disabled="{{disableReply}}"
delegateKey="{{replyKey}}"
2018-01-28 21:51:48 +01:00
/>
<IconButton
2018-02-25 03:20:33 +01:00
label="{{reblogLabel}}"
pressable="{{!reblogDisabled}}"
pressed="{{reblogged}}"
disabled="{{reblogDisabled}}"
href="{{reblogIcon}}"
delegateKey="{{reblogKey}}"
2018-01-28 21:51:48 +01:00
/>
<IconButton
label="Favorite"
pressable="true"
2018-02-24 03:23:36 +01:00
pressed="{{favorited}}"
2018-01-28 21:51:48 +01:00
href="#fa-star"
2018-02-24 23:49:28 +01:00
delegateKey="{{favoriteKey}}"
2018-03-12 03:40:32 +01:00
/>
2018-01-28 21:51:48 +01:00
<IconButton
2018-03-12 03:40:32 +01:00
label="Show more options"
2018-01-28 21:51:48 +01:00
href="#fa-ellipsis-h"
2018-03-12 03:40:32 +01:00
delegateKey="{{optionsKey}}"
2018-01-28 21:51:48 +01:00
/>
</div>
<style>
.status-toolbar {
2018-02-10 05:07:48 +01:00
grid-area: toolbar;
display: flex;
justify-content: space-between;
}
.status-toolbar.status-in-own-thread {
margin-left: 58px;
}
</style>
<script>
2018-01-28 21:51:48 +01:00
import IconButton from '../IconButton.html'
2018-02-24 03:23:36 +01:00
import { store } from '../../_store/store'
2018-02-25 01:12:25 +01:00
import { registerClickDelegate, unregisterClickDelegate } from '../../_utils/delegate'
2018-02-24 23:49:28 +01:00
import { setFavorited } from '../../_actions/favorite'
2018-02-25 03:20:33 +01:00
import { setReblogged } from '../../_actions/reblog'
2018-03-08 03:04:20 +01:00
import { goto } from 'sapper/runtime.js'
2018-03-12 03:40:32 +01:00
import { importDialogs } from '../../_utils/asyncModules'
import { updateProfileAndRelationship } from '../../_actions/accounts'
2018-01-28 21:51:48 +01:00
export default {
2018-02-24 23:49:28 +01:00
oncreate() {
2018-03-05 02:16:33 +01:00
registerClickDelegate(this.get('favoriteKey'), () => this.onFavoriteClick())
registerClickDelegate(this.get('reblogKey'), () => this.onReblogClick())
2018-03-08 03:04:20 +01:00
registerClickDelegate(this.get('replyKey'), () => this.onReplyClick())
2018-03-12 03:40:32 +01:00
registerClickDelegate(this.get('optionsKey'), () => this.onOptionsClick())
2018-02-24 23:49:28 +01:00
},
ondestroy() {
2018-02-25 03:20:33 +01:00
unregisterClickDelegate(this.get('favoriteKey'))
unregisterClickDelegate(this.get('reblogKey'))
2018-03-08 03:04:20 +01:00
unregisterClickDelegate(this.get('replyKey'))
2018-03-12 03:40:32 +01:00
unregisterClickDelegate(this.get('optionsKey'))
2018-02-24 23:49:28 +01:00
},
2018-01-28 21:51:48 +01:00
components: {
IconButton
2018-02-19 19:34:36 +01:00
},
2018-02-24 03:23:36 +01:00
store: () => store,
2018-02-24 23:49:28 +01:00
methods: {
onFavoriteClick() {
let statusId = this.get('statusId')
let favorited = this.get('favorited')
/* no await */ setFavorited(statusId, !favorited)
2018-02-25 03:20:33 +01:00
},
onReblogClick() {
let statusId = this.get('statusId')
let reblogged = this.get('reblogged')
/* no await */ setReblogged(statusId, !reblogged)
2018-03-08 03:04:20 +01:00
},
onReplyClick() {
let statusId = this.get('statusId')
goto(`/statuses/${statusId}/reply`)
2018-03-12 03:40:32 +01:00
},
async onOptionsClick() {
let statusId = this.get('statusId')
let accountId = this.get('accountId')
let updateRelationshipPromise = updateProfileAndRelationship(accountId)
let dialogs = await importDialogs()
await updateRelationshipPromise
dialogs.showStatusOptionsDialog(statusId)
2018-02-24 23:49:28 +01:00
}
},
2018-02-19 19:34:36 +01:00
computed: {
visibility: (status) => status.visibility,
2018-02-25 03:20:33 +01:00
reblogLabel: (visibility) => {
2018-02-19 19:34:36 +01:00
switch (visibility) {
case 'private':
return 'Cannot be boosted because this is followers-only'
case 'direct':
return 'Cannot be boosted because this is a direct message'
default:
return 'Boost'
}
},
2018-02-25 03:20:33 +01:00
reblogIcon: (visibility) => {
2018-02-19 19:34:36 +01:00
switch (visibility) {
case 'private':
return '#fa-lock'
case 'direct':
return '#fa-envelope'
default:
return '#fa-retweet'
}
},
2018-02-25 03:20:33 +01:00
reblogDisabled: (visibility) => {
2018-02-19 19:34:36 +01:00
return visibility === 'private' || visibility === 'direct'
2018-02-24 03:23:36 +01:00
},
2018-02-25 03:20:33 +01:00
reblogged: (status, $currentStatusModifications) => {
if ($currentStatusModifications && status.id in $currentStatusModifications.reblogs) {
return $currentStatusModifications.reblogs[status.id]
}
return status.reblogged
},
2018-02-24 03:23:36 +01:00
favorited: (status, $currentStatusModifications) => {
if ($currentStatusModifications && status.id in $currentStatusModifications.favorites) {
return $currentStatusModifications.favorites[status.id]
}
return status.favourited
2018-02-24 23:49:28 +01:00
},
statusId: (status) => status.id,
2018-03-12 03:40:32 +01:00
accountId: (status) => status.account.id,
2018-03-15 16:59:30 +01:00
favoriteKey: (statusId) => `fav-${statusId}`,
reblogKey: (statusId) => `reblog-${statusId}`,
replyKey: (statusId) => `reply-${statusId}`,
optionsKey: (statusId) => `options-${statusId}`,
2018-01-28 21:51:48 +01:00
}
}
</script>