123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <template>
- <div class='route_container'>
- <confirm-modal
- v-model='picture.showRemoveProfilePictureModal'
- @confirm='removeProfilePicture'
- color='red'
- text='Yes, remove it'
- >
- Are you sure you want to remove your profile picture?
- </confirm-modal>
- <modal-window v-model='picture.showProfilePictureModal' width='25rem' @input='hideProflePictureModal'>
- <div
- class='profile_picture_modal__overlay'
- :class='{
- "profile_picture_modal__overlay--show": picture.loading
- }'
- >
- <loading-icon></loading-icon>
- </div>
- <div
- class='profile_picture_modal'
- :class='{ "profile_picture_modal--picture.dragging": picture.dragging }'
- @dragover='handleDragOver'
- @drkagend='picture.dragging = false'
- @drkgleave='picture.dragging = false'
- @drop='handleFileDrop'
- >
- <div class='h3'>Add a profile picture</div>
- <p class='p--condensed'>
- Drag and drop an image or
- <label class='button profile_picture_modal__upload_button'>
- <input type='file' accept='image/*' @change='processImage($event.target.files[0])'>
- upload a file
- </label>
- </p>
- <div class='profile_picture_modal__drag_area'>
- <span
- v-if='!picture.dataURL'
- class='fa fa-cloud-upload profile_picture_modal__drag_area__icon'
- :class='{ "profile_picture_modal__drag_area__icon--picture.dragging": picture.dragging }'
- ></span>
- <div
- class='profile_picture_modal__drag_area__image picture_circle'
- :style='{ "background-image": "url(" + picture.dataURL + ")" }'
- v-else
- ></div>
- </div>
- <div class='profile_picture_modal__buttons'>
- <button class='button button--modal button--borderless' @click='hideProflePictureModal'>Cancel</button>
- <button
- class='button button--modal button--green'
- :class='{ "button--disabled": !picture.dataURL }'
- @click='uploadProfilePicture'
- >Upload picture</button>
- </div>
- </div>
- </modal-window>
- <div class='h1'>General settings</div>
- <p>
- <div class='h3'>About me</div>
- <p class='p--condensed'>
- Write something about yourself to be displayed on your user page
- </p>
- <fancy-textarea
- placeholder='About me description'
- v-model='description.value'
- :error='description.error'
- type='password'
- ></fancy-textarea>
- <loading-button
- class='button button--green'
- :loading='description.loading'
- @click='saveDescription'
- >
- Save description
- </loading-button>
- </p>
- <p>
- <div class='h3'>Profile picture</div>
- <p class='p--condensed'>
- This will be displayed by your posts on the site
- </p>
- <p
- class='p--condensed profile_picture_preview picture_circle'
- :style='{ "background-image": "url(" + picture.current + ")" }'
- v-if='picture.current'
- ></p>
- <button class='button' @click='picture.showProfilePictureModal = true'>
- {{picture.current ? "Change" : "Add" }} profile picture
- </button>
- <button
- v-if='picture.current'
- class='button'
- style='margin-left: 0.5rem;'
- @click='picture.showRemoveProfilePictureModal = true'
- >
- Remove
- </button>
- </p>
- </div>
- </template>
- <script>
- import FancyTextarea from '../FancyTextarea'
- import LoadingButton from '../LoadingButton'
- import LoadingIcon from '../LoadingIcon'
- import ModalWindow from '../ModalWindow'
- import ConfirmModal from '../ConfirmModal'
- import AjaxErrorHandler from '../../assets/js/errorHandler'
- import logger from '../../assets/js/logger'
- export default {
- name: 'settingsGeneral',
- components: {
- FancyTextarea,
- LoadingButton,
- LoadingIcon,
- ModalWindow,
- ConfirmModal
- },
- data () {
- return {
- description: {
- value: '',
- loading: false,
- error: ''
- },
- picture: {
- current: null,
- showProfilePictureModal: false,
- showRemoveProfilePictureModal: false,
- dragging: false,
- dataURL: null,
- file: null,
- loading: false
- }
- }
- },
- computed: {},
- methods: {
- saveDescription () {
- this.description.error = ''
- this.description.loading = true
- this.axios
- .put('/api/v1/user/' + this.$store.state.username, {
- description: this.description.value
- })
- .then(res => {
- this.description.loading = false
- })
- .catch(e => {
- this.description.loading = false
- AjaxErrorHandler(this.$store)(e, error => {
- this.description.error = error.message
- })
- })
- },
- uploadProfilePicture () {
- this.picture.loading = true
- let formData = new FormData()
- formData.append('picture', this.picture.file)
- this.axios
- .post('/api/v1/user/' + this.$store.state.username + '/picture', formData, {
- headers: {
- 'Content-Type': 'multipart/form-data'
- }
- })
- .then(res => {
- this.hideProflePictureModal()
- this.picture.current = res.data.picture
- })
- .catch(e => {
- this.picture.loading = false
- AjaxErrorHandler(this.$store)(e)
- })
- },
- removeProfilePicture () {
- this.axios
- .delete('/api/v1/user/' + this.$store.state.username + '/picture')
- .then(res => {
- this.picture.current = null
- })
- .catch(AjaxErrorHandler(this.$store))
- },
- hideProflePictureModal () {
- this.picture.showProfilePictureModal = false
-
- //Wait for transition to complete
- setTimeout(() => {
- this.picture.dataURL = null
- this.picture.loading = false
- }, 200)
- },
- handleDragOver (e) {
- e.preventDefault()
- this.picture.dragging = true
- },
- handleFileDrop (e) {
- e.preventDefault()
- this.picture.dragging = false
-
- if(e.dataTransfer && e.dataTransfer.items) {
- let file = e.dataTransfer.items[0]
- if(file.type.match('^image/')) {
- this.processImage(file.getAsFile())
- }
- }
- },
- processImage (file) {
- let reader = new FileReader()
- reader.readAsDataURL(file)
- this.picture.file = file
- reader.addEventListener('load', () => {
- this.picture.dataURL = reader.result
- })
- }
- },
- created () {
- this.$store.dispatch('setTitle', 'general settings')
- this.$nextTick(() => {
- this.axios
- .get('/api/v1/user/' + this.$store.state.username)
- .then(res => {
- this.description.value = res.data.description || ''
- this.picture.current = res.data.picture
- })
- .catch(e => {
- AjaxErrorHandler(this.$store)(e)
- })
- })
- logger('settingsGeneral')
- }
- }
- </script>
- <style lang='scss' scoped>
- @import '../../assets/scss/variables.scss';
- .profile_picture_preview {
- height: 5rem;
- width: 5rem;
- }
- .profile_picture_modal {
- padding: 1rem;
- transition: all 0.2s;
- @at-root #{&}--picture.dragging {
- //background-color: $color__lightgray--primary;
- }
- @at-root #{&}__overlay {
- @include loading-overlay(rgba(0, 0, 0, 0.5), 0.125rem);
- }
- @at-root #{&}__upload_button input[type="file"] {
- display: none;
- }
- @at-root #{&}__drag_area {
- padding: 1rem;
- text-align: center;
- @at-root #{&}__image {
- width: 5rem;
- height: 5rem;
- display: inline-block;
- margin-top: -1rem;
- }
- @at-root #{&}__icon {
- font-size: 6rem;
- color: $color__gray--darker;
- transition: all 0.2s;
- @at-root #{&}--picture.dragging {
- transform: translateY(-0.5rem) scale(1.1);
- color: $color__gray--darkest;
- }
- }
- }
- }
- @media (max-width: 420px) {
- .h1 {
- display: none;
- }
- }
- </style>
|