From 64c48d0ee4cf4a1a82ca417d5e06a2f00ce681ec Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 26 Oct 2021 15:11:14 +0200 Subject: [PATCH] allow opening a template directly from a URL --- .../pages/builder/portal/apps/index.svelte | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index a0b75a3a2e..8a3b6c41b1 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -18,7 +18,7 @@ import { onMount } from "svelte" import { apps, auth, admin } from "stores/portal" import download from "downloadjs" - import { goto } from "@roxi/routify" + import { goto, params } from "@roxi/routify" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import AppCard from "components/start/AppCard.svelte" import AppRow from "components/start/AppRow.svelte" @@ -184,9 +184,27 @@ } } + function createAppFromTemplateUrl(templateKey) { + // validate the template key just to make sure + const templateParts = templateKey.split("/") + if (templateParts.length === 2 && templateParts[0] === "app") { + template = { + key: templateKey, + } + initiateAppCreation() + } else { + notifications.error("Your Template URL is invalid. Please try another.") + } + } + onMount(async () => { await apps.load() loaded = true + + // if the portal is loaded from an external URL + const templateKey = $params["?template"] + if (!templateKey) return + createAppFromTemplateUrl(templateKey) })