This commit is contained in:
mattyatea 2024-01-03 01:52:25 +09:00
parent 09b1bac3ad
commit 1e8889ecfb
1 changed files with 40 additions and 2 deletions

View File

@ -7,13 +7,16 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template> <template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :contentMax="900"> <MkSpacer :contentMax="900">
<MkSwitch v-model="select">SelectMode</MkSwitch>
<MkButton @click="setCategoryBulk">Set Category</MkButton>
<div class="_gaps"> <div class="_gaps">
<div :class="$style.decorations"> <div :class="$style.decorations">
<XDecoration <XDecoration
v-for="avatarDecoration in avatarDecorations" v-for="avatarDecoration in avatarDecorations"
:key="avatarDecoration.id" :key="avatarDecoration.id"
:class=" selectItemsId.includes(avatarDecoration.id) ? $style.selected : '' "
:decoration="avatarDecoration" :decoration="avatarDecoration"
@click="openDecorationEdit(avatarDecoration)" @click="select ? selectItems(avatarDecoration.id) : openDecorationEdit(avatarDecoration)"
/> />
</div> </div>
</div> </div>
@ -22,14 +25,18 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, defineAsyncComponent } from 'vue'; import { ref, computed, defineAsyncComponent, watch } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js'; import { definePageMetadata } from '@/scripts/page-metadata.js';
import XDecoration from '@/pages/settings/avatar-decoration.decoration.vue'; import XDecoration from '@/pages/settings/avatar-decoration.decoration.vue';
import MkButton from '@/components/MkButton.vue';
import MkSwitch from '@/components/MkSwitch.vue';
const avatarDecorations = ref<Misskey.entities.AdminAvatarDecorationsListResponse>([]); const avatarDecorations = ref<Misskey.entities.AdminAvatarDecorationsListResponse>([]);
const select = ref(false);
const selectItemsId = ref<string[]>([]);
function add() { function add() {
avatarDecorations.value.unshift({ avatarDecorations.value.unshift({
@ -42,6 +49,15 @@ function add() {
}); });
} }
function selectItems(decorationId) {
if (selectItemsId.value.includes(decorationId)) {
const index = selectItemsId.value.indexOf(decorationId);
selectItemsId.value.splice(index, 1);
} else {
selectItemsId.value.push(decorationId);
}
}
function openDecorationEdit(avatarDecoration) { function openDecorationEdit(avatarDecoration) {
os.popup(defineAsyncComponent(() => import('@/components/MkAvatarDecoEditDialog.vue')), { os.popup(defineAsyncComponent(() => import('@/components/MkAvatarDecoEditDialog.vue')), {
avatarDecoration: avatarDecoration, avatarDecoration: avatarDecoration,
@ -68,6 +84,25 @@ function load() {
} }
load(); load();
watch(select, () => {
selectItemsId.value = [];
});
async function setCategoryBulk() {
const { canceled, result } = await os.inputText({
title: 'Category',
});
if (canceled) return;
if (selectItemsId.value.length > 1) {
for (let i = 0; i < selectItemsId.value.length; i++) {
let decorationId = selectItemsId.value[i];
await os.api('admin/avatar-decorations/update', {
id: decorationId,
category: result,
});
}
}
}
const headerActions = computed(() => [{ const headerActions = computed(() => [{
asFullButton: true, asFullButton: true,
@ -89,4 +124,7 @@ definePageMetadata({
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
grid-gap: 12px; grid-gap: 12px;
} }
.selected{
border: 0.1px solid var(--accent);
}
</style> </style>