list maximum

This commit is contained in:
samunohito 2024-02-03 16:02:35 +09:00
parent f9e866e733
commit 9bb1e79c83

View file

@ -88,7 +88,7 @@
<script setup lang="ts"> <script setup lang="ts">
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */
import { onMounted, reactive, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { misskeyApi } from '@/scripts/misskey-api.js'; import { misskeyApi } from '@/scripts/misskey-api.js';
import { fromDriveFile, GridItem } from '@/pages/admin/custom-emojis-grid.impl.js'; import { fromDriveFile, GridItem } from '@/pages/admin/custom-emojis-grid.impl.js';
import MkGrid from '@/components/grid/MkGrid.vue'; import MkGrid from '@/components/grid/MkGrid.vue';
@ -111,12 +111,12 @@ import {
GridKeyDownEvent, GridKeyDownEvent,
GridRowContextMenuEvent, GridRowContextMenuEvent,
} from '@/components/grid/grid-event.js'; } from '@/components/grid/grid-event.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { CellValue } from '@/components/grid/cell.js';
import { ColumnSetting } from '@/components/grid/column.js'; import { ColumnSetting } from '@/components/grid/column.js';
import { DroppedFile, readDataTransferItems, flattenDroppedFiles, extractDroppedItems } from '@/scripts/file-drop.js'; import { extractDroppedItems, flattenDroppedFiles } from '@/scripts/file-drop.js';
import { optInGridUtils } from '@/components/grid/optin-utils.js'; import { optInGridUtils } from '@/components/grid/optin-utils.js';
const MAXIMUM_EMOJI_COUNT = 100;
type FolderItem = { type FolderItem = {
id?: string; id?: string;
name: string; name: string;
@ -237,20 +237,30 @@ async function onClearClicked() {
async function onDrop(ev: DragEvent) { async function onDrop(ev: DragEvent) {
const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it)); const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it));
if (droppedFiles.length + gridItems.value.length >= MAXIMUM_EMOJI_COUNT) {
await os.alert({
type: 'warning',
title: '確認',
text: `一度に登録できる絵文字の数は${MAXIMUM_EMOJI_COUNT}件までです。この数を超過した分はリストアップされずに切り捨てられます。`,
});
}
const uploadedItems = await Promise.all( const uploadedItems = await Promise.all(
droppedFiles.map(async (it) => ({ droppedFiles.map(async (it) => ({
droppedFile: it, droppedFile: it,
driveFile: await uploadFile( driveFile: await os.promiseDialog(
it.file, uploadFile(
selectedFolderId.value, it.file,
it.file.name.replace(/\.[^.]+$/, ''), selectedFolderId.value,
keepOriginalUploading.value, it.file.name.replace(/\.[^.]+$/, ''),
keepOriginalUploading.value,
),
), ),
}), }),
), ),
); );
for (const { droppedFile, driveFile } of uploadedItems) { const items = uploadedItems.map(({ droppedFile, driveFile }) => {
const item = fromDriveFile(driveFile); const item = fromDriveFile(driveFile);
if (directoryToCategory.value) { if (directoryToCategory.value) {
item.category = droppedFile.path item.category = droppedFile.path
@ -258,26 +268,31 @@ async function onDrop(ev: DragEvent) {
.replace(/\/[^/]+$/, '') .replace(/\/[^/]+$/, '')
.replace(droppedFile.file.name, ''); .replace(droppedFile.file.name, '');
} }
gridItems.value.push(reactive(item)); return item;
} });
await pushToGridItems(items);
} }
async function onFileSelectClicked(ev: MouseEvent) { async function onFileSelectClicked(ev: MouseEvent) {
const driveFiles = await chooseFileFromPc( const driveFiles = await os.promiseDialog(
true, chooseFileFromPc(
{ true,
uploadFolder: selectedFolderId.value, {
keepOriginal: keepOriginalUploading.value, uploadFolder: selectedFolderId.value,
// keepOriginal: keepOriginalUploading.value,
nameConverter: (file) => file.name.replace(/\.[a-zA-Z0-9]+$/, ''), //
}, nameConverter: (file) => file.name.replace(/\.[a-zA-Z0-9]+$/, ''),
},
),
); );
gridItems.value.push(...driveFiles.map(fromDriveFile));
await pushToGridItems(driveFiles.map(fromDriveFile));
} }
async function onDriveSelectClicked(ev: MouseEvent) { async function onDriveSelectClicked(ev: MouseEvent) {
const driveFiles = await chooseFileFromDrive(true); const driveFiles = await os.promiseDialog(chooseFileFromDrive(true));
gridItems.value.push(...driveFiles.map(fromDriveFile)); await pushToGridItems(driveFiles.map(fromDriveFile));
} }
function onGridEvent(event: GridEvent, currentState: GridCurrentState) { function onGridEvent(event: GridEvent, currentState: GridCurrentState) {
@ -346,6 +361,20 @@ function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState)
optInGridUtils.commonKeyDownHandler(gridItems, event, currentState); optInGridUtils.commonKeyDownHandler(gridItems, event, currentState);
} }
async function pushToGridItems(items: GridItem[]) {
for (const item of items) {
if (gridItems.value.length < 100) {
gridItems.value.push(item);
} else {
await os.alert({
type: 'error',
text: `一度に登録できる絵文字は${MAXIMUM_EMOJI_COUNT}件までです。`,
});
break;
}
}
}
async function refreshUploadFolders() { async function refreshUploadFolders() {
const result = await misskeyApi('drive/folders', {}); const result = await misskeyApi('drive/folders', {});
uploadFolders.value = Array.of<FolderItem>({ name: '-' }, ...result); uploadFolders.value = Array.of<FolderItem>({ name: '-' }, ...result);