mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
fix drag preview image url generation
This commit is contained in:
+8
-10
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
|
|
||||||
import styles from './drag-preview.module.css';
|
import styles from './drag-preview.module.css';
|
||||||
|
|
||||||
|
import { useItemImageUrl } from '/@/renderer/components/item-image/item-image';
|
||||||
import { Icon } from '/@/shared/components/icon/icon';
|
import { Icon } from '/@/shared/components/icon/icon';
|
||||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||||
import { DragData } from '/@/shared/types/drag-and-drop';
|
import { DragData } from '/@/shared/types/drag-and-drop';
|
||||||
@@ -23,22 +24,19 @@ const getItemName = (item: unknown): string => {
|
|||||||
return 'Item';
|
return 'Item';
|
||||||
};
|
};
|
||||||
|
|
||||||
const getItemImage = (item: unknown): null | string => {
|
|
||||||
if (item && typeof item === 'object') {
|
|
||||||
if ('imageUrl' in item && typeof item.imageUrl === 'string') {
|
|
||||||
return item.imageUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DragPreview = memo(({ data }: DragPreviewProps) => {
|
export const DragPreview = memo(({ data }: DragPreviewProps) => {
|
||||||
const items = data.item || [];
|
const items = data.item || [];
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const itemCount = items.length;
|
const itemCount = items.length;
|
||||||
const firstItem = items[0];
|
const firstItem = items[0];
|
||||||
const itemName = firstItem ? getItemName(firstItem) : 'Item';
|
const itemName = firstItem ? getItemName(firstItem) : 'Item';
|
||||||
const itemImage = firstItem ? getItemImage(firstItem) : null;
|
|
||||||
|
const itemImage = useItemImageUrl({
|
||||||
|
id: (firstItem as { id: string })?.id,
|
||||||
|
itemType: data.itemType || LibraryItem.SONG,
|
||||||
|
type: 'table',
|
||||||
|
});
|
||||||
|
|
||||||
const isMultiple = itemCount > 1;
|
const isMultiple = itemCount > 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -18,7 +18,7 @@ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/el
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
|
|
||||||
import { DragPreview } from '/@/shared/components/drag-preview/drag-preview';
|
import { DragPreview } from '/@/renderer/components/drag-preview/drag-preview';
|
||||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||||
import { dndUtils, DragData, DragOperation, DragTarget } from '/@/shared/types/drag-and-drop';
|
import { dndUtils, DragData, DragOperation, DragTarget } from '/@/shared/types/drag-and-drop';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user