mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 20:00:29 +01:00
Better request creation (Closes #14)
This commit is contained in:
@@ -6,6 +6,7 @@ import { useDrag, useDrop } from 'react-dnd';
|
||||
import { useKey, useKeyPressEvent } from 'react-use';
|
||||
|
||||
import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||
import { useActiveRequestId } from '../hooks/useActiveRequestId';
|
||||
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||
@@ -527,8 +528,8 @@ const SidebarItem = forwardRef(function SidebarItem(
|
||||
const updateAnyFolder = useUpdateAnyFolder();
|
||||
const prompt = usePrompt();
|
||||
const [editing, setEditing] = useState<boolean>(false);
|
||||
const activeRequestId = useActiveRequestId();
|
||||
const isActive = activeRequestId === itemId;
|
||||
const activeRequest = useActiveRequest();
|
||||
const isActive = activeRequest?.id === itemId;
|
||||
|
||||
const handleSubmitNameEdit = useCallback(
|
||||
(el: HTMLInputElement) => {
|
||||
@@ -629,9 +630,8 @@ const SidebarItem = forwardRef(function SidebarItem(
|
||||
{
|
||||
key: 'createRequest',
|
||||
label: 'New Request',
|
||||
hotkeyAction: 'request.create',
|
||||
leftSlot: <Icon icon="plus" />,
|
||||
onSelect: () => createRequest.mutate({ folderId: itemId, sortPriority: -1 }),
|
||||
onSelect: () => createRequest.mutate({ folderId: itemId }),
|
||||
},
|
||||
{
|
||||
key: 'createFolder',
|
||||
@@ -647,7 +647,7 @@ const SidebarItem = forwardRef(function SidebarItem(
|
||||
hotkeyAction: 'request.duplicate',
|
||||
leftSlot: <Icon icon="copy" />,
|
||||
onSelect: () => {
|
||||
if (activeRequestId === itemId) {
|
||||
if (activeRequest?.id === itemId) {
|
||||
duplicateRequest.mutate();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -24,7 +24,15 @@ export function useCreateRequest() {
|
||||
if (workspaceId === null) {
|
||||
throw new Error("Cannot create request when there's no active workspace");
|
||||
}
|
||||
patch.sortPriority = patch.sortPriority || -Date.now();
|
||||
if (patch.sortPriority === undefined) {
|
||||
if (activeRequest != null) {
|
||||
// Place above currently-active request
|
||||
patch.sortPriority = activeRequest.sortPriority + 0.0001;
|
||||
} else {
|
||||
// Place at the very top
|
||||
patch.sortPriority = -Date.now();
|
||||
}
|
||||
}
|
||||
patch.folderId = patch.folderId || activeRequest?.folderId;
|
||||
return invoke('create_request', { workspaceId, name: '', ...patch });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user