From e97cbb5d7f86d09ea8e473ed3c831ff24e8eb8f0 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 20 Nov 2021 18:02:00 +0100 Subject: [PATCH] Routing: add hasRoute and hasAnyRoute and make optional components views not render route if they don't exist --- .../views/auth/account/NamePanel.svelte | 5 ++++- .../views/auth/account/PasswordPanel.svelte | 7 +++++-- src/assets/views/auth/account/account.svelte | 7 ++++--- src/assets/views/auth/auth.svelte | 9 +++++++-- .../views/backend/accounts_approval.svelte | 10 +++++++--- src/assets/views/home.svelte | 8 +++++++- src/assets/views/layouts/BaseLayout.svelte | 20 ++++++++++--------- src/common/Routing.ts | 16 +++++++++++++++ 8 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/assets/views/auth/account/NamePanel.svelte b/src/assets/views/auth/account/NamePanel.svelte index 6948cf1..71c0c8b 100644 --- a/src/assets/views/auth/account/NamePanel.svelte +++ b/src/assets/views/auth/account/NamePanel.svelte @@ -3,16 +3,18 @@ import Message from "../../components/Message.svelte"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {hasRoute, route} from "../../../../common/Routing"; let newName = ''; +{#if hasRoute('change-name')}

Change name

{#if $locals.can_change_name} -
@@ -29,3 +31,4 @@ {/if}
+{/if} \ No newline at end of file diff --git a/src/assets/views/auth/account/PasswordPanel.svelte b/src/assets/views/auth/account/PasswordPanel.svelte index 2c0b75c..f25869b 100644 --- a/src/assets/views/auth/account/PasswordPanel.svelte +++ b/src/assets/views/auth/account/PasswordPanel.svelte @@ -2,21 +2,23 @@ import {locals} from "../../../ts/stores"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {hasRoute, route} from "../../../../common/Routing"; let removePasswordMode = false; +{#if hasRoute('remove-password', 'change-password')}

{$locals.has_password ? 'Change' : 'Set'} password

{#if removePasswordMode} - {:else} -
{#if $locals.has_password} @@ -28,3 +30,4 @@ {/if}
+{/if} diff --git a/src/assets/views/auth/account/account.svelte b/src/assets/views/auth/account/account.svelte index cb72f86..ad0035d 100644 --- a/src/assets/views/auth/account/account.svelte +++ b/src/assets/views/auth/account/account.svelte @@ -6,6 +6,7 @@ import PasswordPanel from "./PasswordPanel.svelte"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {route} from "../../../../common/Routing"; const mainEmail = $locals.main_email?.email; const personalInfoFields = $locals.user_personal_info_fields || []; @@ -68,13 +69,13 @@ Secondary {email.email} -
-
@@ -87,7 +88,7 @@ -

Add an email address:

diff --git a/src/assets/views/auth/auth.svelte b/src/assets/views/auth/auth.svelte index 3edc296..ad14119 100644 --- a/src/assets/views/auth/auth.svelte +++ b/src/assets/views/auth/auth.svelte @@ -4,6 +4,7 @@ import Form from "../utils/Form.svelte"; import Field from "../utils/Field.svelte"; import Icon from "../utils/Icon.svelte"; + import {hasRoute, route} from "../../../common/Routing"; let registerUsingMagicLink = $locals.previousFormData()?.['auth_method'] !== 'password'; let loginUsingMagicLink = true; @@ -22,10 +23,11 @@ h1="Authentication and registration">
+ {#if hasRoute('login')}

Log in

- + @@ -39,11 +41,13 @@
+ {/if} + {#if hasRoute('register')}

Register

-
+ {#if $locals.has_username} @@ -68,5 +72,6 @@
+ {/if}
diff --git a/src/assets/views/backend/accounts_approval.svelte b/src/assets/views/backend/accounts_approval.svelte index 982427b..9594dc9 100644 --- a/src/assets/views/backend/accounts_approval.svelte +++ b/src/assets/views/backend/accounts_approval.svelte @@ -5,7 +5,7 @@ import Form from "../utils/Form.svelte"; import Field from "../utils/Field.svelte"; import Breadcrumb from "../components/Breadcrumb.svelte"; - import {route} from "../../../common/Routing"; + import {hasRoute, route} from "../../../common/Routing"; const accounts = $locals.accounts || []; @@ -49,16 +49,20 @@
-
+ {/if} -
+ {/if}
diff --git a/src/assets/views/home.svelte b/src/assets/views/home.svelte index 64a1e35..b03826a 100644 --- a/src/assets/views/home.svelte +++ b/src/assets/views/home.svelte @@ -1,6 +1,6 @@ @@ -9,11 +9,17 @@

swaf - Svelte Web Application Framework

Welcome to {$locals.app.name}!

+ {#if hasAnyRoute('tests', 'design')} + {/if} diff --git a/src/assets/views/layouts/BaseLayout.svelte b/src/assets/views/layouts/BaseLayout.svelte index 59543ff..3c1d753 100644 --- a/src/assets/views/layouts/BaseLayout.svelte +++ b/src/assets/views/layouts/BaseLayout.svelte @@ -1,6 +1,6 @@