Persist window paths

This commit is contained in:
Gregory Schier
2023-10-28 21:23:46 -07:00
parent e8b5e9de02
commit b2150181b3
5 changed files with 38 additions and 8 deletions

View File

@@ -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

View File

@@ -4,7 +4,7 @@ import { w } from '@tauri-apps/api/clipboard-79413165';
const openTag = '${[ ';
const closeTag = ' ]}';
export interface TwigCompletionOption {
interface TwigCompletionOption {
name: string;
}

View File

@@ -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;
}

View 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 });
});
}

View File

@@ -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 />