From fd422d6f89ea6828436d914473d08034e3039648 Mon Sep 17 00:00:00 2001 From: "kacaii.dev" Date: Sun, 10 May 2026 16:49:46 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20remove=20`session.guard`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/page/sidebar.gleam | 35 ++++++++++++++++++++--------------- src/client/session.gleam | 13 ------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/client/page/sidebar.gleam b/src/client/page/sidebar.gleam index 56e2aa6..27abdc9 100644 --- a/src/client/page/sidebar.gleam +++ b/src/client/page/sidebar.gleam @@ -11,22 +11,27 @@ pub fn view(session: session.Session) -> element.Element(Msg) { let data_sidebar = attr.data("sidebar", "") html.aside([data_sidebar, class("p-4 bg-primary text-primary-foreground")], [ - session.guard(session, { - let attr = [class("hover:cursor-pointer hstack")] + case session { + session.Authenticated(..) -> { + let attr = [class("hover:cursor-pointer hstack")] - html.section([], [ - // Dashboard - html.a([attr.href(route.path(route.Dashboard)), ..attr], [ - icon.layout_dashboard([]), - html.p([], [html.text("Dashboard")]), - ]), + html.section([], [ + // Dashboard + html.a([attr.href(route.path(route.Dashboard)), ..attr], [ + icon.layout_dashboard([]), + html.p([], [html.text("Dashboard")]), + ]), - // Calculator - html.a(attr, [ - icon.calculator([]), - html.p([], [html.text("Simulador")]), - ]), - ]) - }), + // Calculator + html.a(attr, [ + icon.calculator([]), + html.p([], [html.text("Simulador")]), + ]), + ]) + } + + // Not authenticated + _ -> element.none() + }, ]) } diff --git a/src/client/session.gleam b/src/client/session.gleam index c730ad4..3f36fb1 100644 --- a/src/client/session.gleam +++ b/src/client/session.gleam @@ -1,7 +1,6 @@ import client/route import client/session/token import gleam/dynamic/decode -import lustre/element pub type Session { ///  User is sucessfully authenticated and is allowed to @@ -34,15 +33,3 @@ pub fn decoder() -> decode.Decoder(Session) { _ -> decode.failure(Guest, "Session") } } - -///  Require User authentication in order to render an HTML element. -/// -/// ```gleam -/// guard(session, html.p([], [])) -/// ``` -pub fn guard(self: Session, element: element.Element(_)) -> element.Element(_) { - case self { - Authenticated(..) -> element - _ -> element.none() - } -} -- 2.51.2