Fix editor stale callbacks and recent item deletion

This commit is contained in:
Gregory Schier
2023-10-30 07:06:21 -07:00
parent 51949f4fbf
commit 8b5d7ae3ed
9 changed files with 45 additions and 20 deletions

View File

@@ -28,7 +28,7 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
const showEnvironmentDialog = useCallback(() => {
dialog.show({
title: "Manage Environments",
title: 'Manage Environments',
render: () => <EnvironmentEditDialog />,
});
}, [dialog]);

View File

@@ -37,7 +37,7 @@ export const EnvironmentEditDialog = function () {
)}
>
{showSidebar && (
<aside className="grid grid-rows-[minmax(0,1fr)_auto] gap-y-0.5 h-full max-w-[200px] pr-4 border-r border-gray-100">
<aside className="grid grid-rows-[minmax(0,1fr)_auto] gap-y-0.5 h-full max-w-[250px] pr-4 border-r border-gray-100">
<div className="min-w-0 h-full w-full overflow-y-scroll">
{environments.map((e) => (
<Button
@@ -68,7 +68,13 @@ export const EnvironmentEditDialog = function () {
</Button>
</aside>
)}
{activeEnvironment != null && <EnvironmentEditor environment={activeEnvironment} />}
{activeEnvironment != null ? (
<EnvironmentEditor environment={activeEnvironment} />
) : (
<div className="flex w-full h-full items-center justify-center text-gray-400 italic">
select an environment
</div>
)}
</div>
);
};

View File

@@ -20,5 +20,6 @@ export default function Workspaces() {
return <Heading>There are no workspaces</Heading>;
}
// TODO: Somehow get recent environmentId for the workspace in here too
return <Navigate to={routes.paths.workspace({ workspaceId })} />;
}

View File

@@ -57,9 +57,10 @@ export function Dialog({
'relative bg-gray-50 pointer-events-auto',
'p-5 rounded-lg overflow-auto',
'dark:border border-highlight shadow shadow-black/10',
'max-w-[90vw] max-h-[calc(100vh-8em)]',
size === 'sm' && 'w-[25rem] max-h-[80vh]',
size === 'md' && 'w-[45rem] max-h-[80vh]',
size === 'full' && 'w-[95vw] h-[calc(100vh-6em)]',
size === 'full' && 'w-[100vw] h-[100vh]',
size === 'dynamic' && 'min-w-[30vw] max-w-[80vw]',
)}
>

View File

@@ -267,10 +267,11 @@ function getExtensions({
: []),
// Handle onFocus
// NOTE: These *must* be anonymous functions so the references update properly
EditorView.domEventHandlers({
focus: onFocus.current,
blur: onBlur.current,
keydown: onKeyDown.current,
focus: () => onFocus.current?.(),
blur: () => onBlur.current?.(),
keydown: e => onKeyDown.current?.(e),
}),
// Handle onChange

View File

@@ -102,14 +102,17 @@ export const Input = forwardRef<EditorView | undefined, InputProps>(function Inp
const wrapperRef = useRef<HTMLDivElement>(null);
// Submit nearest form on Enter key press
const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key !== 'Enter') return;
const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
if (e.key !== 'Enter') return;
const form = wrapperRef.current?.closest('form');
if (!isValid || form == null) return;
const form = wrapperRef.current?.closest('form');
if (!isValid || form == null) return;
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
}, [isValid]);
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
},
[isValid],
);
return (
<VStack ref={wrapperRef} className="w-full">