akkoma-fe/src/components/user_reporting_modal/user_reporting_modal.js

115 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2019-03-19 08:53:11 +00:00
import Status from '../status/status.vue'
2019-04-26 19:31:10 +00:00
import List from '../list/list.vue'
2019-04-06 19:35:23 +00:00
import Checkbox from '../checkbox/checkbox.vue'
import Modal from '../modal/modal.vue'
2019-03-19 08:53:11 +00:00
const UserReportingModal = {
components: {
Status,
2019-04-26 19:31:10 +00:00
List,
Checkbox,
Modal
2019-03-19 08:53:11 +00:00
},
data () {
return {
comment: '',
forward: false,
statusIdsToReport: [],
2019-03-20 16:37:13 +00:00
processing: false,
error: false
2019-03-19 08:53:11 +00:00
}
},
computed: {
isLoggedIn () {
return !!this.$store.state.users.currentUser
},
isOpen () {
return this.isLoggedIn && this.$store.state.reports.modalActivated
},
userId () {
return this.$store.state.reports.userId
},
user () {
return this.$store.getters.findUser(this.userId)
},
remoteInstance () {
return !this.user.is_local && this.user.screen_name.substr(this.user.screen_name.indexOf('@') + 1)
},
statuses () {
return this.$store.state.reports.statuses
},
preTickedIds () {
return this.$store.state.reports.preTickedIds
2019-03-19 08:53:11 +00:00
}
},
watch: {
userId: 'resetState',
preTickedIds (newValue) {
this.statusIdsToReport = newValue
}
},
methods: {
resetState () {
// Reset state
this.comment = ''
this.forward = false
this.statusIdsToReport = this.preTickedIds
this.processing = false
2019-03-20 16:37:13 +00:00
this.error = false
},
2019-03-19 08:53:11 +00:00
closeModal () {
this.$store.dispatch('closeUserReportingModal')
},
reportUser () {
this.processing = true
2019-03-20 16:37:13 +00:00
this.error = false
2019-03-20 15:45:19 +00:00
const params = {
userId: this.userId,
2019-03-19 08:53:11 +00:00
comment: this.comment,
forward: this.forward,
2019-03-20 15:45:19 +00:00
statusIds: this.statusIdsToReport
2019-03-19 08:53:11 +00:00
}
this.$store.state.api.backendInteractor.reportUser({ ...params })
.then(() => {
this.processing = false
this.resetState()
this.closeModal()
})
2019-03-20 16:37:13 +00:00
.catch(() => {
this.processing = false
this.error = true
})
},
clearError () {
this.error = false
2019-03-19 08:53:11 +00:00
},
isChecked (statusId) {
return this.statusIdsToReport.indexOf(statusId) !== -1
},
toggleStatus (checked, statusId) {
if (checked === this.isChecked(statusId)) {
return
}
if (checked) {
this.statusIdsToReport.push(statusId)
} else {
this.statusIdsToReport.splice(this.statusIdsToReport.indexOf(statusId), 1)
}
},
resize (e) {
const target = e.target || e
if (!(target instanceof window.Element)) { return }
// Auto is needed to make textbox shrink when removing lines
target.style.height = 'auto'
target.style.height = `${target.scrollHeight}px`
if (target.value === '') {
target.style.height = null
}
}
}
}
export default UserReportingModal