Open same page when clicking on make changes on local machine

This commit is contained in:
Sebastian Martinez
2024-02-13 06:57:24 +00:00
committed by Rūdolfs Ošiņš
parent a602f5d255
commit 90de4d538c
5 changed files with 25 additions and 21 deletions
+3 -2
View File
@@ -1,8 +1,9 @@
<script>
import { api, httpdStore } from "@app/lib/httpd";
import Command from "./Command.svelte";
import { api, httpdStore } from "@app/lib/httpd";
import { routeToPath, activeUnloadedRouteStore } from "@app/lib/router";
$: path = window.location.href.replace(window.location.origin, "");
$: path = routeToPath($activeUnloadedRouteStore);
$: pathParam = path === "/" ? "" : `--path "${path}"`;
</script>
+6 -4
View File
@@ -16,10 +16,11 @@ import { nodePath } from "@app/views/nodes/router";
export { type Route };
const InitialStore = { resource: "booting" as const };
export const isLoading = writable<boolean>(true);
export const activeRouteStore = writable<LoadedRoute>({
resource: "booting",
});
export const activeRouteStore = writable<LoadedRoute>(InitialStore);
export const activeUnloadedRouteStore = writable<Route>(InitialStore);
let currentUrl: URL | undefined;
@@ -112,6 +113,7 @@ async function navigate(
setTitle(loadedRoute);
activeRouteStore.set(loadedRoute);
activeUnloadedRouteStore.set(newRoute);
isLoading.set(false);
}
@@ -189,7 +191,7 @@ function extractBaseUrl(hostAndPort: string): BaseUrl {
}
}
export function urlToRoute(url: URL): Route | null {
function urlToRoute(url: URL): Route | null {
const segments = url.pathname.substring(1).split("/");
const resource = segments.shift();
+2 -2
View File
@@ -4,7 +4,7 @@
import { queryProject } from "@app/lib/projects";
import { config } from "@app/lib/config";
import { formatPublicExplorer } from "@app/lib/utils";
import { routeToPath, urlToRoute } from "@app/lib/router";
import { activeUnloadedRouteStore, routeToPath } from "@app/lib/router";
import Clipboard from "@app/components/Clipboard.svelte";
import Command from "@app/components/Command.svelte";
@@ -17,7 +17,7 @@
let usedFallbackSeed = false;
const route = urlToRoute(new URL(window.location.href)) as ProjectRoute;
const route = $activeUnloadedRouteStore as ProjectRoute;
const seedRoutes = preferredSeeds.reduce<ProjectRoute[]>((acc, seed) => {
const [, address] = seed.split("@");
acc.push({
+12 -7
View File
@@ -1,6 +1,8 @@
<script lang="ts">
import type { BaseUrl } from "@httpd-client";
import type { Route } from "@app/lib/router/definitions";
import { activeUnloadedRouteStore } from "@app/lib/router";
import { api, httpdStore } from "@app/lib/httpd";
import { isLocal } from "@app/lib/utils";
@@ -16,6 +18,15 @@
export let localProject: "notFound" | "found" | undefined;
export let projectId: string;
export let popover: boolean = false;
let route: Route;
$: {
route = $activeUnloadedRouteStore;
if ("node" in route) {
route.node = api.baseUrl;
}
}
</script>
<style>
@@ -56,13 +67,7 @@
{#if !hideLocalButton}
<div style:padding-top="1rem">
<Link
disabled={disableLocalButton}
route={{
resource: "project.source",
node: api.baseUrl,
project: projectId,
}}>
<Link {route} disabled={disableLocalButton}>
<Button size="large" styleWidth="100%" disabled={disableLocalButton}>
<IconSmall name="device" />Make changes on your local node
</Button>
+2 -6
View File
@@ -35,14 +35,10 @@
},
});
}
const route = router.urlToRoute(
void router.navigateToUrl(
"push",
new URL(activeRoute.params.path || "", window.location.origin),
);
if (route) {
void router.push(route);
} else {
void router.push({ resource: "home" });
}
});
</script>