pinafore/routes/_components/dialog/components/StatusOptionsDialog.html
2018-04-08 16:56:20 -07:00

76 lines
2.3 KiB
HTML

<ModalDialog
:id
:label
:title
background="var(--main-bg)"
>
<GenericDialogList :items on:click="onClick(event)"/>
</ModalDialog>
<script>
import ModalDialog from './ModalDialog.html'
import { store } from '../../../_store/store'
import GenericDialogList from './GenericDialogList.html'
import { setAccountFollowed } from '../../../_actions/follow'
import { doDeleteStatus } from '../../../_actions/delete'
import { show } from '../helpers/showDialog'
import { close } from '../helpers/closeDialog'
import { oncreate } from '../helpers/onCreateDialog'
export default {
oncreate,
computed: {
relationship: ($currentAccountRelationship) => $currentAccountRelationship,
account: ($currentAccountProfile) => $currentAccountProfile,
verifyCredentials: ($currentVerifyCredentials) => $currentVerifyCredentials,
verifyCredentialsId: (verifyCredentials) => verifyCredentials.id,
following: (relationship) => relationship && relationship.following,
followRequested: (relationship) => relationship && relationship.requested,
accountId: (account) => account && account.id,
followLabel: (following, followRequested, account) => {
if (typeof following === 'undefined' || !account) {
return ''
}
return (following || followRequested)
? `Unfollow @${account.acct}`
: `Follow @${account.acct}`
},
items: (followLabel, following, followRequested, accountId, verifyCredentialsId) => (
[
accountId !== verifyCredentialsId &&
{
key: 'follow',
label: followLabel,
icon: following ? '#fa-user-times' : followRequested ? '#fa-hourglass' : '#fa-user-plus'
},
accountId === verifyCredentialsId &&
{
key: 'delete',
label: 'Delete',
icon: '#fa-trash'
}
].filter(Boolean)
)
},
components: {
ModalDialog,
GenericDialogList
},
store: () => store,
methods: {
show,
close,
async onClick(item) {
if (item.key === 'follow') {
let accountId = this.get('accountId')
let following = this.get('following')
await setAccountFollowed(accountId, !following, true)
this.close()
} else if (item.key === 'delete') {
let statusId = this.get('statusId')
await doDeleteStatus(statusId)
this.close()
}
}
}
}
</script>