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

161 lines
4.8 KiB
JavaScript
Raw Normal View History

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'
2025-08-04 13:48:09 +03:00
import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue'
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 {
2025-08-04 13:48:09 +03:00
locked: this.$store.state.users.currentUser.locked,
2020-05-03 17:36:12 +03:00
backgroundUploading: false,
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,
2025-08-04 13:48:09 +03:00
ProfileSettingIndicator,
2023-12-27 22:30:19 -05:00
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
},
2020-05-03 17:36:12 +03:00
},
methods: {
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 })
},
2025-08-04 13:48:09 +03:00
updateProfile () {
const params = {
locked: this.locked
}
this.$store.state.api.backendInteractor
.updateProfile({ params })
.then((user) => {
this.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user)
})
.catch((error) => {
this.displayUploadError(error)
})
},
propsToNative (props) {
return propsToNative(props)
2020-05-03 17:36:12 +03:00
}
2025-08-04 13:48:09 +03:00
},
watch: {
locked () {
this.updateProfile()
}
2020-05-03 17:36:12 +03:00
}
}
export default ProfileTab