pinafore/routes/_components/status/StatusToolbar.html

188 lines
6.0 KiB
HTML
Raw Normal View History

<div class="status-toolbar {isStatusInOwnThread ? 'status-in-own-thread' : ''}" ref:node>
2018-01-28 21:51:48 +01:00
<IconButton
className="status-toolbar-reply-button"
label={replyLabel}
2018-03-30 10:06:17 +02:00
pressable="true"
pressed={replyShown}
2018-06-14 17:42:55 +02:00
href={replyIcon}
delegateKey={replyKey}
focusKey={replyKey}
2018-01-28 21:51:48 +01:00
/>
<IconButton
label={reblogLabel}
pressable={!reblogDisabled}
pressed={reblogged}
disabled={reblogDisabled}
href={reblogIcon}
delegateKey={reblogKey}
2018-04-21 17:32:40 +02:00
ref:reblogIcon
2018-01-28 21:51:48 +01:00
/>
<IconButton
label="Favorite"
pressable="true"
pressed={favorited}
2018-01-28 21:51:48 +01:00
href="#fa-star"
delegateKey={favoriteKey}
2018-04-21 17:32:40 +02:00
ref:favoriteIcon
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"
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 {
2018-05-14 03:53:37 +02:00
margin-left: 63px; /* offset to align all toolbar items: 48px avatar + 15px margin-right */
}
2018-05-14 03:53:37 +02:00
@media (max-width: 767px) {
.status-toolbar.status-in-own-thread {
margin-left: 53px; /* offset to align all toolbar items: 48px avatar + 5px margin-right */
}
}
</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'
import { registerClickDelegates } 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'
import { importShowStatusOptionsDialog } from '../dialog/asyncDialogs'
2018-03-12 03:40:32 +01:00
import { updateProfileAndRelationship } from '../../_actions/accounts'
2018-03-21 17:38:20 +01:00
import { FAVORITE_ANIMATION, REBLOG_ANIMATION } from '../../_static/animations'
import { on } from '../../_utils/eventBus'
2018-01-28 21:51:48 +01:00
export default {
2018-04-20 06:38:01 +02:00
oncreate () {
let {
favoriteKey,
reblogKey,
replyKey,
optionsKey
} = this.get()
registerClickDelegates(this, {
[favoriteKey]: (e) => this.onFavoriteClick(e),
[reblogKey]: (e) => this.onReblogClick(e),
[replyKey]: (e) => this.onReplyClick(e),
[optionsKey]: (e) => this.onOptionsClick(e)
})
on('postedStatus', this, this.onPostedStatus)
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: {
2018-04-20 06:38:01 +02:00
onFavoriteClick (e) {
2018-03-30 10:06:17 +02:00
e.preventDefault()
e.stopPropagation()
let { originalStatusId, favorited } = this.get()
2018-04-21 17:32:40 +02:00
let newFavoritedValue = !favorited
/* no await */ setFavorited(originalStatusId, newFavoritedValue)
if (newFavoritedValue) {
this.refs.favoriteIcon.animate(FAVORITE_ANIMATION)
}
2018-02-25 03:20:33 +01:00
},
2018-04-20 06:38:01 +02:00
onReblogClick (e) {
2018-03-30 10:06:17 +02:00
e.preventDefault()
e.stopPropagation()
let { originalStatusId, reblogged } = this.get()
2018-04-21 17:32:40 +02:00
let newRebloggedValue = !reblogged
/* no await */ setReblogged(originalStatusId, newRebloggedValue)
if (newRebloggedValue) {
this.refs.reblogIcon.animate(REBLOG_ANIMATION)
}
2018-03-08 03:04:20 +01:00
},
2018-04-20 06:38:01 +02:00
onReplyClick (e) {
2018-03-30 10:06:17 +02:00
e.preventDefault()
e.stopPropagation()
requestAnimationFrame(() => {
let { uuid } = this.get()
let { repliesShown } = this.store.get()
repliesShown[uuid] = !repliesShown[uuid]
this.store.set({repliesShown})
2018-03-30 10:06:17 +02:00
this.fire('recalculateHeight')
})
2018-03-12 03:40:32 +01:00
},
2018-04-20 06:38:01 +02:00
async onOptionsClick (e) {
2018-03-30 10:06:17 +02:00
e.preventDefault()
e.stopPropagation()
let { originalStatus, originalAccountId } = this.get()
let updateRelationshipPromise = updateProfileAndRelationship(originalAccountId)
let showStatusOptionsDialog = await importShowStatusOptionsDialog()
2018-03-12 03:40:32 +01:00
await updateRelationshipPromise
showStatusOptionsDialog(originalStatus)
},
2018-04-20 06:38:01 +02:00
onPostedStatus (realm, inReplyToUuid) {
let {
originalStatusId,
uuid
} = this.get()
if (realm !== originalStatusId ||
inReplyToUuid !== uuid) {
return
}
try {
// return status to the reply button after posting a reply
this.refs.node.querySelector('.status-toolbar-reply-button').focus()
} catch (e) { /* ignore */ }
2018-02-24 23:49:28 +01:00
}
},
2018-03-21 17:38:20 +01:00
data: () => ({
favoriteAnimation: FAVORITE_ANIMATION,
reblogAnimation: REBLOG_ANIMATION
}),
2018-02-19 19:34:36 +01:00
computed: {
2018-06-14 17:42:55 +02:00
replyLabel: ({ replyShown, inReplyToId }) => (
replyShown ? 'Close reply' : inReplyToId ? 'Reply to thread' : 'Reply'
),
replyIcon: ({ inReplyToId }) => inReplyToId ? '#fa-reply-all' : '#fa-reply',
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'
}
},
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'
}
},
reblogDisabled: ({ visibility }) => {
2018-02-19 19:34:36 +01:00
return visibility === 'private' || visibility === 'direct'
2018-02-24 03:23:36 +01:00
},
reblogged: ({ originalStatusId, $currentStatusModifications, originalStatus }) => {
if ($currentStatusModifications && originalStatusId in $currentStatusModifications.reblogs) {
return $currentStatusModifications.reblogs[originalStatusId]
2018-02-25 03:20:33 +01:00
}
return originalStatus.reblogged
2018-02-25 03:20:33 +01:00
},
favorited: ({ originalStatusId, $currentStatusModifications, originalStatus }) => {
if ($currentStatusModifications && originalStatusId in $currentStatusModifications.favorites) {
return $currentStatusModifications.favorites[originalStatusId]
2018-02-24 03:23:36 +01:00
}
return originalStatus.favourited
2018-02-24 23:49:28 +01:00
},
favoriteKey: ({ uuid }) => `fav-${uuid}`,
reblogKey: ({ uuid }) => `reblog-${uuid}`,
replyKey: ({ uuid }) => `reply-${uuid}`,
optionsKey: ({ uuid }) => `options-${uuid}`
2018-01-28 21:51:48 +01:00
}
}
</script>