From 88b204f60ca40e741d6d6d72757227508be85d3e Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 16 Mar 2021 15:39:18 -0400 Subject: [PATCH] fix preferences not scrolling when already open, clarify routes Signed-off-by: Sebastian Malton --- .../components/+preferences/preferences.tsx | 11 +++++++---- src/renderer/protocol-handler/app-handlers.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/+preferences/preferences.tsx b/src/renderer/components/+preferences/preferences.tsx index 503e398f08..d17f1de8b4 100644 --- a/src/renderer/components/+preferences/preferences.tsx +++ b/src/renderer/components/+preferences/preferences.tsx @@ -1,7 +1,7 @@ import "./preferences.scss"; import React from "react"; -import { computed, observable } from "mobx"; +import { computed, observable, reaction } from "mobx"; import { observer } from "mobx-react"; import { userStore } from "../../../common/user-store"; @@ -31,9 +31,12 @@ export class Preferences extends React.Component { } componentDidMount() { - const { hash } = navigation.location; - - document.getElementById(hash.slice(1))?.scrollIntoView(); + reaction(() => navigation.location.hash, hash => { + document.getElementById(hash.slice(1))?.scrollIntoView(); + navigation.location.hash = ""; + }, { + fireImmediately: true + }); } render() { diff --git a/src/renderer/protocol-handler/app-handlers.ts b/src/renderer/protocol-handler/app-handlers.ts index d6b34181a9..256b8b396a 100644 --- a/src/renderer/protocol-handler/app-handlers.ts +++ b/src/renderer/protocol-handler/app-handlers.ts @@ -15,11 +15,19 @@ export function bindProtocolAddRouteHandlers() { .addInternalHandler("/preferences", ({ search: { highlight }}) => { navigate(preferencesURL({ fragment: highlight })); }) + .addInternalHandler("/", () => { + navigate(landingURL()); + }) .addInternalHandler("/landing", () => { navigate(landingURL()); }) - .addInternalHandler("/", () => { - navigate(landingURL()); + .addInternalHandler("/landing/:workspaceId", ({ pathname: { workspaceId } }) => { + if (workspaceStore.getById(workspaceId)) { + workspaceStore.setActive(workspaceId); + navigate(landingURL()); + } else { + console.log("[APP-HANDLER]: workspace with given ID does not exist", { workspaceId }); + } }) .addInternalHandler("/cluster", () => { navigate(addClusterURL()); @@ -30,6 +38,8 @@ export function bindProtocolAddRouteHandlers() { if (cluster) { workspaceStore.setActive(cluster.workspace); navigate(clusterViewURL({ params: { clusterId } })); + } else { + console.log("[APP-HANDLER]: cluster with given ID does not exist", { clusterId }); } }) .addInternalHandler("/cluster/:clusterId/settings", ({ pathname: { clusterId } }) => { @@ -38,6 +48,8 @@ export function bindProtocolAddRouteHandlers() { if (cluster) { workspaceStore.setActive(cluster.workspace); navigate(clusterSettingsURL({ params: { clusterId } })); + } else { + console.log("[APP-HANDLER]: cluster with given ID does not exist", { clusterId }); } }) .addInternalHandler("/extensions", () => {