mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 10:18:31 +02:00
Only sync models from active workspace
This commit is contained in:
@@ -1,10 +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 { routePaths, useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
import { useGenerateThemeCss } from '../hooks/useGenerateThemeCss';
|
|
||||||
import { useSyncFontSizeSetting } from '../hooks/useSyncFontSizeSetting';
|
|
||||||
import { useSyncModelStores } from '../hooks/useSyncModelStores';
|
|
||||||
import { useSyncZoomSetting } from '../hooks/useSyncZoomSetting';
|
|
||||||
import { DefaultLayout } from './DefaultLayout';
|
import { DefaultLayout } from './DefaultLayout';
|
||||||
import { RedirectToLatestWorkspace } from './RedirectToLatestWorkspace';
|
import { RedirectToLatestWorkspace } from './RedirectToLatestWorkspace';
|
||||||
import RouteError from './RouteError';
|
import RouteError from './RouteError';
|
||||||
@@ -54,12 +50,6 @@ const router = createBrowserRouter([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export function AppRouter() {
|
export function AppRouter() {
|
||||||
// Add some global hooks that should remain persistent
|
|
||||||
useSyncModelStores();
|
|
||||||
useSyncZoomSetting();
|
|
||||||
useSyncFontSizeSetting();
|
|
||||||
useGenerateThemeCss();
|
|
||||||
|
|
||||||
return <RouterProvider router={router} />;
|
return <RouterProvider router={router} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { emit } from '@tauri-apps/api/event';
|
|||||||
import type { PromptTextRequest, PromptTextResponse } from '@yaakapp-internal/plugin';
|
import type { PromptTextRequest, PromptTextResponse } from '@yaakapp-internal/plugin';
|
||||||
import { useEnsureActiveCookieJar } from '../hooks/useActiveCookieJar';
|
import { useEnsureActiveCookieJar } from '../hooks/useActiveCookieJar';
|
||||||
import { useActiveWorkspaceChangedToast } from '../hooks/useActiveWorkspaceChangedToast';
|
import { useActiveWorkspaceChangedToast } from '../hooks/useActiveWorkspaceChangedToast';
|
||||||
|
import {useGenerateThemeCss} from "../hooks/useGenerateThemeCss";
|
||||||
import { useHotKey } from '../hooks/useHotKey';
|
import { useHotKey } from '../hooks/useHotKey';
|
||||||
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||||
import { useNotificationToast } from '../hooks/useNotificationToast';
|
import { useNotificationToast } from '../hooks/useNotificationToast';
|
||||||
@@ -10,10 +11,18 @@ import { useRecentCookieJars } from '../hooks/useRecentCookieJars';
|
|||||||
import { useRecentEnvironments } from '../hooks/useRecentEnvironments';
|
import { useRecentEnvironments } from '../hooks/useRecentEnvironments';
|
||||||
import { useRecentRequests } from '../hooks/useRecentRequests';
|
import { useRecentRequests } from '../hooks/useRecentRequests';
|
||||||
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||||
|
import {useSyncFontSizeSetting} from "../hooks/useSyncFontSizeSetting";
|
||||||
|
import {useSyncModelStores} from "../hooks/useSyncModelStores";
|
||||||
import { useSyncWorkspaceChildModels } from '../hooks/useSyncWorkspaceChildModels';
|
import { useSyncWorkspaceChildModels } from '../hooks/useSyncWorkspaceChildModels';
|
||||||
|
import {useSyncZoomSetting} from "../hooks/useSyncZoomSetting";
|
||||||
import { useToggleCommandPalette } from '../hooks/useToggleCommandPalette';
|
import { useToggleCommandPalette } from '../hooks/useToggleCommandPalette';
|
||||||
|
|
||||||
export function GlobalHooks() {
|
export function GlobalHooks() {
|
||||||
|
useSyncModelStores();
|
||||||
|
useSyncZoomSetting();
|
||||||
|
useSyncFontSizeSetting();
|
||||||
|
useGenerateThemeCss();
|
||||||
|
|
||||||
// Include here so they always update, even if no component references them
|
// Include here so they always update, even if no component references them
|
||||||
useRecentWorkspaces();
|
useRecentWorkspaces();
|
||||||
useRecentEnvironments();
|
useRecentEnvironments();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { AnyModel } from '@yaakapp-internal/models';
|
|||||||
import { useSetAtom } from 'jotai/index';
|
import { useSetAtom } from 'jotai/index';
|
||||||
import { extractKeyValue } from '../lib/keyValueStore';
|
import { extractKeyValue } from '../lib/keyValueStore';
|
||||||
import { modelsEq } from '../lib/model_util';
|
import { modelsEq } from '../lib/model_util';
|
||||||
|
import {useActiveWorkspace} from "./useActiveWorkspace";
|
||||||
import { cookieJarsAtom } from './useCookieJars';
|
import { cookieJarsAtom } from './useCookieJars';
|
||||||
import { environmentsAtom } from './useEnvironments';
|
import { environmentsAtom } from './useEnvironments';
|
||||||
import { foldersAtom } from './useFolders';
|
import { foldersAtom } from './useFolders';
|
||||||
@@ -25,6 +26,7 @@ export interface ModelPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useSyncModelStores() {
|
export function useSyncModelStores() {
|
||||||
|
const activeWorkspace = useActiveWorkspace();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
||||||
|
|
||||||
@@ -48,10 +50,17 @@ export function useSyncModelStores() {
|
|||||||
? keyValueQueryKey(model)
|
? keyValueQueryKey(model)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
// TODO: Move this logic to useRequestEditor() hook
|
||||||
if (model.model === 'http_request' && windowLabel !== getCurrentWebviewWindow().label) {
|
if (model.model === 'http_request' && windowLabel !== getCurrentWebviewWindow().label) {
|
||||||
wasUpdatedExternally(model.id);
|
wasUpdatedExternally(model.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only sync models that belong to this workspace, if a workspace ID is present
|
||||||
|
if ('workspaceId' in model && model.workspaceId !== activeWorkspace?.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark these models as DESC instead of ASC
|
||||||
const pushToFront = (['http_response', 'grpc_connection'] as AnyModel['model'][]).includes(
|
const pushToFront = (['http_response', 'grpc_connection'] as AnyModel['model'][]).includes(
|
||||||
model.model,
|
model.model,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user