mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-11 17:46:41 -05:00
Persist window paths
This commit is contained in:
@@ -3,11 +3,11 @@ import { routePaths, useAppRoutes } from '../hooks/useAppRoutes';
|
||||
import { useRecentRequests } from '../hooks/useRecentRequests';
|
||||
import { useRequests } from '../hooks/useRequests';
|
||||
import { GlobalHooks } from './GlobalHooks';
|
||||
import RouteError from './RouteError';
|
||||
import Workspace from './Workspace';
|
||||
import Workspaces from './Workspaces';
|
||||
import { DialogProvider } from './DialogContext';
|
||||
import { useRecentEnvironments } from '../hooks/useRecentEnvironments';
|
||||
import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
||||
import RouteError from './RouteError';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
@@ -48,7 +48,7 @@ export function AppRouter() {
|
||||
|
||||
function WorkspaceOrRedirect() {
|
||||
const recentRequests = useRecentRequests();
|
||||
const recentEnvironments = useRecentEnvironments();
|
||||
const activeEnvironmentId = useActiveEnvironmentId();
|
||||
const requests = useRequests();
|
||||
const request = requests.find((r) => r.id === recentRequests[0]);
|
||||
const routes = useAppRoutes();
|
||||
@@ -57,8 +57,8 @@ function WorkspaceOrRedirect() {
|
||||
return <Workspace />;
|
||||
}
|
||||
|
||||
const environmentId = recentEnvironments[0];
|
||||
const { id: requestId, workspaceId } = request;
|
||||
const environmentId = activeEnvironmentId ?? undefined;
|
||||
|
||||
return (
|
||||
<Navigate
|
||||
|
||||
@@ -4,7 +4,7 @@ import { w } from '@tauri-apps/api/clipboard-79413165';
|
||||
const openTag = '${[ ';
|
||||
const closeTag = ' ]}';
|
||||
|
||||
export interface TwigCompletionOption {
|
||||
interface TwigCompletionOption {
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ class PlaceholderWidget extends WidgetType {
|
||||
}
|
||||
toDOM() {
|
||||
const elt = document.createElement('span');
|
||||
elt.className = `placeholder-widget ${!this.isExistingVariable ? 'placeholder-widget-error' : ''}`;
|
||||
elt.className = `placeholder-widget ${
|
||||
!this.isExistingVariable ? 'placeholder-widget-error' : ''
|
||||
}`;
|
||||
elt.textContent = this.name;
|
||||
return elt;
|
||||
}
|
||||
|
||||
21
src-web/lib/initPathnamePersistance.ts
Normal file
21
src-web/lib/initPathnamePersistance.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { NAMESPACE_NO_SYNC, getKeyValue, setKeyValue } from './keyValueStore';
|
||||
|
||||
const key = ['window_pathname', appWindow.label];
|
||||
const namespace = NAMESPACE_NO_SYNC;
|
||||
const fallback = undefined;
|
||||
|
||||
export async function initPathnamePersistance() {
|
||||
if (window.location.pathname === '/') {
|
||||
const pathname = await getKeyValue<string | undefined>({ key, namespace, fallback });
|
||||
if (pathname != null) {
|
||||
window.location.replace(pathname);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('pushstate', async () => {
|
||||
const { pathname: value } = window.location;
|
||||
await setKeyValue<string | undefined>({ key, namespace, value });
|
||||
});
|
||||
}
|
||||
@@ -4,10 +4,17 @@ import { App } from './components/App';
|
||||
import { getKeyValue } from './lib/keyValueStore';
|
||||
import { getPreferredAppearance, setAppearance } from './lib/theme/window';
|
||||
import './main.css';
|
||||
import { initPathnamePersistance } from './lib/initPathnamePersistance';
|
||||
|
||||
setAppearance(await getKeyValue({ key: 'appearance', fallback: getPreferredAppearance() }));
|
||||
await initPathnamePersistance();
|
||||
|
||||
setAppearance(
|
||||
await getKeyValue({
|
||||
key: 'appearance',
|
||||
fallback: getPreferredAppearance(),
|
||||
}),
|
||||
);
|
||||
|
||||
// root holds our app's root DOM Element:
|
||||
createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
|
||||
Reference in New Issue
Block a user