summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/settings/import-export.vue
blob: d48dab9f8d4af9bccd77c3c742c0de708ba76e62 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<div class="_formRoot">
	<FormSection>
		<template #label>{{ $ts._exportOrImport.allNotes }}</template>
		<FormFolder>
			<template #label>{{ $ts.export }}</template>
			<template #icon><i class="fas fa-download"></i></template>
			<MkButton primary :class="$style.button" inline @click="exportNotes()"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		</FormFolder>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.followingList }}</template>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.export }}</template>
			<template #icon><i class="fas fa-download"></i></template>
			<FormSwitch v-model="excludeMutingUsers" class="_formBlock">
				{{ $ts._exportOrImport.excludeMutingUsers }}
			</FormSwitch>
			<FormSwitch v-model="excludeInactiveUsers" class="_formBlock">
				{{ $ts._exportOrImport.excludeInactiveUsers }}
			</FormSwitch>
			<MkButton primary :class="$style.button" inline @click="exportFollowing()"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		</FormFolder>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.import }}</template>
			<template #icon><i class="fas fa-upload"></i></template>
			<MkButton primary :class="$style.button" inline @click="importFollowing($event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
		</FormFolder>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.userLists }}</template>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.export }}</template>
			<template #icon><i class="fas fa-download"></i></template>
			<MkButton primary :class="$style.button" inline @click="exportUserLists()"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		</FormFolder>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.import }}</template>
			<template #icon><i class="fas fa-upload"></i></template>
			<MkButton primary :class="$style.button" inline @click="importUserLists($event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
		</FormFolder>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.muteList }}</template>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.export }}</template>
			<template #icon><i class="fas fa-download"></i></template>
			<MkButton primary :class="$style.button" inline @click="exportMuting()"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		</FormFolder>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.import }}</template>
			<template #icon><i class="fas fa-upload"></i></template>
			<MkButton primary :class="$style.button" inline @click="importMuting($event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
		</FormFolder>
	</FormSection>
	<FormSection>
		<template #label>{{ $ts._exportOrImport.blockingList }}</template>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.export }}</template>
			<template #icon><i class="fas fa-download"></i></template>
			<MkButton primary :class="$style.button" inline @click="exportBlocking()"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
		</FormFolder>
		<FormFolder class="_formBlock">
			<template #label>{{ $ts.import }}</template>
			<template #icon><i class="fas fa-upload"></i></template>
			<MkButton primary :class="$style.button" inline @click="importBlocking($event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
		</FormFolder>
	</FormSection>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import MkButton from '@/components/ui/button.vue';
import FormSection from '@/components/form/section.vue';
import FormFolder from '@/components/form/folder.vue';
import FormSwitch from '@/components/form/switch.vue';
import * as os from '@/os';
import { selectFile } from '@/scripts/select-file';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';

const excludeMutingUsers = ref(false);
const excludeInactiveUsers = ref(false);

const onExportSuccess = () => {
	os.alert({
		type: 'info',
		text: i18n.ts.exportRequested,
	});
};

const onImportSuccess = () => {
	os.alert({
		type: 'info',
		text: i18n.ts.importRequested,
	});
};

const onError = (ev) => {
	os.alert({
		type: 'error',
		text: ev.message,
	});
};

const exportNotes = () => {
	os.api('i/export-notes', {}).then(onExportSuccess).catch(onError);
};

const exportFollowing = () => {
	os.api('i/export-following', {
		excludeMuting: excludeMutingUsers.value,
		excludeInactive: excludeInactiveUsers.value,
	})
	.then(onExportSuccess).catch(onError);
};

const exportBlocking = () => {
	os.api('i/export-blocking', {}).then(onExportSuccess).catch(onError);
};

const exportUserLists = () => {
	os.api('i/export-user-lists', {}).then(onExportSuccess).catch(onError);
};

const exportMuting = () => {
	os.api('i/export-mute', {}).then(onExportSuccess).catch(onError);
};

const importFollowing = async (ev) => {
	const file = await selectFile(ev.currentTarget ?? ev.target);
	os.api('i/import-following', { fileId: file.id }).then(onImportSuccess).catch(onError);
};

const importUserLists = async (ev) => {
	const file = await selectFile(ev.currentTarget ?? ev.target);
	os.api('i/import-user-lists', { fileId: file.id }).then(onImportSuccess).catch(onError);
};

const importMuting = async (ev) => {
	const file = await selectFile(ev.currentTarget ?? ev.target);
	os.api('i/import-muting', { fileId: file.id }).then(onImportSuccess).catch(onError);
};

const importBlocking = async (ev) => {
	const file = await selectFile(ev.currentTarget ?? ev.target);
	os.api('i/import-blocking', { fileId: file.id }).then(onImportSuccess).catch(onError);
};

const headerActions = $computed(() => []);

const headerTabs = $computed(() => []);

definePageMetadata({
	title: i18n.ts.importAndExport,
	icon: 'fas fa-boxes',
});
</script>

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