summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/settings/import-export.vue
blob: 5b5b704695fd893259201bd62ef9bae4b23b6873 (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
106
107
108
109
110
111
112
<template>
<div class="_formRoot">
	<FormSection>
		<template #label>{{ $ts._exportOrImport.allNotes }}</template>
		<MkButton :class="$style.button" inline @click="doExport('notes')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.followingList }}</template>
		<MkButton :class="$style.button" inline @click="doExport('following')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		<MkButton :class="$style.button" inline @click="doImport('following', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.userLists }}</template>
		<MkButton :class="$style.button" inline @click="doExport('user-lists')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		<MkButton :class="$style.button" inline @click="doImport('user-lists', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.muteList }}</template>
		<MkButton :class="$style.button" inline @click="doExport('muting')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		<MkButton :class="$style.button" inline @click="doImport('muting', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.blockingList }}</template>
		<MkButton :class="$style.button" inline @click="doExport('blocking')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		<MkButton :class="$style.button" inline @click="doImport('blocking', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
	</FormSection>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import MkButton from '@/components/ui/button.vue';
import FormSection from '@/components/form/section.vue';
import * as os from '@/os';
import { selectFile } from '@/scripts/select-file';
import * as symbols from '@/symbols';

export default defineComponent({
	components: {
		FormSection,
		MkButton,
	},

	emits: ['info'],

	data() {
		return {
			[symbols.PAGE_INFO]: {
				title: this.$ts.importAndExport,
				icon: 'fas fa-boxes',
				bg: 'var(--bg)',
			},
		}
	},

	mounted() {
		this.$emit('info', this[symbols.PAGE_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 === 'muting' ? 'i/export-mute' :
				null, {})
			.then(() => {
				os.alert({
					type: 'info',
					text: this.$ts.exportRequested
				});
			}).catch((e: any) => {
				os.alert({
					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' :
				target === 'muting' ? 'i/import-muting' :
				target === 'blocking' ? 'i/import-blocking' :
				null, {
					fileId: file.id
			}).then(() => {
				os.alert({
					type: 'info',
					text: this.$ts.importRequested
				});
			}).catch((e: any) => {
				os.alert({
					type: 'error',
					text: e.message
				});
			});
		},
	}
});
</script>

<style module>
.button {
	margin-right: 16px;
}
</style>