Просмотр исходного кода

fix(ui): keep router back button fixed at top as icon-only (#278)

Co-authored-by: gnacho <hnacho@proton.me>
Nacho 3 месяцев назад
Родитель
Сommit
b8afccf4cb
2 измененных файлов с 32 добавлено и 9 удалено
  1. 31 1
      app/src/components/Layout.tsx
  2. 1 8
      app/src/components/routers/RouterDetailHeader.tsx

+ 31 - 1
app/src/components/Layout.tsx

@@ -6,6 +6,7 @@ import { Link, NavLink, Outlet, useLocation, useNavigate } from 'react-router'
 import { AnimatePresence, motion } from 'framer-motion'
 import { AnimatePresence, motion } from 'framer-motion'
 import PullToRefresh from '@/components/PullToRefresh'
 import PullToRefresh from '@/components/PullToRefresh'
 import {
 import {
+  ArrowLeft,
   BarChart3,
   BarChart3,
   Bell,
   Bell,
   Bot,
   Bot,
@@ -87,6 +88,25 @@ function pageTitleKey(pathname: string): string {
   return PAGE_TITLE_KEYS.find(([re]) => re.test(pathname))?.[1] ?? 'nav.overview'
   return PAGE_TITLE_KEYS.find(([re]) => re.test(pathname))?.[1] ?? 'nav.overview'
 }
 }
 
 
+/** true cuando la ruta es el detalle de un router (/routers/:id). */
+function isRouterDetail(pathname: string): boolean {
+  return /^\/routers\/[^/]+/.test(pathname)
+}
+
+/** Botón atrás icon-only, fijo en el topbar/header (issue #275). */
+function BackButton() {
+  const { t } = useTranslation()
+  return (
+    <Link
+      to="/routers"
+      aria-label={t('common.back')}
+      className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-border bg-elevated text-text-secondary transition-colors duration-150 hover:border-accent/40 hover:text-accent"
+    >
+      <ArrowLeft className="h-4 w-4" strokeWidth={2} />
+    </Link>
+  )
+}
+
 /** Pill "Modo demo" (amber sutil) — solo cuando no hay backend */
 /** Pill "Modo demo" (amber sutil) — solo cuando no hay backend */
 function DemoPill() {
 function DemoPill() {
   const { t } = useTranslation()
   const { t } = useTranslation()
@@ -451,6 +471,7 @@ function Topbar() {
 
 
   return (
   return (
     <header className="sticky top-0 z-30 hidden h-14 items-center gap-4 border-b border-border bg-canvas/80 px-6 backdrop-blur-md md:flex pt-safe">
     <header className="sticky top-0 z-30 hidden h-14 items-center gap-4 border-b border-border bg-canvas/80 px-6 backdrop-blur-md md:flex pt-safe">
+      {isRouterDetail(location.pathname) && <BackButton />}
       <h1 className="font-display text-h1 text-text-primary">{t(pageTitleKey(location.pathname))}</h1>
       <h1 className="font-display text-h1 text-text-primary">{t(pageTitleKey(location.pathname))}</h1>
       <div className="ml-auto flex items-center gap-3">
       <div className="ml-auto flex items-center gap-3">
         <button
         <button
@@ -488,7 +509,16 @@ function MobileHeader() {
   }
   }
   return (
   return (
     <header className="[view-transition-name:netpulse-header] sticky top-0 z-30 flex h-14 items-center justify-between border-b border-border bg-canvas/80 px-4 backdrop-blur-md md:hidden pt-safe">
     <header className="[view-transition-name:netpulse-header] sticky top-0 z-30 flex h-14 items-center justify-between border-b border-border bg-canvas/80 px-4 backdrop-blur-md md:hidden pt-safe">
-      <Logo onClick={scrollTopIfActive('/')} />
+      <div className="flex items-center gap-2">
+        {isRouterDetail(location.pathname) ? (
+          <>
+            <BackButton />
+            <Logo compact onClick={scrollTopIfActive('/')} />
+          </>
+        ) : (
+          <Logo onClick={scrollTopIfActive('/')} />
+        )}
+      </div>
       <div className="flex items-center gap-3">
       <div className="flex items-center gap-3">
         <Link to="/" aria-label={t('topbar.networkHealth100', { score: healthScore.score })}>
         <Link to="/" aria-label={t('topbar.networkHealth100', { score: healthScore.score })}>
           <motion.div layoutId="health-ring">
           <motion.div layoutId="health-ring">

+ 1 - 8
app/src/components/routers/RouterDetailHeader.tsx

@@ -1,5 +1,5 @@
 import { Link } from 'react-router'
 import { Link } from 'react-router'
-import { ArrowLeft, Router as RouterIcon } from 'lucide-react'
+import { Router as RouterIcon } from 'lucide-react'
 import { motion, useReducedMotion } from 'framer-motion'
 import { motion, useReducedMotion } from 'framer-motion'
 import { useTranslation } from 'react-i18next'
 import { useTranslation } from 'react-i18next'
 import { roleLabel } from '@/i18n'
 import { roleLabel } from '@/i18n'
@@ -44,13 +44,6 @@ export function RouterDetailHeader({ router }: { router: Router }) {
         />
         />
       )}
       )}
       <div className="flex flex-wrap items-center gap-3">
       <div className="flex flex-wrap items-center gap-3">
-        <Link
-          to="/routers"
-          className="inline-flex items-center gap-1.5 rounded-lg border border-border px-2.5 py-1.5 text-caption font-semibold text-text-secondary transition-colors hover:border-accent/40 hover:text-accent"
-        >
-          <ArrowLeft className="h-3.5 w-3.5" strokeWidth={2} />
-          {t('common.back')}
-        </Link>
         <nav aria-label={t('common.breadcrumb')} className="font-mono text-caption text-text-muted">
         <nav aria-label={t('common.breadcrumb')} className="font-mono text-caption text-text-muted">
           <Link to="/" className="transition-colors hover:text-accent">{t('common.home')}</Link>
           <Link to="/" className="transition-colors hover:text-accent">{t('common.home')}</Link>
           <span className="mx-1.5">/</span>
           <span className="mx-1.5">/</span>