Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/ctf/CtfView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import {
ArrowLeft,
Binary,
Check,
Copy,
Expand All @@ -23,6 +24,7 @@ import { bySeverity, confidenceColor, cx } from '../ui/helpers';
import { LayerFind } from './LayerFind';
import { Button, ConfidenceBar } from '../ui/primitives';
import { CopyChip, FindingCard, IndicatorList } from '../analysis/Evidence';
import { useIsDesktop } from '../../hooks/useMediaQuery';


const KIND_ICON: Record<HintKind, typeof Flag> = {
Expand Down Expand Up @@ -213,10 +215,24 @@ export function CtfView() {
const input = useStore((s) => s.input);
const analysis = useStore((s) => s.analysis);
const chain = useStore((s) => s.chain);
const setActivity = useStore((s) => s.setActivity);
const isDesktop = useIsDesktop();

const back = !isDesktop && (
<button
type="button"
onClick={() => setActivity('operations')}
className="inline-flex items-center gap-1.5 rounded-control border border-line px-2.5 py-1.5 text-micro text-muted transition-colors duration-150 hover:border-accent-line hover:text-text"
>
<ArrowLeft size={13} aria-hidden="true" />
{t.layout.backToWorkspace}
</button>
);

if (input.trim().length === 0) {
return (
<main className="flex min-h-0 flex-1 flex-col items-center justify-center gap-2 px-6 text-center">
{back}
<Search size={22} aria-hidden="true" className="text-faint" />
<h2 className="text-sm font-medium">{t.ctf.emptyTitle}</h2>
<p className="max-w-md text-xs2 leading-relaxed text-muted">{t.ctf.emptyDetail}</p>
Expand All @@ -230,6 +246,7 @@ export function CtfView() {
<main className="min-h-0 flex-1 overflow-y-auto">
<div className="mx-auto max-w-5xl space-y-5 px-4 py-5">
<header className="space-y-3">
{back}
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
<h1 className="text-sm font-semibold">{t.ctf.title}</h1>
<p className="text-micro text-muted">{t.ctf.subtitle}</p>
Expand Down
62 changes: 62 additions & 0 deletions src/components/layout/MobileTabs.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @vitest-environment happy-dom
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { useStore } from '../../store/useStore';
import { MobileTabs } from './MobileTabs';
import { CtfView } from '../ctf/CtfView';

let root: Root;
let container: HTMLDivElement;

function stubDesktop(desktop: boolean) {
vi.stubGlobal('matchMedia', (query: string) => ({
matches: desktop,
media: query,
addEventListener: () => {},
removeEventListener: () => {},
}));
}

beforeEach(() => {
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
localStorage.clear();
useStore.setState({ activity: 'operations', view: 'workspace', mobilePane: 'input', input: '' });
container = document.createElement('div');
document.body.append(container);
});

afterEach(() => {
act(() => root.unmount());
container.remove();
vi.unstubAllGlobals();
});

describe('mobile Search/CTF navigation', () => {
it('opens the CTF view from the mobile tab bar', async () => {
stubDesktop(false);
root = createRoot(container);
await act(() => root.render(<MobileTabs />));

const search = [...container.querySelectorAll('button')].find((b) => b.textContent === 'Search');
expect(search).toBeDefined();

act(() => search!.click());
expect(useStore.getState().view).toBe('ctf');
});

it('returns to the workspace from the CTF view on mobile', async () => {
stubDesktop(false);
useStore.setState({ activity: 'search', view: 'ctf' });
root = createRoot(container);
await act(() => root.render(<CtfView />));

const back = [...container.querySelectorAll('button')].find((b) =>
b.textContent?.includes('Back to workspace'),
);
expect(back).toBeDefined();

act(() => back!.click());
expect(useStore.getState().view).toBe('workspace');
});
});
10 changes: 6 additions & 4 deletions src/components/layout/MobileTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { FileInput, FileOutput, ListOrdered, Wrench } from 'lucide-react';
import { FileInput, FileOutput, ListOrdered, Search, Wrench } from 'lucide-react';
import { useStore, type MobilePane } from '../../store/useStore';
import { t } from '../../i18n/en';
import { cx } from '../ui/helpers';

const TABS: Array<{ id: MobilePane; label: string; Icon: typeof Wrench }> = [
const TABS: Array<{ id: MobilePane | 'search'; label: string; Icon: typeof Wrench }> = [
{ id: 'input', label: t.input.title, Icon: FileInput },
{ id: 'recipe', label: t.recipe.title, Icon: ListOrdered },
{ id: 'output', label: t.output.title, Icon: FileOutput },
{ id: 'operations', label: t.operations.title, Icon: Wrench },
{ id: 'search', label: t.activity.search, Icon: Search },
];

export function MobileTabs() {
const mobilePane = useStore((s) => s.mobilePane);
const setMobilePane = useStore((s) => s.setMobilePane);
const setActivity = useStore((s) => s.setActivity);
const steps = useStore((s) => s.steps);
const chain = useStore((s) => s.chain);

const badge: Partial<Record<MobilePane, number>> = {
const badge: Partial<Record<MobilePane | 'search', number>> = {
recipe: steps.length,
output: chain.length > 1 ? chain.length - 1 : 0,
};
Expand All @@ -33,7 +35,7 @@ export function MobileTabs() {
<button
key={id}
type="button"
onClick={() => setMobilePane(id)}
onClick={() => (id === 'search' ? setActivity('search') : setMobilePane(id))}
aria-current={active ? 'page' : undefined}
className={cx(
'flex flex-1 flex-col items-center gap-0.5 py-2 transition-colors duration-150 ease-smooth',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const t = {
layout: {
panes: 'Workspace panes',
skipToInput: 'Skip to input',
backToWorkspace: 'Back to workspace',
maximiseOutput: 'Maximise the output group',
restore: 'Restore the layout',
resizeOperations: 'Resize the operations pane',
Expand Down
Loading