mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Move refresh button into browser address bar, move fullscreen to the left
This commit is contained in:
3 files changed
+74
-146
No files matched your search
@@ -293,34 +293,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
sendNavigationCommand('refresh');
|
||||
}, [sendNavigationCommand]);
|
||||
|
||||
const goBackIframe = useCallback(() => {
|
||||
if (historyIndex > 0) {
|
||||
// Move back in history
|
||||
const newIndex = historyIndex - 1;
|
||||
const targetPath = navigationHistory[newIndex];
|
||||
|
||||
setHistoryIndex(newIndex);
|
||||
setCurrentPath(targetPath);
|
||||
|
||||
// Tell iframe to navigate to this path
|
||||
sendNavigationCommand('navigate', { url: targetPath });
|
||||
}
|
||||
}, [historyIndex, navigationHistory, sendNavigationCommand]);
|
||||
|
||||
const goForwardIframe = useCallback(() => {
|
||||
if (historyIndex < navigationHistory.length - 1) {
|
||||
// Move forward in history
|
||||
const newIndex = historyIndex + 1;
|
||||
const targetPath = navigationHistory[newIndex];
|
||||
|
||||
setHistoryIndex(newIndex);
|
||||
setCurrentPath(targetPath);
|
||||
|
||||
// Tell iframe to navigate to this path
|
||||
sendNavigationCommand('navigate', { url: targetPath });
|
||||
}
|
||||
}, [historyIndex, navigationHistory, sendNavigationCommand]);
|
||||
|
||||
const toggleFullscreen = useCallback(() => {
|
||||
setIsFullscreen(prev => !prev);
|
||||
}, []);
|
||||
@@ -680,8 +652,8 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
<Tabs value={activeTab} className="h-full">
|
||||
{isPreviewable && (
|
||||
<TabsContent value="preview" className="h-full mt-0">
|
||||
<div
|
||||
ref={previewContainerRef}
|
||||
<div
|
||||
ref={previewContainerRef}
|
||||
className={cn(
|
||||
"h-full w-full flex flex-col relative",
|
||||
isFullscreen && "fixed inset-0 z-[100] bg-background"
|
||||
@@ -693,25 +665,23 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
currentPath={currentPath}
|
||||
onNavigate={hasBuiltProject ? navigateIframe : undefined}
|
||||
onRefresh={hasBuiltProject ? refreshIframe : undefined}
|
||||
onBack={hasBuiltProject ? goBackIframe : undefined}
|
||||
onForward={hasBuiltProject ? goForwardIframe : undefined}
|
||||
canGoBack={hasBuiltProject && historyIndex > 0}
|
||||
canGoForward={hasBuiltProject && historyIndex < navigationHistory.length - 1}
|
||||
leftContent={(
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={toggleFullscreen}
|
||||
className="h-8 w-8 p-0 ml-1"
|
||||
title={isFullscreen ? 'Exit immersive view' : 'Enter immersive view'}
|
||||
>
|
||||
{isFullscreen ? (
|
||||
<Minimize className="h-4 w-4" />
|
||||
) : (
|
||||
<Maximize className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
extraContent={(
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={toggleFullscreen}
|
||||
className="h-8 w-8 p-0"
|
||||
title={isFullscreen ? 'Exit immersive view' : 'Enter immersive view'}
|
||||
>
|
||||
{isFullscreen ? (
|
||||
<Minimize className="h-4 w-4" />
|
||||
) : (
|
||||
<Maximize className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
{(!isMobile && onToggleView && isPreviewable) && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
||||
@@ -3,11 +3,9 @@ import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { BrowserAddressBar } from './browser-address-bar';
|
||||
|
||||
describe('BrowserAddressBar', () => {
|
||||
it('renders navigation buttons and address input', () => {
|
||||
render(<BrowserAddressBar />);
|
||||
it('renders address input and refresh button', () => {
|
||||
render(<BrowserAddressBar onRefresh={vi.fn()} />);
|
||||
|
||||
expect(screen.getByTitle('Go back')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('Go forward')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('Refresh')).toBeInTheDocument();
|
||||
expect(screen.getByPlaceholderText('Enter path (e.g., /, /about)')).toBeInTheDocument();
|
||||
});
|
||||
@@ -23,65 +21,30 @@ describe('BrowserAddressBar', () => {
|
||||
expect(onNavigate).toHaveBeenCalledWith('/about');
|
||||
});
|
||||
|
||||
it('disables back/forward buttons based on canGoBack/canGoForward props and handlers', () => {
|
||||
// Test with handlers provided
|
||||
const onBack = vi.fn();
|
||||
const onForward = vi.fn();
|
||||
it('disables input when no onNavigate handler is provided', () => {
|
||||
render(<BrowserAddressBar />);
|
||||
|
||||
render(
|
||||
<BrowserAddressBar
|
||||
onBack={onBack}
|
||||
onForward={onForward}
|
||||
canGoBack={false}
|
||||
canGoForward={true}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTitle('Go back')).toBeDisabled(); // disabled because canGoBack=false
|
||||
expect(screen.getByTitle('Go forward')).not.toBeDisabled(); // enabled because canGoForward=true and handler provided
|
||||
});
|
||||
|
||||
it('disables buttons when no handlers are provided', () => {
|
||||
render(
|
||||
<BrowserAddressBar
|
||||
canGoBack={true}
|
||||
canGoForward={true}
|
||||
/>
|
||||
);
|
||||
|
||||
// All buttons should be disabled when no handlers are provided
|
||||
expect(screen.getByTitle('Go back')).toBeDisabled();
|
||||
expect(screen.getByTitle('Go forward')).toBeDisabled();
|
||||
expect(screen.getByTitle('Refresh')).toBeDisabled();
|
||||
|
||||
// Input should also be disabled when no onNavigate handler is provided
|
||||
// Input should be disabled when no onNavigate handler is provided
|
||||
expect(screen.getByPlaceholderText('Enter path (e.g., /, /about)')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('calls navigation handlers when buttons are clicked', () => {
|
||||
const onBack = vi.fn();
|
||||
const onForward = vi.fn();
|
||||
it('shows refresh button inside input when onRefresh handler is provided', () => {
|
||||
const onRefresh = vi.fn();
|
||||
render(<BrowserAddressBar onRefresh={onRefresh} />);
|
||||
|
||||
render(
|
||||
<BrowserAddressBar
|
||||
onBack={onBack}
|
||||
onForward={onForward}
|
||||
onRefresh={onRefresh}
|
||||
canGoBack={true}
|
||||
canGoForward={true}
|
||||
/>
|
||||
);
|
||||
const refreshButton = screen.getByTitle('Refresh');
|
||||
expect(refreshButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByTitle('Go back'));
|
||||
fireEvent.click(screen.getByTitle('Go forward'));
|
||||
fireEvent.click(screen.getByTitle('Refresh'));
|
||||
|
||||
expect(onBack).toHaveBeenCalled();
|
||||
expect(onForward).toHaveBeenCalled();
|
||||
fireEvent.click(refreshButton);
|
||||
expect(onRefresh).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not show refresh button when no onRefresh handler is provided', () => {
|
||||
render(<BrowserAddressBar />);
|
||||
|
||||
expect(screen.queryByTitle('Refresh')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('updates input value when currentPath prop changes', () => {
|
||||
const { rerender } = render(<BrowserAddressBar currentPath="/" />);
|
||||
|
||||
@@ -98,4 +61,24 @@ describe('BrowserAddressBar', () => {
|
||||
|
||||
expect(input).toHaveValue('/contact');
|
||||
});
|
||||
|
||||
it('renders leftContent when provided', () => {
|
||||
render(
|
||||
<BrowserAddressBar
|
||||
leftContent={<button data-testid="left-button">Left</button>}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('left-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders extraContent when provided', () => {
|
||||
render(
|
||||
<BrowserAddressBar
|
||||
extraContent={<button data-testid="extra-button">Extra</button>}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('extra-button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { ChevronLeft, ChevronRight, RefreshCw } from 'lucide-react';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
@@ -9,24 +9,18 @@ interface BrowserAddressBarProps {
|
||||
currentPath?: string;
|
||||
onNavigate?: (path: string) => void;
|
||||
onRefresh?: () => void;
|
||||
onBack?: () => void;
|
||||
onForward?: () => void;
|
||||
canGoBack?: boolean;
|
||||
canGoForward?: boolean;
|
||||
className?: string;
|
||||
extraContent?: ReactNode;
|
||||
leftContent?: ReactNode;
|
||||
}
|
||||
|
||||
export function BrowserAddressBar({
|
||||
currentPath = '/',
|
||||
onNavigate,
|
||||
onRefresh,
|
||||
onBack,
|
||||
onForward,
|
||||
canGoBack = false,
|
||||
canGoForward = false,
|
||||
className,
|
||||
extraContent,
|
||||
leftContent,
|
||||
}: BrowserAddressBarProps) {
|
||||
const [inputValue, setInputValue] = useState(currentPath);
|
||||
|
||||
@@ -55,53 +49,34 @@ export function BrowserAddressBar({
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
"flex items-center gap-1 p-2 border-b bg-background w-full",
|
||||
"flex items-center gap-2 p-2 border-b bg-background w-full",
|
||||
className
|
||||
)}>
|
||||
{/* Navigation buttons */}
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onBack}
|
||||
disabled={!canGoBack || !onBack}
|
||||
className="h-8 w-8 p-0"
|
||||
title="Go back"
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onForward}
|
||||
disabled={!canGoForward || !onForward}
|
||||
className="h-8 w-8 p-0"
|
||||
title="Go forward"
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onRefresh}
|
||||
disabled={!onRefresh}
|
||||
className="h-8 w-8 p-0"
|
||||
title="Refresh"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
{/* Left content (e.g., maximize button) */}
|
||||
{leftContent}
|
||||
|
||||
{/* Address bar */}
|
||||
<form onSubmit={handleSubmit} className="flex-1 mx-auto px-4 max-w-2xl">
|
||||
{/* Address bar with refresh button inside */}
|
||||
<form onSubmit={handleSubmit} className="flex-1 mx-auto px-4 max-w-2xl relative">
|
||||
<Input
|
||||
type="text"
|
||||
value={inputValue}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter path (e.g., /, /about)"
|
||||
className="h-8 bg-muted/50 border-muted-foreground/20 focus:bg-background"
|
||||
className="h-8 bg-muted/50 border-muted-foreground/20 focus:bg-background pr-9"
|
||||
disabled={!onNavigate}
|
||||
/>
|
||||
{onRefresh && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onRefresh}
|
||||
className="h-6 w-6 p-0 absolute right-5 top-1/2 -translate-y-1/2 hover:bg-transparent"
|
||||
title="Refresh"
|
||||
>
|
||||
<RefreshCw className="h-3.5 w-3.5 text-muted-foreground hover:text-foreground" />
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
|
||||
{/* Extra content */}
|
||||
|
||||
Reference in new issue
Block a user