pleroma-fe/src/components/settings_modal/tabs/profile_tab.js

186 lines
6.1 KiB
JavaScript
Raw Normal View History

2020-05-03 17:36:12 +03:00
import unescape from 'lodash/unescape'
2020-06-10 03:24:55 +09:00
import merge from 'lodash/merge'
2025-08-03 21:56:45 +03:00
import UserCard from 'src/components/user_card/user_card.vue'
import ImageCropper from 'src/components/image_cropper/image_cropper.vue'
import ScopeSelector from 'src/components/scope_selector/scope_selector.vue'
import fileSizeFormatService from 'src/components/../services/file_size_format/file_size_format.js'
import ProgressButton from 'src/components/progress_button/progress_button.vue'
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
import suggestor from 'src/components/emoji_input/suggestor.js'
import Checkbox from 'src/components/checkbox/checkbox.vue'
import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue'
2023-12-27 22:30:19 -05:00
import Select from 'src/components/select/select.vue'
import BooleanSetting from '../helpers/boolean_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js'
import localeService from 'src/services/locale/locale.service.js'
import { propsToNative } from 'src/services/attributes_helper/attributes_helper.service.js'
2020-10-20 21:18:23 +03:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faTimes,
2020-10-21 00:01:28 +03:00
faPlus,
faCircleNotch
2020-10-20 21:18:23 +03:00
} from '@fortawesome/free-solid-svg-icons'
2025-02-03 13:02:14 +02:00
import { useInterfaceStore } from 'src/stores/interface'
2020-10-20 21:18:23 +03:00
library.add(
faTimes,
2020-10-21 00:01:28 +03:00
faPlus,
faCircleNotch
2020-10-20 21:18:23 +03:00
)
2020-05-03 17:36:12 +03:00
const ProfileTab = {
data () {
return {
newName: this.$store.state.users.currentUser.name_unescaped,
2020-05-03 17:36:12 +03:00
newBio: unescape(this.$store.state.users.currentUser.description),
newLocked: this.$store.state.users.currentUser.locked,
newBirthday: this.$store.state.users.currentUser.birthday,
showBirthday: this.$store.state.users.currentUser.show_birthday,
2020-06-10 03:24:55 +09:00
newFields: this.$store.state.users.currentUser.fields.map(field => ({ name: field.name, value: field.value })),
2020-05-03 17:36:12 +03:00
showRole: this.$store.state.users.currentUser.show_role,
role: this.$store.state.users.currentUser.role,
2020-06-21 14:59:05 +02:00
bot: this.$store.state.users.currentUser.bot,
2023-12-27 22:30:19 -05:00
actorType: this.$store.state.users.currentUser.actor_type,
2020-05-03 17:36:12 +03:00
bannerUploading: false,
backgroundUploading: false,
banner: null,
bannerPreview: null,
background: null,
backgroundPreview: null,
emailLanguage: this.$store.state.users.currentUser.language || ['']
2020-05-03 17:36:12 +03:00
}
},
components: {
2025-08-03 21:56:45 +03:00
UserCard,
2020-05-03 17:36:12 +03:00
ScopeSelector,
ImageCropper,
EmojiInput,
ProgressButton,
Checkbox,
BooleanSetting,
2023-12-27 22:30:19 -05:00
InterfaceLanguageSwitcher,
Select
2020-05-03 17:36:12 +03:00
},
computed: {
user () {
return this.$store.state.users.currentUser
},
...SharedComputedObject(),
2020-05-03 17:36:12 +03:00
emojiUserSuggestor () {
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
2020-05-03 17:36:12 +03:00
...this.$store.state.instance.customEmoji
],
2020-11-18 18:43:24 +02:00
store: this.$store
2020-05-03 17:36:12 +03:00
})
},
emojiSuggestor () {
2022-07-31 12:35:48 +03:00
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
2022-07-31 12:35:48 +03:00
...this.$store.state.instance.customEmoji
]
})
2020-06-10 03:24:55 +09:00
},
userSuggestor () {
2020-11-18 18:43:24 +02:00
return suggestor({ store: this.$store })
},
bannerImgSrc () {
const src = this.$store.state.users.currentUser.cover_photo
return (!src) ? this.defaultBanner : src
2023-12-27 22:30:19 -05:00
},
2023-12-27 22:36:13 -05:00
groupActorAvailable () {
return this.$store.state.instance.groupActorAvailable
},
2023-12-27 22:30:19 -05:00
availableActorTypes () {
2023-12-27 22:36:13 -05:00
return this.groupActorAvailable ? ['Person', 'Service', 'Group'] : ['Person', 'Service']
2020-05-03 17:36:12 +03:00
}
},
methods: {
updateProfile () {
const params = {
note: this.newBio,
locked: this.newLocked,
2025-02-04 15:23:21 +02:00
// Backend notation.
display_name: this.newName,
fields_attributes: this.newFields.filter(el => el != null),
2023-12-27 22:30:19 -05:00
actor_type: this.actorType,
show_role: this.showRole,
birthday: this.newBirthday || '',
show_birthday: this.showBirthday
}
if (this.emailLanguage) {
params.language = localeService.internalToBackendLocaleMulti(this.emailLanguage)
}
2020-05-03 17:36:12 +03:00
this.$store.state.api.backendInteractor
.updateProfile({ params })
.then((user) => {
2020-06-10 03:24:55 +09:00
this.newFields.splice(user.fields.length)
merge(this.newFields, user.fields)
2020-05-03 17:36:12 +03:00
this.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user)
})
},
changeVis (visibility) {
this.newDefaultScope = visibility
},
uploadFile (slot, e) {
const file = e.target.files[0]
if (!file) { return }
if (file.size > this.$store.state.instance[slot + 'limit']) {
const filesize = fileSizeFormatService.fileSizeFormat(file.size)
const allowedsize = fileSizeFormatService.fileSizeFormat(this.$store.state.instance[slot + 'limit'])
2023-04-05 21:06:37 -06:00
useInterfaceStore().pushGlobalNotice({
2020-12-02 12:46:31 +02:00
messageKey: 'upload.error.message',
messageArgs: [
this.$t('upload.error.file_too_big', {
2020-05-03 17:36:12 +03:00
filesize: filesize.num,
filesizeunit: filesize.unit,
allowedsize: allowedsize.num,
allowedsizeunit: allowedsize.unit
2020-12-02 12:46:31 +02:00
})
],
level: 'error'
})
2020-05-03 17:36:12 +03:00
return
}
2025-02-04 15:23:21 +02:00
2020-05-03 17:36:12 +03:00
const reader = new FileReader()
reader.onload = ({ target }) => {
const img = target.result
this[slot + 'Preview'] = img
this[slot] = file
}
reader.readAsDataURL(file)
},
2025-08-04 11:10:43 +03:00
resetBackground () {
const confirmed = window.confirm(this.$t('settings.reset_background_confirm'))
if (confirmed) {
this.submitBackground('')
}
},
submitBackground (background) {
if (!this.backgroundPreview && background !== '') { return }
this.backgroundUploading = true
this.$store.state.api.backendInteractor.updateProfileImages({ background })
.then((data) => {
this.$store.commit('addNewUsers', [data])
this.$store.commit('setCurrentUser', data)
this.backgroundPreview = null
})
.catch(this.displayUploadError)
.finally(() => { this.backgroundUploading = false })
},
propsToNative (props) {
return propsToNative(props)
2020-05-03 17:36:12 +03:00
}
}
}
export default ProfileTab