refactor(client): refactor import-export to use Composition API (#8579)

This commit is contained in:
Andreas Nedbal 2022-05-01 04:55:15 +02:00 committed by GitHub
parent e0950fe5ea
commit edf8f94fec

View file

@ -37,8 +37,8 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, onMounted, ref } from 'vue'; import { defineExpose, ref } from 'vue';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import FormSection from '@/components/form/section.vue'; import FormSection from '@/components/form/section.vue';
import FormGroup from '@/components/form/group.vue'; import FormGroup from '@/components/form/group.vue';
@ -48,108 +48,80 @@ import { selectFile } from '@/scripts/select-file';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
export default defineComponent({ const excludeMutingUsers = ref(false);
components: { const excludeInactiveUsers = ref(false);
FormSection,
FormGroup,
FormSwitch,
MkButton,
},
emits: ['info'], const onExportSuccess = () => {
os.alert({
type: 'info',
text: i18n.ts.exportRequested,
});
};
setup(props, context) { const onImportSuccess = () => {
const INFO = { os.alert({
title: i18n.ts.importAndExport, type: 'info',
icon: 'fas fa-boxes', text: i18n.ts.importRequested,
bg: 'var(--bg)', });
}; };
const excludeMutingUsers = ref(false); const onError = (ev) => {
const excludeInactiveUsers = ref(false); os.alert({
type: 'error',
text: ev.message,
});
};
const onExportSuccess = () => { const exportNotes = () => {
os.alert({ os.api('i/export-notes', {}).then(onExportSuccess).catch(onError);
type: 'info', };
text: i18n.ts.exportRequested,
});
};
const onImportSuccess = () => { const exportFollowing = () => {
os.alert({ os.api('i/export-following', {
type: 'info', excludeMuting: excludeMutingUsers.value,
text: i18n.ts.importRequested, excludeInactive: excludeInactiveUsers.value,
}); })
}; .then(onExportSuccess).catch(onError);
};
const onError = (e) => { const exportBlocking = () => {
os.alert({ os.api('i/export-blocking', {}).then(onExportSuccess).catch(onError);
type: 'error', };
text: e.message,
});
};
const exportNotes = () => { const exportUserLists = () => {
os.api('i/export-notes', {}).then(onExportSuccess).catch(onError); os.api('i/export-user-lists', {}).then(onExportSuccess).catch(onError);
}; };
const exportFollowing = () => { const exportMuting = () => {
os.api('i/export-following', { os.api('i/export-mute', {}).then(onExportSuccess).catch(onError);
excludeMuting: excludeMutingUsers.value, };
excludeInactive: excludeInactiveUsers.value,
})
.then(onExportSuccess).catch(onError);
};
const exportBlocking = () => { const importFollowing = async (ev) => {
os.api('i/export-blocking', {}).then(onExportSuccess).catch(onError); const file = await selectFile(ev.currentTarget ?? ev.target);
}; os.api('i/import-following', { fileId: file.id }).then(onImportSuccess).catch(onError);
};
const exportUserLists = () => { const importUserLists = async (ev) => {
os.api('i/export-user-lists', {}).then(onExportSuccess).catch(onError); const file = await selectFile(ev.currentTarget ?? ev.target);
}; os.api('i/import-user-lists', { fileId: file.id }).then(onImportSuccess).catch(onError);
};
const exportMuting = () => { const importMuting = async (ev) => {
os.api('i/export-mute', {}).then(onExportSuccess).catch(onError); const file = await selectFile(ev.currentTarget ?? ev.target);
}; os.api('i/import-muting', { fileId: file.id }).then(onImportSuccess).catch(onError);
};
const importFollowing = async (ev) => { const importBlocking = async (ev) => {
const file = await selectFile(ev.currentTarget ?? ev.target); const file = await selectFile(ev.currentTarget ?? ev.target);
os.api('i/import-following', { fileId: file.id }).then(onImportSuccess).catch(onError); os.api('i/import-blocking', { fileId: file.id }).then(onImportSuccess).catch(onError);
}; };
const importUserLists = async (ev) => { defineExpose({
const file = await selectFile(ev.currentTarget ?? ev.target); [symbols.PAGE_INFO]: {
os.api('i/import-user-lists', { fileId: file.id }).then(onImportSuccess).catch(onError); title: i18n.ts.importAndExport,
}; icon: 'fas fa-boxes',
bg: 'var(--bg)',
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);
};
return {
[symbols.PAGE_INFO]: INFO,
excludeMutingUsers,
excludeInactiveUsers,
exportNotes,
exportFollowing,
exportBlocking,
exportUserLists,
exportMuting,
importFollowing,
importUserLists,
importMuting,
importBlocking,
};
},
}); });
</script> </script>