mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:38:26 +02:00
Fix active cookie jar and improve routing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { lazy } from 'react';
|
import { lazy } from 'react';
|
||||||
import { createBrowserRouter, Navigate, RouterProvider, useParams } from 'react-router-dom';
|
import { createBrowserRouter, Navigate, RouterProvider, useParams } from 'react-router-dom';
|
||||||
import { routePaths, useAppRoutes } from '../hooks/useAppRoutes';
|
import { paths, useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
import { DefaultLayout } from './DefaultLayout';
|
import { DefaultLayout } from './DefaultLayout';
|
||||||
import { RedirectToLatestWorkspace } from './RedirectToLatestWorkspace';
|
import { RedirectToLatestWorkspace } from './RedirectToLatestWorkspace';
|
||||||
import RouteError from './RouteError';
|
import RouteError from './RouteError';
|
||||||
@@ -19,19 +19,23 @@ const router = createBrowserRouter([
|
|||||||
element: <RedirectToLatestWorkspace />,
|
element: <RedirectToLatestWorkspace />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: routePaths.workspaces(),
|
path: paths.workspaces(),
|
||||||
element: <RedirectToLatestWorkspace />,
|
element: <RedirectToLatestWorkspace />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: routePaths.workspace({
|
path: paths.workspace({
|
||||||
workspaceId: ':workspaceId',
|
workspaceId: ':workspaceId',
|
||||||
|
environmentId: null,
|
||||||
|
cookieJarId: null,
|
||||||
}),
|
}),
|
||||||
element: <LazyWorkspace />,
|
element: <LazyWorkspace />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: routePaths.request({
|
path: paths.request({
|
||||||
workspaceId: ':workspaceId',
|
workspaceId: ':workspaceId',
|
||||||
requestId: ':requestId',
|
requestId: ':requestId',
|
||||||
|
environmentId: null,
|
||||||
|
cookieJarId: null,
|
||||||
}),
|
}),
|
||||||
element: <LazyWorkspace />,
|
element: <LazyWorkspace />,
|
||||||
},
|
},
|
||||||
@@ -40,8 +44,10 @@ const router = createBrowserRouter([
|
|||||||
element: <RedirectLegacyEnvironmentURLs />,
|
element: <RedirectLegacyEnvironmentURLs />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: routePaths.workspaceSettings({
|
path: paths.workspaceSettings({
|
||||||
workspaceId: ':workspaceId',
|
workspaceId: ':workspaceId',
|
||||||
|
environmentId: null,
|
||||||
|
cookieJarId: null,
|
||||||
}),
|
}),
|
||||||
element: <LazySettings />,
|
element: <LazySettings />,
|
||||||
},
|
},
|
||||||
@@ -64,13 +70,13 @@ function RedirectLegacyEnvironmentURLs() {
|
|||||||
workspaceId?: string;
|
workspaceId?: string;
|
||||||
environmentId?: string;
|
environmentId?: string;
|
||||||
}>();
|
}>();
|
||||||
const environmentId = rawEnvironmentId === '__default__' ? undefined : rawEnvironmentId;
|
const environmentId = (rawEnvironmentId === '__default__' ? undefined : rawEnvironmentId) ?? null;
|
||||||
|
|
||||||
let to;
|
let to;
|
||||||
if (workspaceId != null && requestId != null) {
|
if (workspaceId != null && requestId != null) {
|
||||||
to = routes.paths.request({ workspaceId, environmentId, requestId });
|
to = routes.paths.request({ workspaceId, environmentId, requestId, cookieJarId: null });
|
||||||
} else if (workspaceId != null) {
|
} else if (workspaceId != null) {
|
||||||
to = routes.paths.workspace({ workspaceId, environmentId });
|
to = routes.paths.workspace({ workspaceId, environmentId, cookieJarId: null });
|
||||||
} else {
|
} else {
|
||||||
to = routes.paths.workspaces();
|
to = routes.paths.workspaces();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,7 +271,8 @@ export function CommandPalette({ onClose }: { onClose: () => void }) {
|
|||||||
return routes.navigate('request', {
|
return routes.navigate('request', {
|
||||||
workspaceId: r.workspaceId,
|
workspaceId: r.workspaceId,
|
||||||
requestId: r.id,
|
requestId: r.id,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -313,7 +314,8 @@ export function CommandPalette({ onClose }: { onClose: () => void }) {
|
|||||||
workspaceCommands,
|
workspaceCommands,
|
||||||
sortedRequests,
|
sortedRequests,
|
||||||
routes,
|
routes,
|
||||||
activeEnvironment,
|
activeEnvironment?.id,
|
||||||
|
activeCookieJar?.id,
|
||||||
sortedEnvironments,
|
sortedEnvironments,
|
||||||
setActiveEnvironmentId,
|
setActiveEnvironmentId,
|
||||||
sortedWorkspaces,
|
sortedWorkspaces,
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ export function MoveToWorkspaceDialog({ onDone, request, activeWorkspaceId }: Pr
|
|||||||
className="mr-auto min-w-[5rem]"
|
className="mr-auto min-w-[5rem]"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toast.hide('workspace-moved');
|
toast.hide('workspace-moved');
|
||||||
routes.navigate('workspace', { workspaceId: selectedWorkspaceId });
|
routes.navigate('workspace', {
|
||||||
|
workspaceId: selectedWorkspaceId,
|
||||||
|
cookieJarId: null,
|
||||||
|
environmentId: null,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Switch to Workspace
|
Switch to Workspace
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useKeyPressEvent } from 'react-use';
|
import { useKeyPressEvent } from 'react-use';
|
||||||
|
import { useActiveCookieJar } from '../hooks/useActiveCookieJar';
|
||||||
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
||||||
@@ -20,6 +21,7 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
|
|||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
const activeWorkspace = useActiveWorkspace();
|
const activeWorkspace = useActiveWorkspace();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
const allRecentRequestIds = useRecentRequests();
|
const allRecentRequestIds = useRecentRequests();
|
||||||
const recentRequestIds = useMemo(() => allRecentRequestIds.slice(1), [allRecentRequestIds]);
|
const recentRequestIds = useMemo(() => allRecentRequestIds.slice(1), [allRecentRequestIds]);
|
||||||
@@ -57,8 +59,9 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
|
|||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
environmentId: activeEnvironment?.id,
|
|
||||||
workspaceId: activeWorkspace.id,
|
workspaceId: activeWorkspace.id,
|
||||||
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -76,7 +79,7 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
return recentRequestItems.slice(0, 20);
|
return recentRequestItems.slice(0, 20);
|
||||||
}, [activeWorkspace, activeEnvironment?.id, recentRequestIds, requests, routes]);
|
}, [activeWorkspace, recentRequestIds, requests, routes, activeEnvironment?.id, activeCookieJar?.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown ref={dropdownRef} items={items}>
|
<Dropdown ref={dropdownRef} items={items}>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
|
import { getRecentCookieJars } from '../hooks/useRecentCookieJars';
|
||||||
import { getRecentEnvironments } from '../hooks/useRecentEnvironments';
|
import { getRecentEnvironments } from '../hooks/useRecentEnvironments';
|
||||||
import { getRecentRequests } from '../hooks/useRecentRequests';
|
import { getRecentRequests } from '../hooks/useRecentRequests';
|
||||||
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||||
@@ -20,13 +21,14 @@ export function RedirectToLatestWorkspace() {
|
|||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
const workspaceId = recentWorkspaces[0] ?? workspaces[0]?.id ?? 'n/a';
|
const workspaceId = recentWorkspaces[0] ?? workspaces[0]?.id ?? 'n/a';
|
||||||
const environmentId = (await getRecentEnvironments(workspaceId))[0];
|
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? null;
|
||||||
const requestId = (await getRecentRequests(workspaceId))[0];
|
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? null;
|
||||||
|
const requestId = (await getRecentRequests(workspaceId))[0] ?? null;
|
||||||
|
|
||||||
if (workspaceId != null && requestId != null) {
|
if (workspaceId != null && requestId != null) {
|
||||||
navigate(routes.paths.request({ workspaceId, environmentId, requestId }));
|
navigate(routes.paths.request({ workspaceId, environmentId, requestId, cookieJarId }));
|
||||||
} else {
|
} else {
|
||||||
navigate(routes.paths.workspace({ workspaceId, environmentId }));
|
navigate(routes.paths.workspace({ workspaceId, environmentId, cookieJarId }));
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [navigate, recentWorkspaces, routes.paths, workspaces, workspaces.length]);
|
}, [navigate, recentWorkspaces, routes.paths, workspaces, workspaces.length]);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
|
|||||||
import type { XYCoord } from 'react-dnd';
|
import type { XYCoord } from 'react-dnd';
|
||||||
import { useDrag, useDrop } from 'react-dnd';
|
import { useDrag, useDrop } from 'react-dnd';
|
||||||
import { useKey, useKeyPressEvent } from 'react-use';
|
import { useKey, useKeyPressEvent } from 'react-use';
|
||||||
|
import { useActiveCookieJar } from '../hooks/useActiveCookieJar';
|
||||||
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
||||||
|
|
||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
@@ -73,6 +74,7 @@ export function Sidebar({ className }: Props) {
|
|||||||
const sidebarRef = useRef<HTMLLIElement>(null);
|
const sidebarRef = useRef<HTMLLIElement>(null);
|
||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const folders = useFolders();
|
const folders = useFolders();
|
||||||
const requests = useRequests();
|
const requests = useRequests();
|
||||||
const activeWorkspace = useActiveWorkspace();
|
const activeWorkspace = useActiveWorkspace();
|
||||||
@@ -221,14 +223,22 @@ export function Sidebar({ className }: Props) {
|
|||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
requestId: id,
|
requestId: id,
|
||||||
workspaceId: item.workspaceId,
|
workspaceId: item.workspaceId,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
setSelectedId(id);
|
setSelectedId(id);
|
||||||
setSelectedTree(tree);
|
setSelectedTree(tree);
|
||||||
if (!opts.noFocus) focusActiveRequest({ forced: { id, tree } });
|
if (!opts.noFocus) focusActiveRequest({ forced: { id, tree } });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[treeParentMap, collapsed, routes, activeEnvironment, focusActiveRequest],
|
[
|
||||||
|
treeParentMap,
|
||||||
|
collapsed,
|
||||||
|
routes,
|
||||||
|
activeEnvironment?.id,
|
||||||
|
activeCookieJar?.id,
|
||||||
|
focusActiveRequest,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleClearSelected = useCallback(() => {
|
const handleClearSelected = useCallback(() => {
|
||||||
@@ -273,8 +283,9 @@ export function Sidebar({ className }: Props) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
requestId: selected.id,
|
requestId: selected.id,
|
||||||
workspaceId: activeWorkspace?.id,
|
workspaceId: activeWorkspace?.id ?? null,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -747,8 +758,8 @@ function SidebarItem({
|
|||||||
}, [setEditing, itemModel]);
|
}, [setEditing, itemModel]);
|
||||||
|
|
||||||
const handleBlur = useCallback(
|
const handleBlur = useCallback(
|
||||||
(e: React.FocusEvent<HTMLInputElement>) => {
|
async (e: React.FocusEvent<HTMLInputElement>) => {
|
||||||
handleSubmitNameEdit(e.currentTarget);
|
await handleSubmitNameEdit(e.currentTarget);
|
||||||
},
|
},
|
||||||
[handleSubmitNameEdit],
|
[handleSubmitNameEdit],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export function useActiveCookieJar() {
|
|||||||
export function useEnsureActiveCookieJar() {
|
export function useEnsureActiveCookieJar() {
|
||||||
const cookieJars = useCookieJars();
|
const cookieJars = useCookieJars();
|
||||||
const [activeCookieJarId, setActiveCookieJarId] = useActiveCookieJarId();
|
const [activeCookieJarId, setActiveCookieJarId] = useActiveCookieJarId();
|
||||||
|
|
||||||
|
// Set the active cookie jar to the first one, if none set
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cookieJars == null) return; // Hasn't loaded yet
|
if (cookieJars == null) return; // Hasn't loaded yet
|
||||||
if (cookieJars.find((j) => j.id === activeCookieJarId)) {
|
if (cookieJars.find((j) => j.id === activeCookieJarId)) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import type { RouteParamsRequest } from './useAppRoutes';
|
|
||||||
|
|
||||||
export function useActiveRequestId(): string | null {
|
export function useActiveRequestId(): string | null {
|
||||||
const { requestId } = useParams<RouteParamsRequest>();
|
const { requestId } = useParams();
|
||||||
return requestId ?? null;
|
return requestId ?? null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { Workspace } from '@yaakapp-internal/models';
|
import type { Workspace } from '@yaakapp-internal/models';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import type { RouteParamsWorkspace } from './useAppRoutes';
|
|
||||||
import { useWorkspaces } from './useWorkspaces';
|
import { useWorkspaces } from './useWorkspaces';
|
||||||
|
|
||||||
export function useActiveWorkspace(): Workspace | null {
|
export function useActiveWorkspace(): Workspace | null {
|
||||||
@@ -15,6 +14,6 @@ export function useActiveWorkspace(): Workspace | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useActiveWorkspaceId(): string | null {
|
function useActiveWorkspaceId(): string | null {
|
||||||
const { workspaceId } = useParams<RouteParamsWorkspace>();
|
const { workspaceId } = useParams();
|
||||||
return workspaceId ?? null;
|
return workspaceId ?? null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
import type { Environment } from '@yaakapp-internal/models';
|
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { QUERY_COOKIE_JAR_ID } from './useActiveCookieJar';
|
import { QUERY_COOKIE_JAR_ID } from './useActiveCookieJar';
|
||||||
import { QUERY_ENVIRONMENT_ID } from './useActiveEnvironment';
|
import { QUERY_ENVIRONMENT_ID } from './useActiveEnvironment';
|
||||||
import { useActiveRequestId } from './useActiveRequestId';
|
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
|
||||||
|
|
||||||
export type RouteParamsWorkspace = {
|
export type RouteParamsWorkspace = {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
environmentId?: string;
|
environmentId: string | null;
|
||||||
cookieJarId?: string;
|
cookieJarId: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RouteParamsRequest = RouteParamsWorkspace & {
|
export type RouteParamsRequest = RouteParamsWorkspace & {
|
||||||
requestId: string;
|
requestId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const routePaths = {
|
export const paths = {
|
||||||
workspaces() {
|
workspaces() {
|
||||||
return '/workspaces';
|
return '/workspaces';
|
||||||
},
|
},
|
||||||
@@ -52,44 +49,21 @@ export const routePaths = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function useAppRoutes() {
|
export function useAppRoutes() {
|
||||||
const activeWorkspace = useActiveWorkspace();
|
|
||||||
const requestId = useActiveRequestId();
|
|
||||||
const nav = useNavigate();
|
const nav = useNavigate();
|
||||||
|
|
||||||
const navigate = useCallback(
|
const navigate = useCallback(
|
||||||
<T extends keyof typeof routePaths>(path: T, ...params: Parameters<(typeof routePaths)[T]>) => {
|
<T extends keyof typeof paths>(path: T, ...params: Parameters<(typeof paths)[T]>) => {
|
||||||
// Not sure how to make TS work here, but it's good from the
|
// Not sure how to make TS work here, but it's good from the
|
||||||
// outside caller perspective.
|
// outside caller perspective.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const resolvedPath = routePaths[path](...(params as any));
|
const resolvedPath = paths[path](...(params as any));
|
||||||
nav(resolvedPath);
|
nav(resolvedPath);
|
||||||
},
|
},
|
||||||
[nav],
|
[nav],
|
||||||
);
|
);
|
||||||
|
|
||||||
const setEnvironment = useCallback(
|
|
||||||
(environment: Environment | null) => {
|
|
||||||
if (activeWorkspace == null) {
|
|
||||||
navigate('workspaces');
|
|
||||||
} else if (requestId == null) {
|
|
||||||
navigate('workspace', {
|
|
||||||
workspaceId: activeWorkspace.id,
|
|
||||||
environmentId: environment == null ? undefined : environment.id,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
navigate('request', {
|
|
||||||
workspaceId: activeWorkspace.id,
|
|
||||||
environmentId: environment == null ? undefined : environment.id,
|
|
||||||
requestId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[navigate, activeWorkspace, requestId],
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paths: routePaths,
|
paths,
|
||||||
navigate,
|
navigate,
|
||||||
setEnvironment,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { GrpcRequest } from '@yaakapp-internal/models';
|
|||||||
import {useSetAtom} from "jotai";
|
import {useSetAtom} from "jotai";
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import { invokeCmd } from '../lib/tauri';
|
import { invokeCmd } from '../lib/tauri';
|
||||||
|
import {useActiveCookieJar} from "./useActiveCookieJar";
|
||||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||||
import { useActiveRequest } from './useActiveRequest';
|
import { useActiveRequest } from './useActiveRequest';
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
@@ -13,6 +14,7 @@ import {updateModelList} from "./useSyncModelStores";
|
|||||||
export function useCreateGrpcRequest() {
|
export function useCreateGrpcRequest() {
|
||||||
const workspace = useActiveWorkspace();
|
const workspace = useActiveWorkspace();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
||||||
@@ -51,7 +53,8 @@ export function useCreateGrpcRequest() {
|
|||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
workspaceId: request.workspaceId,
|
workspaceId: request.workspaceId,
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { HttpRequest } from '@yaakapp-internal/models';
|
|||||||
import { useSetAtom } from 'jotai/index';
|
import { useSetAtom } from 'jotai/index';
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import { invokeCmd } from '../lib/tauri';
|
import { invokeCmd } from '../lib/tauri';
|
||||||
|
import { useActiveCookieJar } from './useActiveCookieJar';
|
||||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||||
import { useActiveRequest } from './useActiveRequest';
|
import { useActiveRequest } from './useActiveRequest';
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
@@ -13,6 +14,7 @@ import { updateModelList } from './useSyncModelStores';
|
|||||||
export function useCreateHttpRequest() {
|
export function useCreateHttpRequest() {
|
||||||
const workspace = useActiveWorkspace();
|
const workspace = useActiveWorkspace();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||||
@@ -25,7 +27,7 @@ export function useCreateHttpRequest() {
|
|||||||
}
|
}
|
||||||
if (patch.sortPriority === undefined) {
|
if (patch.sortPriority === undefined) {
|
||||||
if (activeRequest != null) {
|
if (activeRequest != null) {
|
||||||
// Place above currently-active request
|
// Place above currently active request
|
||||||
patch.sortPriority = activeRequest.sortPriority - 0.0001;
|
patch.sortPriority = activeRequest.sortPriority - 0.0001;
|
||||||
} else {
|
} else {
|
||||||
// Place at the very top
|
// Place at the very top
|
||||||
@@ -45,7 +47,8 @@ export function useCreateHttpRequest() {
|
|||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
workspaceId: request.workspaceId,
|
workspaceId: request.workspaceId,
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useSetAtom } from 'jotai/index';
|
|||||||
import { invokeCmd } from '../lib/tauri';
|
import { invokeCmd } from '../lib/tauri';
|
||||||
import { useAppRoutes } from './useAppRoutes';
|
import { useAppRoutes } from './useAppRoutes';
|
||||||
import { usePrompt } from './usePrompt';
|
import { usePrompt } from './usePrompt';
|
||||||
import {updateModelList} from "./useSyncModelStores";
|
import { updateModelList } from './useSyncModelStores';
|
||||||
import { workspacesAtom } from './useWorkspaces';
|
import { workspacesAtom } from './useWorkspaces';
|
||||||
|
|
||||||
export function useCreateWorkspace() {
|
export function useCreateWorkspace() {
|
||||||
@@ -34,7 +34,11 @@ export function useCreateWorkspace() {
|
|||||||
// Optimistic update
|
// Optimistic update
|
||||||
setWorkspaces(updateModelList(workspace));
|
setWorkspaces(updateModelList(workspace));
|
||||||
|
|
||||||
routes.navigate('workspace', { workspaceId: workspace.id });
|
routes.navigate('workspace', {
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
environmentId: null,
|
||||||
|
cookieJarId: null,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useMutation } from '@tanstack/react-query';
|
|||||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import { invokeCmd } from '../lib/tauri';
|
import { invokeCmd } from '../lib/tauri';
|
||||||
|
import {useActiveCookieJar} from "./useActiveCookieJar";
|
||||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
import { useAppRoutes } from './useAppRoutes';
|
import { useAppRoutes } from './useAppRoutes';
|
||||||
@@ -16,6 +17,7 @@ export function useDuplicateGrpcRequest({
|
|||||||
}) {
|
}) {
|
||||||
const activeWorkspace = useActiveWorkspace();
|
const activeWorkspace = useActiveWorkspace();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
|
|
||||||
return useMutation<GrpcRequest, string>({
|
return useMutation<GrpcRequest, string>({
|
||||||
@@ -36,7 +38,8 @@ export function useDuplicateGrpcRequest({
|
|||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
workspaceId: activeWorkspace.id,
|
workspaceId: activeWorkspace.id,
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useMutation } from '@tanstack/react-query';
|
|||||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import { invokeCmd } from '../lib/tauri';
|
import { invokeCmd } from '../lib/tauri';
|
||||||
|
import {useActiveCookieJar} from "./useActiveCookieJar";
|
||||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
import { useAppRoutes } from './useAppRoutes';
|
import { useAppRoutes } from './useAppRoutes';
|
||||||
@@ -15,6 +16,7 @@ export function useDuplicateHttpRequest({
|
|||||||
}) {
|
}) {
|
||||||
const activeWorkspace = useActiveWorkspace();
|
const activeWorkspace = useActiveWorkspace();
|
||||||
const [activeEnvironment] = useActiveEnvironment();
|
const [activeEnvironment] = useActiveEnvironment();
|
||||||
|
const [activeCookieJar] = useActiveCookieJar();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
return useMutation<HttpRequest, string>({
|
return useMutation<HttpRequest, string>({
|
||||||
mutationKey: ['duplicate_http_request', id],
|
mutationKey: ['duplicate_http_request', id],
|
||||||
@@ -28,7 +30,8 @@ export function useDuplicateHttpRequest({
|
|||||||
routes.navigate('request', {
|
routes.navigate('request', {
|
||||||
workspaceId: activeWorkspace.id,
|
workspaceId: activeWorkspace.id,
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
environmentId: activeEnvironment?.id,
|
environmentId: activeEnvironment?.id ?? null,
|
||||||
|
cookieJarId: activeCookieJar?.id ?? null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ export function useImportData() {
|
|||||||
if (importedWorkspace != null) {
|
if (importedWorkspace != null) {
|
||||||
routes.navigate('workspace', {
|
routes.navigate('workspace', {
|
||||||
workspaceId: importedWorkspace.id,
|
workspaceId: importedWorkspace.id,
|
||||||
environmentId: imported.environments[0]?.id,
|
environmentId: imported.environments[0]?.id ?? null,
|
||||||
|
cookieJarId: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ export function useOpenSettings() {
|
|||||||
if (workspace == null) return;
|
if (workspace == null) return;
|
||||||
|
|
||||||
await invokeCmd('cmd_new_child_window', {
|
await invokeCmd('cmd_new_child_window', {
|
||||||
url: routes.paths.workspaceSettings({ workspaceId: workspace.id }),
|
url: routes.paths.workspaceSettings({
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
cookieJarId: null,
|
||||||
|
environmentId: null,
|
||||||
|
}),
|
||||||
label: 'settings',
|
label: 'settings',
|
||||||
title: 'Yaak Settings',
|
title: 'Yaak Settings',
|
||||||
innerSize: [600, 550],
|
innerSize: [600, 550],
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ export function useOpenWorkspace() {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
inNewWindow: boolean;
|
inNewWindow: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const environmentId = (await getRecentEnvironments(workspaceId))[0];
|
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? null;
|
||||||
const requestId = (await getRecentRequests(workspaceId))[0];
|
const requestId = (await getRecentRequests(workspaceId))[0] ?? null;
|
||||||
const cookieJarId = (await getRecentCookieJars(workspaceId))[0];
|
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? null;
|
||||||
const baseArgs = { workspaceId, environmentId, cookieJarId } as const;
|
const baseArgs = { workspaceId, environmentId, cookieJarId } as const;
|
||||||
if (inNewWindow) {
|
if (inNewWindow) {
|
||||||
const path =
|
const path =
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export function useTemplateFunctions() {
|
|||||||
// Fetch periodically until functions are returned
|
// Fetch periodically until functions are returned
|
||||||
// NOTE: visibilitychange (refetchOnWindowFocus) does not work on Windows, so we'll rely on this logic
|
// NOTE: visibilitychange (refetchOnWindowFocus) does not work on Windows, so we'll rely on this logic
|
||||||
// to refetch things until that's working again
|
// to refetch things until that's working again
|
||||||
|
// TODO: Update plugin system to wait for plugins to initialize before sending the first event to them
|
||||||
refetchInterval: numFns > 0 ? Infinity : 500,
|
refetchInterval: numFns > 0 ? Infinity : 500,
|
||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user