misskey-awawa/src/client/app/mobile/views/pages/settings/settings.profile.vue

187 lines
4.5 KiB
Vue
Raw Normal View History

2018-05-19 11:31:13 +00:00
<template>
2018-06-14 07:48:49 +00:00
<ui-card>
<div slot="title">%fa:user% %i18n:@title%</div>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<section class="fit-top">
<ui-form :disabled="saving">
<ui-input v-model="name" :max="30">
<span>%i18n:@name%</span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="username" readonly>
<span>%i18n:@account%</span>
<span slot="prefix">@</span>
<span slot="suffix">@{{ host }}</span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="location">
<span>%i18n:@location%</span>
<span slot="prefix">%fa:map-marker-alt%</span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="birthday" type="date">
<span>%i18n:@birthday%</span>
<span slot="prefix">%fa:birthday-cake%</span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-textarea v-model="description" :max="500">
<span>%i18n:@description%</span>
</ui-textarea>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input type="file" @change="onAvatarChange">
<span>%i18n:@avatar%</span>
<span slot="icon">%fa:image%</span>
<span slot="text" v-if="avatarUploading">%i18n:@uploading%<mk-ellipsis/></span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input type="file" @change="onBannerChange">
<span>%i18n:@banner%</span>
<span slot="icon">%fa:image%</span>
<span slot="text" v-if="bannerUploading">%i18n:@uploading%<mk-ellipsis/></span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-13 09:23:44 +00:00
<ui-button @click="save(true)">%i18n:@save%</ui-button>
2018-09-05 04:47:26 +00:00
</ui-form>
</section>
2018-09-13 09:23:44 +00:00
<section>
<header>%i18n:@advanced%</header>
<div>
<ui-switch v-model="isCat" @change="save(false)">%i18n:@is-cat%</ui-switch>
<ui-switch v-model="alwaysMarkNsfw">%i18n:common.always-mark-nsfw%</ui-switch>
2018-09-13 09:23:44 +00:00
</div>
</section>
<section>
<header>%i18n:@privacy%</header>
<div>
<ui-switch v-model="isLocked" @change="save(false)">%i18n:@is-locked%</ui-switch>
2018-10-13 11:11:00 +00:00
<ui-switch v-model="carefulBot" @change="save(false)">%i18n:@careful-bot%</ui-switch>
2018-09-13 09:23:44 +00:00
</div>
</section>
2018-06-14 07:48:49 +00:00
</ui-card>
2018-05-19 11:31:13 +00:00
</template>
<script lang="ts">
import Vue from 'vue';
2018-05-20 08:37:30 +00:00
import { apiUrl, host } from '../../../../config';
2018-05-19 11:31:13 +00:00
export default Vue.extend({
data() {
return {
2018-05-20 08:37:30 +00:00
host,
2018-05-19 11:31:13 +00:00
name: null,
2018-05-20 08:37:30 +00:00
username: null,
2018-05-19 11:31:13 +00:00
location: null,
description: null,
birthday: null,
2018-05-20 05:01:47 +00:00
avatarId: null,
bannerId: null,
2018-05-21 02:08:08 +00:00
isCat: false,
2018-09-13 09:23:44 +00:00
isLocked: false,
2018-10-13 11:11:00 +00:00
carefulBot: false,
2018-05-20 05:01:47 +00:00
saving: false,
2018-06-14 22:56:56 +00:00
avatarUploading: false,
bannerUploading: false
2018-05-19 11:31:13 +00:00
};
},
2018-05-20 00:04:48 +00:00
computed: {
alwaysMarkNsfw: {
get() { return this.$store.state.i.settings.alwaysMarkNsfw; },
set(value) { (this as any).api('i/update', { alwaysMarkNsfw: value }); }
},
},
2018-05-19 11:31:13 +00:00
created() {
2018-05-27 04:49:09 +00:00
this.name = this.$store.state.i.name || '';
this.username = this.$store.state.i.username;
this.location = this.$store.state.i.profile.location;
this.description = this.$store.state.i.description;
this.birthday = this.$store.state.i.profile.birthday;
this.avatarId = this.$store.state.i.avatarId;
this.bannerId = this.$store.state.i.bannerId;
this.isCat = this.$store.state.i.isCat;
2018-09-13 09:23:44 +00:00
this.isLocked = this.$store.state.i.isLocked;
2018-10-13 11:11:00 +00:00
this.carefulBot = this.$store.state.i.carefulBot;
2018-05-19 11:31:13 +00:00
},
2018-05-20 00:04:48 +00:00
methods: {
2018-05-20 05:01:47 +00:00
onAvatarChange([file]) {
2018-06-14 22:56:56 +00:00
this.avatarUploading = true;
2018-05-20 05:01:47 +00:00
const data = new FormData();
data.append('file', file);
2018-05-27 04:49:09 +00:00
data.append('i', this.$store.state.i.token);
2018-05-20 05:01:47 +00:00
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
2018-08-19 04:32:02 +00:00
.then(response => response.json())
.then(f => {
this.avatarId = f.id;
this.avatarUploading = false;
})
.catch(e => {
this.avatarUploading = false;
alert('%18n:@upload-failed%');
});
2018-05-20 05:01:47 +00:00
},
onBannerChange([file]) {
2018-06-14 22:56:56 +00:00
this.bannerUploading = true;
2018-05-20 05:01:47 +00:00
const data = new FormData();
data.append('file', file);
2018-05-27 04:49:09 +00:00
data.append('i', this.$store.state.i.token);
2018-05-20 05:01:47 +00:00
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
2018-08-19 04:32:02 +00:00
.then(response => response.json())
.then(f => {
this.bannerId = f.id;
this.bannerUploading = false;
})
.catch(e => {
this.bannerUploading = false;
alert('%18n:@upload-failed%');
});
2018-05-20 05:01:47 +00:00
},
2018-09-13 09:23:44 +00:00
save(notify) {
2018-05-19 11:31:13 +00:00
this.saving = true;
(this as any).api('i/update', {
name: this.name || null,
location: this.location || null,
description: this.description || null,
2018-05-20 05:01:47 +00:00
birthday: this.birthday || null,
avatarId: this.avatarId,
2018-05-21 02:08:08 +00:00
bannerId: this.bannerId,
2018-09-13 09:23:44 +00:00
isCat: this.isCat,
2018-10-13 11:11:00 +00:00
isLocked: this.isLocked,
carefulBot: this.carefulBot
2018-05-20 05:01:47 +00:00
}).then(i => {
2018-05-19 11:31:13 +00:00
this.saving = false;
2018-05-27 04:49:09 +00:00
this.$store.state.i.avatarId = i.avatarId;
this.$store.state.i.avatarUrl = i.avatarUrl;
this.$store.state.i.bannerId = i.bannerId;
this.$store.state.i.bannerUrl = i.bannerUrl;
2018-05-20 05:01:47 +00:00
2018-09-13 09:23:44 +00:00
if (notify) {
2018-10-10 12:23:38 +00:00
this.$swal({
type: 'success',
text: '%i18n:@saved%'
});
2018-09-13 09:23:44 +00:00
}
2018-05-19 11:31:13 +00:00
});
}
}
});
</script>