mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-17 22:39:42 +02:00
Fix editor stale callbacks and recent item deletion
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "Yaak",
|
"productName": "Yaak",
|
||||||
"version": "2023.1.5"
|
"version": "2023.1.6"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"windows": [],
|
"windows": [],
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
|
|
||||||
const showEnvironmentDialog = useCallback(() => {
|
const showEnvironmentDialog = useCallback(() => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
title: "Manage Environments",
|
title: 'Manage Environments',
|
||||||
render: () => <EnvironmentEditDialog />,
|
render: () => <EnvironmentEditDialog />,
|
||||||
});
|
});
|
||||||
}, [dialog]);
|
}, [dialog]);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const EnvironmentEditDialog = function () {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{showSidebar && (
|
{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">
|
<div className="min-w-0 h-full w-full overflow-y-scroll">
|
||||||
{environments.map((e) => (
|
{environments.map((e) => (
|
||||||
<Button
|
<Button
|
||||||
@@ -68,7 +68,13 @@ export const EnvironmentEditDialog = function () {
|
|||||||
</Button>
|
</Button>
|
||||||
</aside>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ export default function Workspaces() {
|
|||||||
return <Heading>There are no workspaces</Heading>;
|
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 })} />;
|
return <Navigate to={routes.paths.workspace({ workspaceId })} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,9 +57,10 @@ export function Dialog({
|
|||||||
'relative bg-gray-50 pointer-events-auto',
|
'relative bg-gray-50 pointer-events-auto',
|
||||||
'p-5 rounded-lg overflow-auto',
|
'p-5 rounded-lg overflow-auto',
|
||||||
'dark:border border-highlight shadow shadow-black/10',
|
'dark:border border-highlight shadow shadow-black/10',
|
||||||
|
'max-w-[90vw] max-h-[calc(100vh-8em)]',
|
||||||
size === 'sm' && 'w-[25rem] max-h-[80vh]',
|
size === 'sm' && 'w-[25rem] max-h-[80vh]',
|
||||||
size === 'md' && 'w-[45rem] 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]',
|
size === 'dynamic' && 'min-w-[30vw] max-w-[80vw]',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -267,10 +267,11 @@ function getExtensions({
|
|||||||
: []),
|
: []),
|
||||||
|
|
||||||
// Handle onFocus
|
// Handle onFocus
|
||||||
|
// NOTE: These *must* be anonymous functions so the references update properly
|
||||||
EditorView.domEventHandlers({
|
EditorView.domEventHandlers({
|
||||||
focus: onFocus.current,
|
focus: () => onFocus.current?.(),
|
||||||
blur: onBlur.current,
|
blur: () => onBlur.current?.(),
|
||||||
keydown: onKeyDown.current,
|
keydown: e => onKeyDown.current?.(e),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Handle onChange
|
// Handle onChange
|
||||||
|
|||||||
@@ -102,14 +102,17 @@ export const Input = forwardRef<EditorView | undefined, InputProps>(function Inp
|
|||||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
// Submit nearest form on Enter key press
|
// Submit nearest form on Enter key press
|
||||||
const handleKeyDown = useCallback((e: KeyboardEvent) => {
|
const handleKeyDown = useCallback(
|
||||||
if (e.key !== 'Enter') return;
|
(e: KeyboardEvent) => {
|
||||||
|
if (e.key !== 'Enter') return;
|
||||||
|
|
||||||
const form = wrapperRef.current?.closest('form');
|
const form = wrapperRef.current?.closest('form');
|
||||||
if (!isValid || form == null) return;
|
if (!isValid || form == null) return;
|
||||||
|
|
||||||
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
|
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
|
||||||
}, [isValid]);
|
},
|
||||||
|
[isValid],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack ref={wrapperRef} className="w-full">
|
<VStack ref={wrapperRef} className="w-full">
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useMemo } from 'react';
|
||||||
import { createGlobalState, useEffectOnce } from 'react-use';
|
import { createGlobalState, useEffectOnce } from 'react-use';
|
||||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||||
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
||||||
import { useKeyValue } from './useKeyValue';
|
import { useKeyValue } from './useKeyValue';
|
||||||
import { NAMESPACE_GLOBAL, getKeyValue } from '../lib/keyValueStore';
|
import { NAMESPACE_GLOBAL, getKeyValue } from '../lib/keyValueStore';
|
||||||
|
import { useEnvironments } from './useEnvironments';
|
||||||
|
|
||||||
const useHistoryState = createGlobalState<string[]>([]);
|
const useHistoryState = createGlobalState<string[]>([]);
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ const namespace = NAMESPACE_GLOBAL;
|
|||||||
const defaultValue: string[] = [];
|
const defaultValue: string[] = [];
|
||||||
|
|
||||||
export function useRecentEnvironments() {
|
export function useRecentEnvironments() {
|
||||||
|
const environments = useEnvironments();
|
||||||
const activeWorkspaceId = useActiveWorkspaceId();
|
const activeWorkspaceId = useActiveWorkspaceId();
|
||||||
const activeEnvironmentId = useActiveEnvironmentId();
|
const activeEnvironmentId = useActiveEnvironmentId();
|
||||||
const [history, setHistory] = useHistoryState();
|
const [history, setHistory] = useHistoryState();
|
||||||
@@ -31,7 +33,7 @@ export function useRecentEnvironments() {
|
|||||||
// Update local storage state when history changes
|
// Update local storage state when history changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
kv.set(history);
|
kv.set(history);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
// Set history when active request changes
|
// Set history when active request changes
|
||||||
@@ -43,7 +45,12 @@ export function useRecentEnvironments() {
|
|||||||
});
|
});
|
||||||
}, [activeEnvironmentId, setHistory]);
|
}, [activeEnvironmentId, setHistory]);
|
||||||
|
|
||||||
return history;
|
const onlyValidIds = useMemo(
|
||||||
|
() => history.filter((id) => environments.some((e) => e.id === id)),
|
||||||
|
[history, environments],
|
||||||
|
);
|
||||||
|
|
||||||
|
return onlyValidIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRecentEnvironments(workspaceId: string) {
|
export async function getRecentEnvironments(workspaceId: string) {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useMemo } from 'react';
|
||||||
import { createGlobalState, useEffectOnce, useLocalStorage } from 'react-use';
|
import { createGlobalState, useEffectOnce, useLocalStorage } from 'react-use';
|
||||||
import { useActiveRequestId } from './useActiveRequestId';
|
|
||||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||||
|
import { useWorkspaces } from './useWorkspaces';
|
||||||
|
|
||||||
const useHistoryState = createGlobalState<string[]>([]);
|
const useHistoryState = createGlobalState<string[]>([]);
|
||||||
|
|
||||||
export function useRecentWorkspaces() {
|
export function useRecentWorkspaces() {
|
||||||
|
const workspaces = useWorkspaces();
|
||||||
const activeWorkspaceId = useActiveWorkspaceId();
|
const activeWorkspaceId = useActiveWorkspaceId();
|
||||||
const [history, setHistory] = useHistoryState();
|
const [history, setHistory] = useHistoryState();
|
||||||
const [lsState, setLSState] = useLocalStorage<string[]>('recent_workspaces', []);
|
const [lsState, setLSState] = useLocalStorage<string[]>('recent_workspaces', []);
|
||||||
@@ -31,5 +32,10 @@ export function useRecentWorkspaces() {
|
|||||||
});
|
});
|
||||||
}, [activeWorkspaceId, setHistory]);
|
}, [activeWorkspaceId, setHistory]);
|
||||||
|
|
||||||
return history;
|
const onlyValidIds = useMemo(
|
||||||
|
() => history.filter((id) => workspaces.some((w) => w.id === id)),
|
||||||
|
[history, workspaces],
|
||||||
|
);
|
||||||
|
|
||||||
|
return onlyValidIds;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user