summaryrefslogtreecommitdiff
path: root/src/client/pages/settings/import-export.vue
blob: 2e384bb7649e4874dbfbaf98b56e465db1474c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
<FormBase>
	<FormGroup>
		<template #label>{{ $ts._exportOrImport.allNotes }}</template>
		<FormButton @click="doExport('notes')"><Fa :icon="faDownload"/> {{ $ts.export }}</FormButton>
	</FormGroup>
	<FormGroup>
		<template #label>{{ $ts._exportOrImport.followingList }}</template>
		<FormButton @click="doExport('following')"><Fa :icon="faDownload"/> {{ $ts.export }}</FormButton>
		<FormButton @click="doImport('following', $event)"><Fa :icon="faUpload"/> {{ $ts.import }}</FormButton>
	</FormGroup>
	<FormGroup>
		<template #label>{{ $ts._exportOrImport.userLists }}</template>
		<FormButton @click="doExport('user-lists')"><Fa :icon="faDownload"/> {{ $ts.export }}</FormButton>
		<FormButton @click="doImport('user-lists', $event)"><Fa :icon="faUpload"/> {{ $ts.import }}</FormButton>
	</FormGroup>
	<FormGroup>
		<template #label>{{ $ts._exportOrImport.muteList }}</template>
		<FormButton @click="doExport('mute')"><Fa :icon="faDownload"/> {{ $ts.export }}</FormButton>
	</FormGroup>
	<FormGroup>
		<template #label>{{ $ts._exportOrImport.blockingList }}</template>
		<FormButton @click="doExport('blocking')"><Fa :icon="faDownload"/> {{ $ts.export }}</FormButton>
	</FormGroup>
</FormBase>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { faDownload, faUpload, faBoxes } from '@fortawesome/free-solid-svg-icons';
import FormSelect from '@/components/form/select.vue';
import FormButton from '@/components/form/button.vue';
import FormBase from '@/components/form/base.vue';
import FormGroup from '@/components/form/group.vue';
import * as os from '@/os';
import { selectFile } from '@/scripts/select-file';

export default defineComponent({
	components: {
		FormBase,
		FormGroup,
		FormButton,
	},

	emits: ['info'],

	data() {
		return {
			INFO: {
				title: this.$ts.importAndExport,
				icon: faBoxes
			},
			faDownload, faUpload, faBoxes
		}
	},

	mounted() {
		this.$emit('info', this.INFO);
	},

	methods: {
		doExport(target) {
			os.api(
				target == 'notes' ? 'i/export-notes' :
				target == 'following' ? 'i/export-following' :
				target == 'blocking' ? 'i/export-blocking' :
				target == 'user-lists' ? 'i/export-user-lists' :
				target == 'mute' ? 'i/export-mute' :
				null, {})
			.then(() => {
				os.dialog({
					type: 'info',
					text: this.$ts.exportRequested
				});
			}).catch((e: any) => {
				os.dialog({
					type: 'error',
					text: e.message
				});
			});
		},

		async doImport(target, e) {
			const file = await selectFile(e.currentTarget || e.target);
			
			os.api(
				target == 'following' ? 'i/import-following' :
				target == 'user-lists' ? 'i/import-user-lists' :
				null, {
					fileId: file.id
			}).then(() => {
				os.dialog({
					type: 'info',
					text: this.$ts.importRequested
				});
			}).catch((e: any) => {
				os.dialog({
					type: 'error',
					text: e.message
				});
			});
		},
	}
});
</script>