Files
spacedrive/interface/app/$libraryId/Explorer/View/GridView.tsx
Utku ac0078cd59 [ENG-1416] Add black bars back to grid and list view (#1760)
Add black bars back to grid and list view
2023-11-09 18:25:29 +00:00

90 lines
2.3 KiB
TypeScript

import clsx from 'clsx';
import { memo } from 'react';
import { useMatch } from 'react-router';
import {
byteSize,
getExplorerItemData,
getItemFilePath,
getItemLocation,
type ExplorerItem
} from '@sd/client';
import { useExplorerContext } from '../Context';
import { FileThumb } from '../FilePath/Thumb';
import { useExplorerViewContext } from '../ViewContext';
import GridList from './GridList';
import { RenamableItemText } from './RenamableItemText';
import { ViewItem } from './ViewItem';
interface GridViewItemProps {
data: ExplorerItem;
selected: boolean;
isRenaming: boolean;
cut: boolean;
}
const GridViewItem = memo(({ data, selected, cut, isRenaming }: GridViewItemProps) => {
const explorer = useExplorerContext();
const { showBytesInGridView } = explorer.useSettingsSnapshot();
const explorerItemData = getExplorerItemData(data);
const filePathData = getItemFilePath(data);
const location = getItemLocation(data);
const isEphemeralLocation = useMatch('/:libraryId/ephemeral/:ephemeralId');
const isFolder = filePathData?.is_dir;
const hidden = filePathData?.hidden;
const showSize =
showBytesInGridView &&
!location &&
!isFolder &&
(!isEphemeralLocation || !isFolder) &&
(!isRenaming || !selected);
return (
<ViewItem data={data} className={clsx('h-full w-full', hidden && 'opacity-50')}>
<div
className={clsx('mb-1 aspect-square rounded-lg', selected && 'bg-app-selectedItem')}
>
<FileThumb
data={data}
frame={explorerItemData.kind !== 'Video'}
extension
blackBars
className={clsx('px-2 py-1', cut && 'opacity-60')}
/>
</div>
<div className="flex flex-col justify-center">
<RenamableItemText item={data} style={{ maxHeight: 40 }} lines={2} />
{showSize && filePathData?.size_in_bytes_bytes && (
<span
className={clsx(
'cursor-default truncate rounded-md px-1.5 py-[1px] text-center text-tiny text-ink-dull'
)}
>
{`${byteSize(filePathData.size_in_bytes_bytes)}`}
</span>
)}
</div>
</ViewItem>
);
});
export default () => {
const explorerView = useExplorerViewContext();
return (
<GridList>
{({ item, selected, cut }) => (
<GridViewItem
data={item}
selected={selected}
cut={cut}
isRenaming={explorerView.isRenaming}
/>
)}
</GridList>
);
};