pinafore/routes/_components/dialog/components/AccountProfileOptionsDialog...

131 lines
3.9 KiB
HTML
Raw Normal View History

2018-04-05 06:45:19 +02:00
<ModalDialog
:id
2018-04-05 06:45:19 +02:00
:label
:title
background="var(--main-bg)"
>
<GenericDialogList :items on:click="onClick(event)"/>
</ModalDialog>
<script>
import ModalDialog from './ModalDialog.html'
import { store } from '../../../_store/store'
2018-04-05 06:45:19 +02:00
import GenericDialogList from './GenericDialogList.html'
import { importDialogs } from '../../../_utils/asyncModules'
import { createDialogId } from '../helpers/createDialogId'
import { show } from '../helpers/showDialog'
import { close } from '../helpers/closeDialog'
import { oncreate } from '../helpers/onCreateDialog'
import { setAccountBlocked } from '../../../_actions/block'
2018-04-15 07:18:48 +02:00
import { setAccountMuted } from '../../../_actions/mute'
import { setAccountFollowed } from '../../../_actions/follow'
2018-04-05 06:45:19 +02:00
export default {
oncreate,
store: () => store,
data: () => ({
id: createDialogId()
}),
2018-04-05 06:45:19 +02:00
computed: {
2018-04-15 07:18:48 +02:00
// begin account data copypasta
verifyCredentialsId: (verifyCredentials) => verifyCredentials.id,
following: (relationship) => relationship && relationship.following,
followRequested: (relationship) => relationship && relationship.requested,
accountId: (account) => account && account.id,
acct: (account) => account.acct,
muting: (relationship) => relationship.muting,
blocking: (relationship) => relationship.blocking,
followLabel: (following, followRequested, account, acct) => {
if (typeof following === 'undefined' || !account) {
return ''
}
return (following || followRequested)
? `Unfollow @${acct}`
: `Follow @${acct}`
},
followIcon: (following, followRequested) => {
return following ? '#fa-user-times' : followRequested ? '#fa-hourglass' : '#fa-user-plus'
},
blockLabel: (blocking, acct) => {
return blocking ? `Unblock @${acct}` : `Block @${acct}`
},
blockIcon: (blocking) => blocking ? '#fa-unlock' : '#fa-ban',
muteLabel: (muting, acct) => {
return muting ? `Unmute @${acct}` : `Mute @${acct}`
},
muteIcon: (muting) => muting ? '#fa-volume-up' : '#fa-volume-off',
// end account data copypasta
items: (blockLabel, blocking, blockIcon, muteLabel, muteIcon,
2018-04-20 06:38:01 +02:00
followLabel, followIcon, following, followRequested,
accountId, verifyCredentialsId, acct) => {
2018-04-15 07:18:48 +02:00
let isUser = accountId === verifyCredentialsId
return [
!isUser && {
2018-04-05 06:45:19 +02:00
key: 'mention',
2018-04-15 07:18:48 +02:00
label: `Mention @${acct}`,
2018-04-05 06:45:19 +02:00
icon: '#fa-comments'
},
2018-04-15 07:18:48 +02:00
!isUser && !blocking && {
key: 'follow',
label: followLabel,
icon: followIcon
},
!isUser && {
key: 'block',
2018-04-15 07:18:48 +02:00
label: blockLabel,
icon: blockIcon
},
!isUser && !blocking && {
key: 'mute',
label: muteLabel,
icon: muteIcon
2018-04-05 06:45:19 +02:00
}
2018-04-15 07:18:48 +02:00
].filter(Boolean)
}
2018-04-05 06:45:19 +02:00
},
methods: {
show,
close,
2018-04-20 06:38:01 +02:00
onClick (item) {
switch (item.key) {
case 'mention':
return this.onMentionClicked()
2018-04-15 07:18:48 +02:00
case 'follow':
return this.onFollowClicked()
case 'block':
return this.onBlockClicked()
2018-04-15 07:18:48 +02:00
case 'mute':
return this.onMuteClicked()
}
},
2018-04-20 06:38:01 +02:00
async onMentionClicked () {
let { acct } = this.get()
2018-04-07 09:21:00 +02:00
this.store.setComposeData('dialog', {
2018-04-15 07:18:48 +02:00
text: `@${acct} `
2018-04-05 06:45:19 +02:00
})
2018-04-07 09:21:00 +02:00
let dialogs = await importDialogs()
dialogs.showComposeDialog()
this.close()
},
2018-04-20 06:38:01 +02:00
async onFollowClicked () {
let { accountId, following } = this.get()
2018-04-15 07:18:48 +02:00
this.close()
await setAccountFollowed(accountId, !following, true)
},
2018-04-20 06:38:01 +02:00
async onBlockClicked () {
let { accountId, blocking } = this.get()
this.close()
await setAccountBlocked(accountId, !blocking, true)
2018-04-15 07:18:48 +02:00
},
2018-04-20 06:38:01 +02:00
async onMuteClicked () {
let { accountId, muting } = this.get()
2018-04-15 07:18:48 +02:00
this.close()
await setAccountMuted(accountId, !muting, true)
2018-04-05 06:45:19 +02:00
}
},
components: {
ModalDialog,
GenericDialogList
2018-04-20 06:38:01 +02:00
}
2018-04-05 06:45:19 +02:00
}
</script>