mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-29 10:52:47 -04:00
* added buttons for zoom in and out * currently added only English translation * added magnification prop * added a `div` Wrapper for Scrolling * Update Original.tsx * Update de/common.json * Update es/common.json * Update fr/common.json * Update it/common.json * Update js/common.json * Update nl/common.json * Update ru/common.json * Update tr/common.json * Update by/common.json * Update zh-CN/common.json * Update zh-TW/common.json * Reset Zoom * Squashed commit of the following: commit 36ae94c998874b5aaf79be0b87d1c05c605b1ff0 Merge: df02017299126332dfAuthor: Aditya <raghavbhai4545@gmail.com> Date: Sat Apr 27 21:35:22 2024 +0530 Merge branch 'spacedriveapp:main' into main commit9126332df1Author: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Sat Apr 27 18:08:07 2024 +0300 [MOB-89] Separate headers (#2408) * separate headers improvements to headers cleanup missed cleanup documentation * Update SearchStack.tsx commita61a7bee65Author: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Fri Apr 26 20:36:21 2024 +0300 Windows mouse resize fix (#2407) Update useMouseItemResize.ts commit9384bade61Author: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Date: Thu Apr 25 21:29:55 2024 -0300 Revert OpenDAL for ephemeral location (#2399) * Revert "OpenDAL - Ephemeral Locations (#2283)" This reverts commit2848782e8e. * Format * Fix some diff problems commite76ff78f3cAuthor: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Thu Apr 25 20:29:55 2024 -0400 Alpha 0.2.13 (#2394) bump commit476447ab70Author: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Date: Thu Apr 25 21:20:36 2024 -0300 Fix server release again (#2403) * Fix server release again * small improvement to regex commitab46cffa11Author: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Date: Thu Apr 25 14:37:25 2024 -0700 Reactive file identification (#2396) * yes * Explain mysterious if * Use id alias just for consistency reasons * yes * Rust fmt * fix ts --------- Co-authored-by: Ericson "Fogo" Soares <ericson.ds999@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com> commit64bbce32e9Author: Utku <74243531+utkubakir@users.noreply.github.com> Date: Thu Apr 25 16:06:35 2024 -0400 Fix title (#2398) * fix task manager title * 2 more config item commit310eb28e63Author: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Date: Thu Apr 25 14:58:50 2024 -0300 Fix `cargo test` & improve `pnpm prep` native deps download (#2393) Couple of fixes - Increase `pnpm prep` connection timeout to 5min, to better handle downloading native deps under flaky network conditions - Fix `cargo test` and cache-factory CI - Clippy and fmt commitb86d3d27cbAuthor: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Thu Apr 25 20:29:46 2024 +0300 [ENG-1762] Reverse mouse resize direction (#2395) Update useMouseItemResize.ts commit449337285dAuthor: Artsiom Voitas <artsiom.voitas@gmail.com> Date: Thu Apr 25 19:26:36 2024 +0300 Improved translation into Belarusian and Russian (#2391) * feat: improved translation on belarusian and russian * updated keys related to vacuum * updated keys related to vacuum commitb1ffbee9b1Author: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Date: Thu Apr 25 09:14:43 2024 -0700 Fix thumbnail generation reactivity (#2392) fix commit73f521a3b8Author: Ericson "Fogo" Soares <ericson.ds999@gmail.com> Date: Thu Apr 25 01:06:11 2024 -0300 [ENG-1629] Write new file identifier with the task system (#2334) * Introduce deep vs shallow for indexer tasks with different priorities * Make job wait to dispatch if it's paused * Extract file metadata task on file identifier job * Some initial drafts on object processor task * Object processor task for file identifier * File Identifier job and shallow commit463babe1d4Author: Heavysnowjakarta <54460050+HeavySnowJakarta@users.noreply.github.com> Date: Thu Apr 25 07:38:34 2024 +0800 I18n polish (zh-cn) (#2337) * i18n some polishes * reviewed 1st-100th strings of zh-cn i18n * change the indent to 2 space characters commit2c777e53f1Author: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Date: Wed Apr 24 20:37:38 2024 -0300 Fix core test (#2386) * Fix core test * Import CompressedCRDTOperations --------- Co-authored-by: Ericson "Fogo" Soares <ericson.ds999@gmail.com> commit57b0139240Author: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Thu Apr 25 02:34:24 2024 +0300 [MOB-90] Visual adjustments (#2383) * Visual adjustments * Update Tags.tsx * cleanup * remove prop * remove hitslop * sectionlist commite0f540a1beAuthor: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Wed Apr 24 14:20:51 2024 -0400 Small Trash UI fixes (#2385) * Update index.tsx * More ui fixes + toast * Update index.tsx * Add Translations commit279aaf2c50Author: Utku <74243531+utkubakir@users.noreply.github.com> Date: Wed Apr 24 12:48:14 2024 -0400 hide placeholders (#2384) commit3bed56d4d9Author: Utku <74243531+utkubakir@users.noreply.github.com> Date: Wed Apr 24 10:25:22 2024 -0400 Alpha 0.2.12 (#2382) * pnpm * alpha 0.2.12 * make pnpm version non strict commit0b6bd050a0Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Wed Apr 24 18:09:18 2024 +0800 Fix main (#2381) * fix * fix commitae6c49b0baAuthor: Oscar Beaumont <oscar@otbeaumont.me> Date: Wed Apr 24 16:43:30 2024 +0800 Improved p2p settings (#2379) improved p2p settings commit918c2a987dAuthor: Brendan Allan <brendonovich@outlook.com> Date: Wed Apr 24 16:26:50 2024 +0800 Batch ingest sync operations (#2378) batch ingest sync operations commit643bd3a142Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Wed Apr 24 16:27:31 2024 +0800 Block size (#2377) Block size + some Clippy commite009a0478cAuthor: Utku <74243531+utkubakir@users.noreply.github.com> Date: Tue Apr 23 19:20:59 2024 -0400 Revert "[MOB-85] Better headers" (#2376) Revert "[MOB-85] Better headers (#2375)" This reverts commit6a556a457d. commit6a556a457dAuthor: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Wed Apr 24 01:21:31 2024 +0300 [MOB-85] Better headers (#2375) * wip * improve headers * cleanup commitb4037d6537Author: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Mon Apr 22 15:46:10 2024 -0400 Open Trash from the application (#2338) * Open Trash from the application * Working Trash Sidebar Button * Small UI fixes * Update common.json * Move openTrash to Tauri Command instead of RSPC * format and remove type assertion --------- Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com> commit745399ecabAuthor: nikec <43032218+niikeec@users.noreply.github.com> Date: Mon Apr 22 20:54:42 2024 +0200 [ENG-1751] Improve active item handling (#2367) base commit959ccdfd98Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Mon Apr 22 20:43:44 2024 +0800 Reintroduce P2P Settings (#2365) * redo backend to be less cringe * fixed up commitef969f1adaAuthor: Oscar Beaumont <oscar@otbeaumont.me> Date: Mon Apr 22 19:47:47 2024 +0800 Remove indexer rules from ephemeral indexer (#2319) remove indexer rules from ephemeral indexer commit548fff1e96Author: Brendan Allan <brendonovich@outlook.com> Date: Mon Apr 22 18:29:54 2024 +0800 Ignore empty object/filepath search filters (#2371) commit52c5c2bfe7Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Mon Apr 22 18:28:35 2024 +0800 Show errors creating P2P listeners on startup (#2372) * do it * fix accuracy * `useRef` as god intended commit20e5430eafAuthor: nikec <43032218+niikeec@users.noreply.github.com> Date: Mon Apr 22 12:27:30 2024 +0200 [ENG-1753] Only open quick preview when items are selected (#2374) only toggle when items are selected commit13e4ff6107Author: nikec <43032218+niikeec@users.noreply.github.com> Date: Mon Apr 22 12:25:53 2024 +0200 [ENG-1752] Fix explorer selection reset when closing quick preview via keybind (#2373) prevent selection reset commit51c94c88e3Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Mon Apr 22 18:12:06 2024 +0800 Fix Docker start command (#2370) commitd689e7e58aAuthor: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Sun Apr 21 17:28:27 2024 +0300 [ENG-1750] Update context menu colors (#2369) update context menu colors commit df0201729278dfa11126b41922e404146c151a35 Merge:5624054f1619a4c8b6 Author: Aditya <raghavbhai4545@gmail.com> Date: Sat Apr 20 13:14:52 2024 +0530 Merge branch 'main' of https://github.com/Raghav-45/spacedrive commit947354f6c0Author: Oscar Beaumont <oscar@otbeaumont.me> Date: Sat Apr 20 11:21:20 2024 +0800 Remove files over p2p feature (#2364) * goodbye * types * a commitf97a761346Author: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Sat Apr 20 02:18:54 2024 +0300 [ENG-1745] Mouse wheel resize (#2366) * Resize layout items with mouse wheel icon/item size using mouse wheel Update useMouseItemResize.ts Update useMouseItemResize.ts * improve comment * fb * Update useMouseItemResize.ts * Update IconSize.tsx commit 619a4c8b6dfe7239bce1b54b528a3176aa7350da Merge: df4f6279b795bb18d1Author: Aditya <raghavbhai4545@gmail.com> Date: Tue Aug 29 16:59:18 2023 +0530 Merge branch 'spacedriveapp:main' into main commit df4f6279bfbd7bdaa120212b19db72cfae0d17c7 Merge: dfb519206e4b03619dAuthor: Aditya <raghavbhai4545@gmail.com> Date: Tue Aug 22 20:44:09 2023 +0530 Merge branch 'spacedriveapp:main' into main commit dfb51920667c24ff05b16ebc63bf4aea33225002 Merge: c1bfc3296a0a1c6766Author: Aditya <raghavbhai4545@gmail.com> Date: Thu Aug 17 21:22:49 2023 +0530 Merge branch 'spacedriveapp:main' into main commit c1bfc3296ee7686a6a142d74a91cf13cf4bd7677 Merge: de274c3319c0aec816Author: Aditya <raghavbhai4545@gmail.com> Date: Tue Aug 15 19:43:43 2023 +0530 Merge branch 'spacedriveapp:main' into main commit de274c3317cff942e9c3a4f2c8c08819a897d251 Merge: 14faf0bcec86a728a1Author: Aditya <raghavbhai4545@gmail.com> Date: Sun Aug 13 21:54:16 2023 +0530 Merge branch 'spacedriveapp:main' into main commit 14faf0bce2ee9123bf66706812357d6aefc44dea Merge: 3e013d8bdbaf032883Author: Aditya <raghavbhai4545@gmail.com> Date: Thu Aug 10 06:54:01 2023 -0400 Merge branch 'spacedriveapp:main' into main commit 3e013d8bdef2ba59536c90044be4312336b6cd8a Merge:2e702f2eb7708ba585Author: Aditya <raghavbhai4545@gmail.com> Date: Tue Aug 8 11:21:07 2023 -0400 Merge branch 'spacedriveapp:main' into main commit2e702f2ebaAuthor: Brendan Allan <brendonovich@outlook.com> Date: Tue Aug 8 07:58:58 2023 -0700 Mention pnpm dev:web in CONTRIBUTING.md commita1c5c55a37Author: Raghav-45 <77260113+Raghav-45@users.noreply.github.com> Date: Tue Aug 8 18:49:50 2023 +0530 Update command to run server I encountered an issue where the cargo run -p server command was not functioning properly. It took me nearly an hour to pinpoint the problem, which turned out to be related to a modification in the Cargo.toml file. This change was made by @Brendonovich during their work on issue #1181, which pertained to *syncing ingestion*. Initially, I believed that re-cloning the repository from GitHub would resolve the issue. However, after attempting this solution exactly 5 times, I realized my assumption was incorrect. Despite the time and effort spent, I was able to successfully identify and rectify the problem. * conflicts * Revert "conflicts" This reverts commit2f1066a0a3. * Revert "Squashed commit of the following:" This reverts commitcd2435edaf. * change in line endings from 'LF' to 'CRLF'. * Update common.json * Update common.json * Update common.json * fixed indent --------- Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
291 lines
7.8 KiB
TypeScript
291 lines
7.8 KiB
TypeScript
import { getIcon, getIconByName } from '@sd/assets/util';
|
|
import clsx from 'clsx';
|
|
import {
|
|
forwardRef,
|
|
HTMLAttributes,
|
|
SyntheticEvent,
|
|
useImperativeHandle,
|
|
useMemo,
|
|
useRef,
|
|
useState
|
|
} from 'react';
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
import { getItemFilePath, useLibraryContext, type ExplorerItem } from '@sd/client';
|
|
import { useIsDark } from '~/hooks';
|
|
import { pdfViewerEnabled } from '~/util/pdfViewer';
|
|
import { usePlatform } from '~/util/Platform';
|
|
|
|
import { useExplorerItemData } from '../useExplorerItemData';
|
|
import { Image, ImageProps } from './Image';
|
|
import LayeredFileIcon from './LayeredFileIcon';
|
|
import { Original } from './Original';
|
|
import { useFrame } from './useFrame';
|
|
import { useBlackBars, useSize } from './utils';
|
|
|
|
export interface ThumbProps {
|
|
data: ExplorerItem;
|
|
loadOriginal?: boolean;
|
|
size?: number;
|
|
cover?: boolean;
|
|
frame?: boolean;
|
|
onLoad?: (state: ThumbType) => void;
|
|
onError?: (state: ThumbType, error: Error) => void;
|
|
blackBars?: boolean;
|
|
blackBarsSize?: number;
|
|
extension?: boolean;
|
|
mediaControls?: boolean;
|
|
pauseVideo?: boolean;
|
|
className?: string;
|
|
frameClassName?: string;
|
|
childClassName?: string | ((type: ThumbType) => string | undefined);
|
|
isSidebarPreview?: boolean;
|
|
childProps?: HTMLAttributes<HTMLElement>;
|
|
magnification?: number;
|
|
}
|
|
|
|
type ThumbType = { variant: 'original' } | { variant: 'thumbnail' } | { variant: 'icon' };
|
|
|
|
export const FileThumb = forwardRef<HTMLImageElement, ThumbProps>((props, ref) => {
|
|
const isDark = useIsDark();
|
|
const platform = usePlatform();
|
|
const frame = useFrame();
|
|
|
|
const itemData = useExplorerItemData(props.data);
|
|
const filePath = getItemFilePath(props.data);
|
|
|
|
const { library } = useLibraryContext();
|
|
|
|
const [loadState, setLoadState] = useState<{
|
|
[K in 'original' | 'thumbnail' | 'icon']: 'notLoaded' | 'loaded' | 'error';
|
|
}>({ original: 'notLoaded', thumbnail: 'notLoaded', icon: 'notLoaded' });
|
|
|
|
const childClassName = 'max-h-full max-w-full object-contain';
|
|
const frameClassName = clsx(frame.className, props.frameClassName);
|
|
|
|
const thumbType = useMemo<ThumbType>(() => {
|
|
const thumbType = 'thumbnail';
|
|
|
|
if (thumbType === 'thumbnail')
|
|
if (
|
|
loadState.thumbnail !== 'error' &&
|
|
itemData.hasLocalThumbnail &&
|
|
itemData.thumbnailKey.length > 0
|
|
)
|
|
return { variant: 'thumbnail' };
|
|
|
|
return { variant: 'icon' };
|
|
}, [itemData, loadState]);
|
|
|
|
const src = useMemo(() => {
|
|
switch (thumbType.variant) {
|
|
case 'original':
|
|
if (filePath && (itemData.extension !== 'pdf' || pdfViewerEnabled())) {
|
|
if ('id' in filePath && itemData.locationId)
|
|
return platform.getFileUrl(library.uuid, itemData.locationId, filePath.id);
|
|
else if ('path' in filePath) return platform.getFileUrlByPath(filePath.path);
|
|
}
|
|
break;
|
|
|
|
case 'thumbnail':
|
|
if (itemData.thumbnailKey.length > 0)
|
|
return platform.getThumbnailUrlByThumbKey(itemData.thumbnailKey);
|
|
|
|
break;
|
|
case 'icon':
|
|
if (itemData.customIcon) return getIconByName(itemData.customIcon as any, isDark);
|
|
|
|
return getIcon(
|
|
// itemData.isDir || parent?.type === 'Node' ? 'Folder' :
|
|
itemData.kind,
|
|
isDark,
|
|
itemData.extension,
|
|
itemData.isDir
|
|
);
|
|
}
|
|
}, [filePath, isDark, library.uuid, itemData, platform, thumbType]);
|
|
|
|
const onLoad = (s: 'original' | 'thumbnail' | 'icon') => {
|
|
setLoadState((state) => ({ ...state, [s]: 'loaded' }));
|
|
props.onLoad?.call(null, thumbType);
|
|
};
|
|
|
|
const onError = (
|
|
s: 'original' | 'thumbnail' | 'icon',
|
|
event: ErrorEvent | SyntheticEvent<Element, Event>
|
|
) => {
|
|
setLoadState((state) => ({ ...state, [s]: 'error' }));
|
|
|
|
const rawError =
|
|
('error' in event && event.error) ||
|
|
('message' in event && event.message) ||
|
|
'Filetype is not supported yet';
|
|
|
|
props.onError?.call(
|
|
null,
|
|
thumbType,
|
|
rawError instanceof Error ? rawError : new Error(rawError)
|
|
);
|
|
};
|
|
|
|
const _childClassName =
|
|
typeof props.childClassName === 'function'
|
|
? props.childClassName(thumbType)
|
|
: props.childClassName;
|
|
|
|
const className = clsx(childClassName, _childClassName);
|
|
|
|
const thumbnail = (() => {
|
|
if (!src) return <></>;
|
|
|
|
switch (thumbType.variant) {
|
|
case 'thumbnail':
|
|
return (
|
|
<Thumbnail
|
|
{...props.childProps}
|
|
ref={ref}
|
|
src={src}
|
|
cover={props.cover}
|
|
onLoad={() => onLoad('thumbnail')}
|
|
onError={(e) => onError('thumbnail', e)}
|
|
decoding={props.size ? 'async' : 'sync'}
|
|
className={clsx(
|
|
props.cover
|
|
? [
|
|
'min-h-full min-w-full object-cover object-center',
|
|
_childClassName
|
|
]
|
|
: className,
|
|
props.frame && !(itemData.kind === 'Video' && props.blackBars)
|
|
? frameClassName
|
|
: null
|
|
)}
|
|
crossOrigin="anonymous" // Here it is ok, because it is not a react attr
|
|
blackBars={props.blackBars && itemData.kind === 'Video' && !props.cover}
|
|
blackBarsSize={props.blackBarsSize}
|
|
extension={
|
|
props.extension && itemData.extension && itemData.kind === 'Video'
|
|
? itemData.extension
|
|
: undefined
|
|
}
|
|
/>
|
|
);
|
|
|
|
case 'icon':
|
|
return (
|
|
<LayeredFileIcon
|
|
{...props.childProps}
|
|
ref={ref}
|
|
src={src}
|
|
kind={itemData.kind}
|
|
extension={itemData.extension}
|
|
onLoad={() => onLoad('icon')}
|
|
onError={(e) => onError('icon', e)}
|
|
decoding={props.size ? 'async' : 'sync'}
|
|
className={className}
|
|
draggable={false}
|
|
/>
|
|
);
|
|
default:
|
|
return <></>;
|
|
}
|
|
})();
|
|
|
|
return (
|
|
<div
|
|
key={thumbType.variant}
|
|
style={{
|
|
...(props.size
|
|
? { maxWidth: props.size, width: props.size, height: props.size }
|
|
: {})
|
|
}}
|
|
className={clsx(
|
|
'relative flex shrink-0 items-center justify-center',
|
|
// !loaded && 'invisible',
|
|
!props.size && 'size-full',
|
|
props.cover && 'overflow-hidden',
|
|
props.className
|
|
)}
|
|
>
|
|
{props.loadOriginal ? (
|
|
<ErrorBoundary fallback={thumbnail}>
|
|
<Original
|
|
onLoad={() => onLoad('original')}
|
|
onError={(e) => onError('original', e)}
|
|
filePath={filePath}
|
|
className={className}
|
|
frameClassName={frameClassName}
|
|
itemData={itemData}
|
|
isDark={isDark}
|
|
childClassName={childClassName}
|
|
size={props.size}
|
|
magnification={props.magnification}
|
|
mediaControls={props.mediaControls}
|
|
frame={props.frame}
|
|
isSidebarPreview={props.isSidebarPreview}
|
|
pauseVideo={props.pauseVideo}
|
|
blackBars={props.blackBars}
|
|
blackBarsSize={props.blackBarsSize}
|
|
/>
|
|
</ErrorBoundary>
|
|
) : (
|
|
thumbnail
|
|
)}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
interface ThumbnailProps extends Omit<ImageProps, 'blackBarsStyle' | 'size'> {
|
|
cover?: boolean;
|
|
blackBars?: boolean;
|
|
blackBarsSize?: number;
|
|
extension?: string;
|
|
}
|
|
|
|
const Thumbnail = forwardRef<HTMLImageElement, ThumbnailProps>(
|
|
({ blackBars, blackBarsSize, extension, cover, className, style, ...props }, _ref) => {
|
|
const ref = useRef<HTMLImageElement>(null);
|
|
useImperativeHandle<HTMLImageElement | null, HTMLImageElement | null>(
|
|
_ref,
|
|
() => ref.current
|
|
);
|
|
|
|
const size = useSize(ref);
|
|
|
|
const { style: blackBarsStyle } = useBlackBars(ref, size, {
|
|
size: blackBarsSize,
|
|
disabled: !blackBars
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<Image
|
|
{...props}
|
|
className={clsx(className, blackBars && size.width === 0 && 'invisible')}
|
|
style={{ ...style, ...blackBarsStyle }}
|
|
size={size}
|
|
ref={ref}
|
|
/>
|
|
|
|
{(cover || size.width > 80) && extension && (
|
|
<div
|
|
style={{
|
|
...(!cover && {
|
|
marginTop: Math.floor(size.height / 2) - 2,
|
|
marginLeft: Math.floor(size.width / 2) - 2
|
|
})
|
|
}}
|
|
className={clsx(
|
|
'pointer-events-none absolute rounded bg-black/60 px-1 py-0.5 text-[9px] font-semibold uppercase text-white opacity-70',
|
|
cover
|
|
? 'bottom-1 right-1'
|
|
: 'left-1/2 top-1/2 -translate-x-full -translate-y-full'
|
|
)}
|
|
>
|
|
{extension}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
);
|