mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Lazy load routes
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import { createBrowserRouter, RouterProvider } from "react-router-dom";
|
import { lazy, Suspense } from 'react';
|
||||||
import { Workspaces } from '../pages/Workspaces';
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
||||||
import { Workspace } from '../pages/Workspace';
|
|
||||||
import { RouteError } from "./RouteError";
|
const Workspaces = lazy(() => import('../pages/Workspaces'));
|
||||||
|
const Workspace = lazy(() => import('../pages/Workspace'));
|
||||||
|
const RouteError = lazy(() => import('./RouteError'));
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@@ -26,6 +28,8 @@ const router = createBrowserRouter([
|
|||||||
|
|
||||||
export function AppRouter() {
|
export function AppRouter() {
|
||||||
return (
|
return (
|
||||||
<RouterProvider router={router} />
|
<Suspense>
|
||||||
|
<RouterProvider router={router} />
|
||||||
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,8 +109,10 @@ export const baseExtensions = [
|
|||||||
drawSelection(),
|
drawSelection(),
|
||||||
dropCursor(),
|
dropCursor(),
|
||||||
bracketMatching(),
|
bracketMatching(),
|
||||||
debouncedAutocompletionDisplay({ millis: 1000 }),
|
// TODO: Figure out how to debounce showing of autocomplete in a good way
|
||||||
autocompletion({ closeOnBlur: true, interactionDelay: 200, activateOnTyping: false }),
|
// debouncedAutocompletionDisplay({ millis: 1000 }),
|
||||||
|
// autocompletion({ closeOnBlur: true, interactionDelay: 200, activateOnTyping: false }),
|
||||||
|
autocompletion({ closeOnBlur: true, interactionDelay: 300 }),
|
||||||
syntaxHighlighting(myHighlightStyle),
|
syntaxHighlighting(myHighlightStyle),
|
||||||
EditorState.allowMultipleSelections.of(true),
|
EditorState.allowMultipleSelections.of(true),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useRequestUpdate } from '../hooks/useRequest';
|
import { useRequestUpdate } from '../hooks/useRequest';
|
||||||
import type { HttpHeader, HttpRequest } from '../lib/models';
|
import type { HttpHeader, HttpRequest } from '../lib/models';
|
||||||
import { IconButton } from './IconButton';
|
import { IconButton } from './IconButton';
|
||||||
@@ -13,13 +13,10 @@ type PairWithId = { header: Partial<HttpHeader>; id: string };
|
|||||||
|
|
||||||
export function HeaderEditor({ request }: Props) {
|
export function HeaderEditor({ request }: Props) {
|
||||||
const updateRequest = useRequestUpdate(request);
|
const updateRequest = useRequestUpdate(request);
|
||||||
const saveHeaders = useCallback(
|
const saveHeaders = (pairs: PairWithId[]) => {
|
||||||
(pairs: PairWithId[]) => {
|
const headers = pairs.map((p) => ({ name: '', value: '', ...p.header }));
|
||||||
const headers = pairs.map((p) => ({ name: '', value: '', ...p.header }));
|
updateRequest.mutate({ headers });
|
||||||
updateRequest.mutate({ headers });
|
};
|
||||||
},
|
|
||||||
[updateRequest],
|
|
||||||
);
|
|
||||||
|
|
||||||
const newPair = () => {
|
const newPair = () => {
|
||||||
return { header: { name: '', value: '' }, id: Math.random().toString() };
|
return { header: { name: '', value: '' }, id: Math.random().toString() };
|
||||||
@@ -29,16 +26,13 @@ export function HeaderEditor({ request }: Props) {
|
|||||||
request.headers.map((h) => ({ header: h, id: Math.random().toString() })),
|
request.headers.map((h) => ({ header: h, id: Math.random().toString() })),
|
||||||
);
|
);
|
||||||
|
|
||||||
const setPairsAndSave = useCallback(
|
const setPairsAndSave = (fn: (pairs: PairWithId[]) => PairWithId[]) => {
|
||||||
(fn: (pairs: PairWithId[]) => PairWithId[]) => {
|
setPairs((oldPairs) => {
|
||||||
setPairs((oldPairs) => {
|
const newPairs = fn(oldPairs);
|
||||||
const newPairs = fn(oldPairs);
|
saveHeaders(newPairs);
|
||||||
saveHeaders(newPairs);
|
return newPairs;
|
||||||
return newPairs;
|
});
|
||||||
});
|
};
|
||||||
},
|
|
||||||
[saveHeaders],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleChangeHeader = (pair: PairWithId) => {
|
const handleChangeHeader = (pair: PairWithId) => {
|
||||||
setPairsAndSave((pairs) =>
|
setPairsAndSave((pairs) =>
|
||||||
@@ -58,7 +52,7 @@ export function HeaderEditor({ request }: Props) {
|
|||||||
if (lastPair.header.name !== '' || lastPair.header.value !== '') {
|
if (lastPair.header.name !== '' || lastPair.header.value !== '') {
|
||||||
setPairsAndSave((pairs) => [...pairs, newPair()]);
|
setPairsAndSave((pairs) => [...pairs, newPair()]);
|
||||||
}
|
}
|
||||||
}, [pairs, setPairsAndSave]);
|
}, [pairs]);
|
||||||
|
|
||||||
const handleDelete = (pair: PairWithId) => {
|
const handleDelete = (pair: PairWithId) => {
|
||||||
setPairsAndSave((oldPairs) => oldPairs.filter((p) => p.id !== pair.id));
|
setPairsAndSave((oldPairs) => oldPairs.filter((p) => p.id !== pair.id));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ButtonLink } from './ButtonLink';
|
|||||||
import { Heading } from './Heading';
|
import { Heading } from './Heading';
|
||||||
import { VStack } from './Stacks';
|
import { VStack } from './Stacks';
|
||||||
|
|
||||||
export function RouteError() {
|
export default function RouteError() {
|
||||||
const error = useRouteError();
|
const error = useRouteError();
|
||||||
const stringified = JSON.stringify(error);
|
const stringified = JSON.stringify(error);
|
||||||
const message = (error as any).message ?? stringified;
|
const message = (error as any).message ?? stringified;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type Params = {
|
|||||||
requestId?: string;
|
requestId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Workspace() {
|
export default function Workspace() {
|
||||||
const params = useParams<Params>();
|
const params = useParams<Params>();
|
||||||
const workspaceId = params?.workspaceId ?? '';
|
const workspaceId = params?.workspaceId ?? '';
|
||||||
const { data: requests } = useRequests(workspaceId);
|
const { data: requests } = useRequests(workspaceId);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Heading } from '../components/Heading';
|
|||||||
import { VStack } from '../components/Stacks';
|
import { VStack } from '../components/Stacks';
|
||||||
import { useWorkspaces } from '../hooks/useWorkspaces';
|
import { useWorkspaces } from '../hooks/useWorkspaces';
|
||||||
|
|
||||||
export function Workspaces() {
|
export default function Workspaces() {
|
||||||
const workspaces = useWorkspaces();
|
const workspaces = useWorkspaces();
|
||||||
return (
|
return (
|
||||||
<VStack as="ul" className="p-12">
|
<VStack as="ul" className="p-12">
|
||||||
|
|||||||
Reference in New Issue
Block a user