import { createEffect, createSignal, Match, mergeProps, onCleanup, Switch, } from "solid-js"; import DevicesListView from "./devices-list-view"; import IntegrationListView from "./integration-list-view"; import UrlUtils from "../../tools/url-utils"; import IntegrationView from "./integration-view"; function DevicesView(props) { props = mergeProps({ onIntegrationClicked: () => {} }, props); const DEVICES_LIST_VIEW = "devices"; const INTEGRATION_LIST_VIEW = "integrations"; const INTEGRATION_VIEW = "integration"; const VIEWS = [DEVICES_LIST_VIEW, INTEGRATION_LIST_VIEW, INTEGRATION_VIEW]; const [currentView, setCurrentView] = createSignal(INTEGRATION_LIST_VIEW); createEffect(() => { let url = UrlUtils.getUrl(); url = UrlUtils.addQueryParameter(url, "tab", currentView()); UrlUtils.setUrl(url); }); onCleanup(() => { window.removeEventListener("popstate", setViewFromUrl); }); setViewFromUrl(); window.addEventListener("popstate", setViewFromUrl); function setViewFromUrl() { let view = UrlUtils.getQueryParameter("tab"); if (!view) return; if (!VIEWS.includes(view)) return; setCurrentView(view); } function handleIntegrationClicked(integration) { IntegrationView.setIntegration(integration); setCurrentView(INTEGRATION_VIEW); } function Navigation() { return (
); } return (
} onIntegrationClicked={handleIntegrationClicked} /> } />
); } export default DevicesView;