mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-20 14:38:58 -04:00
* WIP * Some minor fixes for light theme - Fix `useIsDark` not reading the initial theme value (only reacting to theme changes) - Fix `Inspector` always showing a dark image when no item was selected - Fix `Thumb` video extension using black text on light theme * Improve form error messages - Fix `addLocationDialog` not registering the path input - Remove `@hookform/error-message` * Fix Dialog not respecting max-width - Fix ErrorMessage animation jumping * A lot of misc fixes - Implement an `useExplorerItemData` (cleaner fix for thumbnail flicker) - Fix broken image showing for `Thumb` due a rece condition when props are updated - Implement an `ExternalObject` component that hacks an alternative for `onLoad` and `onError` events for <object> - Fix `Overview` broken layout when `Inspector` is open and window is small - Improve `IndexerRuleEditor` UX in `AddLocationDialog` - Improve the way `IndexerRuleEditor` handles rules deletion - Fix `IndexerRuleEditor` closing the the new rule form even when the rule creation fails - Add an editable prop to `IndexerRuleEditor` to disable all editable functions - Fix `getIcon` fallbacking to Document instead of the dark version of an icon if it exists - Add some missing colors to white theme * Format * Fix Backup restore key dialog not resetting after error * Feedback * Format * Normalize imports * Fix ColorPicker export * Fix Thumb video ext not showing in MediaView with show square thumbnails - Fix AddLocationDialog Error resetting when changing IndexRules
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { useLayoutEffect } from 'react';
|
|
|
|
export interface ExternalObjectProps
|
|
extends Omit<React.ComponentProps<'object'>, 'chidren' | 'onLoad' | 'onError'> {
|
|
data: string;
|
|
onLoad?: (event: Event) => void;
|
|
onError?: (event: string | Event) => void;
|
|
crossOrigin?: React.ComponentProps<'link'>['crossOrigin'];
|
|
}
|
|
|
|
export const ExternalObject = ({
|
|
data,
|
|
onLoad,
|
|
onError,
|
|
crossOrigin,
|
|
...props
|
|
}: ExternalObjectProps) => {
|
|
// Use link preload as a hack to get access to an onLoad and onError events for the object tag
|
|
useLayoutEffect(
|
|
() => {
|
|
if (!(onLoad && onError)) return;
|
|
|
|
const link = document.createElement('link');
|
|
link.as = 'fetch';
|
|
link.rel = 'preload';
|
|
if (crossOrigin) link.crossOrigin = crossOrigin;
|
|
link.href = data;
|
|
|
|
link.onload = (e) => {
|
|
link.remove();
|
|
onLoad(e);
|
|
};
|
|
|
|
link.onerror = (e) => {
|
|
link.remove();
|
|
onError(e);
|
|
};
|
|
|
|
document.head.appendChild(link);
|
|
|
|
() => link.remove();
|
|
},
|
|
// Disable this rule because onLoad and onError changed should not trigger this effect
|
|
// TODO: Remove this after useEffectEvent enters stable React
|
|
// https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
[data, crossOrigin]
|
|
);
|
|
|
|
return <object data={data} {...props} />;
|
|
};
|