feat: Add delete all lists

This commit is contained in:
ThatOneCalculator 2022-12-05 23:10:44 -08:00
parent 6de6e5a393
commit 1743d13f0f
4 changed files with 51 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "calckey",
"version": "12.119.0-calc.19-b4",
"version": "12.119.0-calc.19-b5",
"codename": "aqua",
"repository": {
"type": "git",

View File

@ -306,6 +306,7 @@ import * as ep___users_groups_transfer from './endpoints/users/groups/transfer.j
import * as ep___users_groups_update from './endpoints/users/groups/update.js';
import * as ep___users_lists_create from './endpoints/users/lists/create.js';
import * as ep___users_lists_delete from './endpoints/users/lists/delete.js';
import * as ep___users_lists_delete_all from './endpoints/users/lists/delete-all.js';
import * as ep___users_lists_list from './endpoints/users/lists/list.js';
import * as ep___users_lists_pull from './endpoints/users/lists/pull.js';
import * as ep___users_lists_push from './endpoints/users/lists/push.js';
@ -631,6 +632,7 @@ const eps = [
['users/groups/update', ep___users_groups_update],
['users/lists/create', ep___users_lists_create],
['users/lists/delete', ep___users_lists_delete],
['users/lists/delete-all', ep___users_lists_delete_all],
['users/lists/list', ep___users_lists_list],
['users/lists/pull', ep___users_lists_pull],
['users/lists/push', ep___users_lists_push],

View File

@ -0,0 +1,36 @@
import { UserLists } from '@/models/index.js';
import define from '../../../define.js';
import { ApiError } from '../../../error.js';
export const meta = {
tags: ['lists'],
requireCredential: true,
kind: 'write:account',
description: 'Delete all lists of users.',
errors: {
noSuchList: {
message: 'No such list.',
code: 'NO_SUCH_LIST',
id: '78436795-db79-42f5-b1e2-55ea2cf19166',
},
},
} as const;
export const paramDef = {
type: 'object',
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
while (await UserLists.findOneBy({ userId: user.id }) != null) {
const userList = await UserLists.findOneBy({ userId: user.id });
if (userList == null) {
throw new ApiError(meta.errors.noSuchList);
}
await UserLists.delete(userList.id);
}
});

View File

@ -4,6 +4,7 @@
<MkSpacer :content-max="700">
<div class="qkcjvfiv">
<MkButton primary class="add" @click="create"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.createList }}</MkButton>
<MkButton @click="deleteAll"><i class="ph-trash-bold ph-lg"></i> {{ i18n.ts.deleteAll }}</MkButton>
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="pagination" class="lists _content">
<MkA v-for="list in items" :key="list.id" class="list _panel" :to="`/my/lists/${ list.id }`">
@ -41,6 +42,17 @@ async function create() {
pagingComponent.reload();
}
async function deleteAll() {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('removeAreYouSure', { x: 'all lists' }),
});
if (canceled) return;
await os.api('users/lists/delete-all');
os.success();
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);