mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-24 16:41:07 -04:00
* Update rspc, prisma-client-rust, axum and tanstack-query - Deleted some unused examples and fully commented out frontend code - Implement many changes required due to the updates - Update most rust dependencies * Re-enable p2p * Fix server * Auto format * Fix injected script format - Update some github actions - Update pnpm lock file * Fix devtools showing up when app opens - Fix million complaining about Sparkles component * Fix sd-server * Fix and improve thumbnails rendering - Fix core always saying a new thumbnail was generated even for files that it skiped thumbnail generation - Rewrite FileThumb and improve related components * Ignore tmp files when running prettier * Improve FileThumb component performance - Rework useExplorerDraggable and useExplorerItemData hooks due to reduce unecessary re-renders * More fixes for thumb component - A couple of minor performance improvements to frontend code * auto format * Fix Thumbnail and QuickPreview * Fix logic for when to show 'fail to load original' error message in QuickPreview - Updated prisma-client-rust, libp2p, tauri, tauri-specta, rspc and hyper * Fix type checking - Format scripts * Add script prettier config * Fix serde missing feature - Use rust-libp2p spacedrive fork again - Update rspc * Autoformat + fix pnpm lock * Fix thumbnail first load again * Autoformat * autoformat * Fix rust-libp2p fork url again? * Remove usePathsInfiniteQuery hook * Update tauri 2.0.6
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { getIcon, getIconByName, getLayeredIcon, IconTypes } from '@sd/assets/util';
|
|
import clsx from 'clsx';
|
|
import { forwardRef, Suspense, useMemo, type ImgHTMLAttributes } from 'react';
|
|
import { type ObjectKindKey } from '@sd/client';
|
|
import { useIsDark } from '~/hooks';
|
|
|
|
interface LayeredFileIconProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src'> {
|
|
kind: ObjectKindKey;
|
|
isDir: boolean;
|
|
extension: string | null;
|
|
customIcon: IconTypes | null;
|
|
}
|
|
|
|
const SUPPORTED_ICONS = ['Document', 'Code', 'Text', 'Config'];
|
|
|
|
const positionConfig: Record<string, string> = {
|
|
Text: 'flex h-full w-full items-center justify-center',
|
|
Code: 'flex h-full w-full items-center justify-center',
|
|
Config: 'flex h-full w-full items-center justify-center'
|
|
};
|
|
|
|
const LayeredFileIcon = forwardRef<HTMLImageElement, LayeredFileIconProps>(
|
|
({ kind, isDir, extension, customIcon, ...props }, ref) => {
|
|
const isDark = useIsDark();
|
|
|
|
const src = useMemo(
|
|
() =>
|
|
customIcon
|
|
? getIconByName(customIcon, isDark)
|
|
: getIcon(kind, isDark, extension, isDir),
|
|
[customIcon, isDark, kind, extension, isDir]
|
|
);
|
|
|
|
const iconImg = <img ref={ref} src={src} {...props} alt={`${kind} icon`} />;
|
|
|
|
if (SUPPORTED_ICONS.includes(kind) === false) {
|
|
return iconImg;
|
|
}
|
|
|
|
const IconComponent = extension ? getLayeredIcon(kind, extension) : null;
|
|
|
|
const positionClass =
|
|
positionConfig[kind] || 'flex h-full w-full items-end justify-end pb-4 pr-2';
|
|
|
|
return IconComponent == null ? (
|
|
iconImg
|
|
) : (
|
|
<div className="relative">
|
|
{iconImg}
|
|
<div
|
|
className={clsx('pointer-events-none absolute bottom-0 right-0', positionClass)}
|
|
>
|
|
<Suspense>
|
|
<IconComponent viewBox="0 0 16 16" height="40%" width="40%" />
|
|
</Suspense>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
);
|
|
|
|
export default LayeredFileIcon;
|