feat: user DataExport script setup #1937

Merged
dpschen merged 1 commits from dpschen/frontend:feature/feat-user-data-export-script-setup into main 2022-05-19 20:44:45 +00:00
1 changed files with 33 additions and 29 deletions

View File

@ -40,37 +40,41 @@
<script lang="ts">
import {defineComponent} from 'vue'
import DataExportService from '@/services/dataExport'
export default defineComponent({
name: 'user-settings-data-export',
Review

Do we even need this?

Do we even need this?
Review

It's used here:

const dataExportService = shallowReactive(new DataExportService())
It's used here: ```ts const dataExportService = shallowReactive(new DataExportService()) ```
Review

Or wait. You meant the name, right?
I kept the definition because else we would need to rename the file to keep the same name in the devtools. Usually that should be in sync.

Or wait. You meant the name, right? I kept the definition because else we would need to rename the file to keep the same name in the devtools. Usually that should be in sync.
Review

Yes, exactly the comment was about the name :)

Your response makes sense!

Yes, exactly the comment was about the name :) Your response makes sense!
data() {
return {
dataExportService: new DataExportService(),
password: '',
errPasswordRequired: false,
}
},
computed: {
isLocalUser() {
return this.$store.state.auth.info?.isLocalUser
},
},
mounted() {
this.setTitle(`${this.$t('user.export.title')} - ${this.$t('user.settings.title')}`)
},
methods: {
async requestDataExport() {
if (this.password === '' && this.isLocalUser) {
this.errPasswordRequired = true
this.$refs.passwordInput.focus()
return
}
await this.dataExportService.request(this.password)
this.$message.success({message: this.$t('user.export.success')})
this.password = ''
},
},
})
</script>
<script setup lang="ts">
import {ref, computed, shallowReactive} from 'vue'
import {useStore} from 'vuex'
import {useI18n} from 'vue-i18n'
import DataExportService from '@/services/dataExport'
import { useTitle } from '@/composables/useTitle'
import {success} from '@/message'
const {t} = useI18n()
const store = useStore()
useTitle(() => `${t('user.export.title')} - ${t('user.settings.title')}`)
const dataExportService = shallowReactive(new DataExportService())
const password = ref('')
const errPasswordRequired = ref(false)
const isLocalUser = computed(() => store.state.auth.info?.isLocalUser)
const passwordInput = ref()
async function requestDataExport() {
if (password.value === '' && isLocalUser.value) {
errPasswordRequired.value = true
passwordInput.value.focus()
return
}
await dataExportService.request(password.value)
success({message: t('user.export.success')})
password.value = ''
}
</script>