From d1c052c9e8e83903ace1cc0648c6c3d8f44457aa Mon Sep 17 00:00:00 2001 From: Pouzor Date: Tue, 30 Jun 2026 00:48:56 +0200 Subject: [PATCH] feat: hide header View link in standalone mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "View" link opens the read-only live view of the canvas. In frontend-only standalone mode the editor already renders the only (localStorage) copy, so the live view adds nothing — hide the link. Kept in full mode. ha-relevant: no --- frontend/src/components/panels/Toolbar.tsx | 12 +++++-- .../panels/__tests__/Toolbar.test.tsx | 31 ++++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/panels/Toolbar.tsx b/frontend/src/components/panels/Toolbar.tsx index 87d1d72..6f1b2b5 100644 --- a/frontend/src/components/panels/Toolbar.tsx +++ b/frontend/src/components/panels/Toolbar.tsx @@ -4,6 +4,8 @@ import { Button } from '@/components/ui/button' import { Logo } from '@/components/ui/Logo' import { useCanvasStore } from '@/stores/canvasStore' +const STANDALONE = import.meta.env.VITE_STANDALONE === 'true' + interface ToolbarProps { onSave: () => void onAutoLayout: () => void @@ -82,9 +84,13 @@ export function Toolbar({ onSave, onAutoLayout, onExport, onChangeStyle, onUndo, - + {/* Live view reads backend/localStorage canvas; pointless in standalone + where the editor already shows the only (localStorage) copy. */} + {!STANDALONE && ( + + )} diff --git a/frontend/src/components/panels/__tests__/Toolbar.test.tsx b/frontend/src/components/panels/__tests__/Toolbar.test.tsx index 0540929..e06cc60 100644 --- a/frontend/src/components/panels/__tests__/Toolbar.test.tsx +++ b/frontend/src/components/panels/__tests__/Toolbar.test.tsx @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach, vi } from 'vitest' +import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import { Toolbar } from '../Toolbar' import { useCanvasStore } from '@/stores/canvasStore' @@ -56,4 +56,33 @@ describe('Toolbar', () => { fireEvent.click(screen.getByText('Save')) expect(defaultProps.onSave).toHaveBeenCalledWith() }) + + it('shows the View (live view) link in full mode', () => { + render() + expect(screen.getByText('View')).toBeInTheDocument() + }) +}) + +// ── Standalone mode ──────────────────────────────────────────────────────────── +// VITE_STANDALONE is read at module load, so re-import Toolbar after stubbing it. +describe('Toolbar (standalone)', () => { + afterEach(() => { + vi.unstubAllEnvs() + }) + + it('hides the View link (live view is pointless without a backend)', async () => { + vi.stubEnv('VITE_STANDALONE', 'true') + vi.resetModules() + const { useCanvasStore: cs } = await import('@/stores/canvasStore') + vi.mocked(cs).mockReturnValue({ + hasUnsavedChanges: false, past: [], future: [], + } as ReturnType) + const { Toolbar: TB } = await import('../Toolbar') + + render() + expect(screen.queryByText('View')).not.toBeInTheDocument() + // Other actions remain. + expect(screen.getByText('Save')).toBeInTheDocument() + expect(screen.getByText('MD')).toBeInTheDocument() + }) })