From 6394a831dfe6724691af7b3494c6f293ac44c248 Mon Sep 17 00:00:00 2001 From: hreyes Date: Mon, 9 Feb 2026 11:51:28 -0600 Subject: [PATCH] feature/logo-nav --- .../components/sidebar/team-switcher.svelte | 108 ++++++++++++------ .../ui/sidebar/sidebar-trigger.svelte | 48 +++++++- 2 files changed, 115 insertions(+), 41 deletions(-) diff --git a/frontend/src/lib/components/sidebar/team-switcher.svelte b/frontend/src/lib/components/sidebar/team-switcher.svelte index 088b02df..0118331f 100644 --- a/frontend/src/lib/components/sidebar/team-switcher.svelte +++ b/frontend/src/lib/components/sidebar/team-switcher.svelte @@ -9,59 +9,91 @@ import { getBackendAssetUrl } from "$lib/utils"; const sidebar = useSidebar(); - + // Derivar la URL del logo usando el endpoint específico let activeCompanyLogoUrl = $derived( - companyStore.activeCompany?.logo - ? getBackendAssetUrl(`v1/a76/company/${companyStore.activeCompany.id}/logo/image?t=${new Date().getTime()}`) + companyStore.activeCompany?.logo + ? getBackendAssetUrl( + `v1/a76/company/${companyStore.activeCompany.id}/logo/image?t=${Date.now()}` + ) : null ); - + // Iniciales de la compañía activa (2 primeras letras) let activeCompanyInitials = $derived( - companyStore.activeCompany?.name?.slice(0, 2).toUpperCase() || 'CO' + companyStore.activeCompany?.name?.slice(0, 2).toUpperCase() || "CO" ); + // Fallback en degradé cuando no hay logo cargado + const fallbackBg = + "radial-gradient(circle at 30% 30%, rgba(0,0,0,0.08), rgba(0,0,0,0.12)), linear-gradient(135deg, rgba(99,102,241,0.12), rgba(14,165,233,0.18))"; + + const logoBg = $derived( + activeCompanyLogoUrl + ? `url(${activeCompanyLogoUrl})` + : fallbackBg + ); - - {#snippet child({ props })} - -
+ {#snippet child({ props })} + - {#if activeCompanyLogoUrl} - {companyStore.activeCompany?.name { (e.currentTarget as HTMLImageElement).style.display = 'none'; }} - /> - {:else} - {activeCompanyInitials} - {/if} -
-
- - {companyStore.activeCompany?.name || 'Seleccionar compañía'} - - {#if companyStore.activeCompany?.rfc} - - {companyStore.activeCompany.rfc} + + + + + +
+ {#if activeCompanyLogoUrl} + {companyStore.activeCompany?.name { + (e.currentTarget as HTMLImageElement).style.display = "none"; + }} + /> + {:else} + {activeCompanyInitials} + {/if} +
+
+ + {companyStore.activeCompany?.name || "Seleccionar compañía"} - {/if} -
- - - {/snippet} - + {#if companyStore.activeCompany?.rfc} + + {companyStore.activeCompany.rfc} + + {/if} +
+ + + + +
+ {/snippet} +
import { Button } from "$lib/components/ui/button/index.js"; - import { cn } from "$lib/utils.js"; + import { cn, getBackendAssetUrl } from "$lib/utils.js"; import PanelLeftIcon from "@lucide/svelte/icons/panel-left"; import type { ComponentProps } from "svelte"; + import { companyStore } from "$lib/stores/company.svelte"; import { useSidebar } from "./context.svelte.js"; let { @@ -15,6 +16,19 @@ } = $props(); const sidebar = useSidebar(); + + // Derive the current company logo as a skin for the trigger when collapsed. + let activeCompanyLogoUrl = $derived( + companyStore.activeCompany?.logo + ? getBackendAssetUrl( + `v1/a76/company/${companyStore.activeCompany.id}/logo/image?t=${Date.now()}` + ) + : null + ); + + // Keep a short fallback in case there is no logo. + const fallbackBg = + "radial-gradient(circle at 30% 30%, rgba(0,0,0,0.08), rgba(0,0,0,0.12)), linear-gradient(135deg, rgba(99,102,241,0.08), rgba(14,165,233,0.14))";