mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 15:21:23 +02: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 { useKey, useKeyPressEvent } from 'react-use';
|
||||||
|
|
||||||
import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
||||||
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useActiveRequestId } from '../hooks/useActiveRequestId';
|
import { useActiveRequestId } from '../hooks/useActiveRequestId';
|
||||||
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
@@ -527,8 +528,8 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
const updateAnyFolder = useUpdateAnyFolder();
|
const updateAnyFolder = useUpdateAnyFolder();
|
||||||
const prompt = usePrompt();
|
const prompt = usePrompt();
|
||||||
const [editing, setEditing] = useState<boolean>(false);
|
const [editing, setEditing] = useState<boolean>(false);
|
||||||
const activeRequestId = useActiveRequestId();
|
const activeRequest = useActiveRequest();
|
||||||
const isActive = activeRequestId === itemId;
|
const isActive = activeRequest?.id === itemId;
|
||||||
|
|
||||||
const handleSubmitNameEdit = useCallback(
|
const handleSubmitNameEdit = useCallback(
|
||||||
(el: HTMLInputElement) => {
|
(el: HTMLInputElement) => {
|
||||||
@@ -629,9 +630,8 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
{
|
{
|
||||||
key: 'createRequest',
|
key: 'createRequest',
|
||||||
label: 'New Request',
|
label: 'New Request',
|
||||||
hotkeyAction: 'request.create',
|
|
||||||
leftSlot: <Icon icon="plus" />,
|
leftSlot: <Icon icon="plus" />,
|
||||||
onSelect: () => createRequest.mutate({ folderId: itemId, sortPriority: -1 }),
|
onSelect: () => createRequest.mutate({ folderId: itemId }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'createFolder',
|
key: 'createFolder',
|
||||||
@@ -647,7 +647,7 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
hotkeyAction: 'request.duplicate',
|
hotkeyAction: 'request.duplicate',
|
||||||
leftSlot: <Icon icon="copy" />,
|
leftSlot: <Icon icon="copy" />,
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
if (activeRequestId === itemId) {
|
if (activeRequest?.id === itemId) {
|
||||||
duplicateRequest.mutate();
|
duplicateRequest.mutate();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,7 +24,15 @@ export function useCreateRequest() {
|
|||||||
if (workspaceId === null) {
|
if (workspaceId === null) {
|
||||||
throw new Error("Cannot create request when there's no active workspace");
|
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;
|
patch.folderId = patch.folderId || activeRequest?.folderId;
|
||||||
return invoke('create_request', { workspaceId, name: '', ...patch });
|
return invoke('create_request', { workspaceId, name: '', ...patch });
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user