Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(howto): open the How-it-works films over the whole window (C26)

purpleee09f5ffebfb
diff --git a/e2e/howto-large.spec.ts b/e2e/howto-large.spec.ts
new file mode 100644
index 00000000..3ec4f919
--- /dev/null
+++ b/e2e/howto-large.spec.ts
@@ -0,0 +1,57 @@
+import { test, expect } from '@playwright/test'
+import { readFileSync } from 'node:fs'
+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'
+import { seedOnboardingDone } from './support/cloud-mock'
+
+/**
+ * C26 (3.1.0): a How-it-works film opens over the whole window, and C25: the
+ * dialog sheet it sits on is opaque white in the light theme. The films come
+ * from lu-labs.ai; here a local clip stands in for them.
+ */
+const SHOTS = process.env.LU_SHOTS_DIR
+const CLIP = readFileSync(new URL('../docs/assets/home/katana.mp4', import.meta.url))
+
+test('the How-it-works film can be enlarged to the window (light theme)', async ({ page }) => {
+ await page.setViewportSize({ width: 1440, height: 900 })
+ await page.route('https://lu-labs.ai/howto/**', (r) => r.fulfill({ body: CLIP, contentType: 'video/mp4' }))
+ await page.addInitScript(tauriMockInit, { assistantReply: DEFAULT_ASSISTANT_REPLY, modelName: DEFAULT_MODEL_NAME })
+ await seedOnboardingDone(page)
+ await page.addInitScript(() => {
+ const raw = JSON.parse(localStorage.getItem('chat-settings') || '{}')
+ raw.state.settings.theme = 'light'
+ localStorage.setItem('chat-settings', JSON.stringify(raw))
+ })
+ await page.goto('/')
+ await expect(page.locator('html')).toHaveClass(/light/)
+
+ await page.getByRole('banner').getByRole('button', { name: 'Settings', exact: true }).click()
+ await page.getByRole('button', { name: 'Onboarding' }).click()
+ const entry = page.getByTestId('howto-beginners')
+ await expect(entry).toBeVisible()
+ const topic = (await entry.getAttribute('data-testid'))!.slice('howto-'.length)
+ await entry.locator('button').first().click()
+ const card = page.getByTestId(`howto-card-${topic}`)
+ await expect(card).toBeVisible()
+ await expect(page.getByTestId('howto-video')).toBeVisible()
+ const small = await page.getByTestId('howto-video').boundingBox()
+ if (SHOTS) await page.screenshot({ path: `${SHOTS}/C26-1-karte-klein.png` })
+
+ await page.getByTestId('howto-enlarge').click()
+ const big = page.getByTestId('howto-video-large')
+ await expect(big).toBeVisible()
+ await page.waitForTimeout(1200)
+ const box = await big.boundingBox()
+ expect(box!.width).toBeGreaterThan(small!.width * 3)
+ expect(box!.width).toBeGreaterThan(1000)
+ if (SHOTS) await page.screenshot({ path: `${SHOTS}/C26-2-vergroessert-hell.png` })
+
+ // C25: the sheet under the big film is .lu-dialog, opaque white in light.
+ const bg = await page.locator('.lu-dialog').first().evaluate((el) => getComputedStyle(el).backgroundColor)
+ expect(bg).toBe('rgb(255, 255, 255)')
+
+ await page.keyboard.press('Escape')
+ await expect(big).toBeHidden()
+ await expect(card).toBeVisible()
+ await page.keyboard.press('Escape')
+ await expect(card).toBeHidden()
+})
diff --git a/src/components/ui/HowItWorks.tsx b/src/components/ui/HowItWorks.tsx
index 6aab6258..9cf2690a 100644
--- a/src/components/ui/HowItWorks.tsx
+++ b/src/components/ui/HowItWorks.tsx
@@ -1,6 +1,6 @@
-import { useEffect, useLayoutEffect, useRef, useState } from 'react'
+import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
import { createPortal } from 'react-dom'
-import { CircleHelp, ExternalLink, Play, X } from 'lucide-react'
+import { CircleHelp, ExternalLink, Maximize2, Minimize2, Play, X } from 'lucide-react'
import { HOWTO, howtoGuideUrl, howtoLineAt, howtoVideoUrl } from '../../lib/howto'
import { openExternal } from '../../api/backend'
import { useDismissOnEscape } from '../../hooks/useDismissOnEscape'
@@ -45,6 +45,13 @@ export function howtoCardPlace(
* The entry to "How it works" and the card it opens: a short silent film and
* ONE line under it that follows the scene. Nothing is loaded until the card
* is opened; without a connection the card shows its lines as a list instead.
+ *
+ * C26 (3.1.0, Discord: "so small they are unwatchable"): the 340 px card is a
+ * preview. The enlarge button, or a double click on the film, opens it over
+ * the whole window, with the film as large as the window allows and the same
+ * line under it, at the second it was at. Escape or a click beside it goes
+ * back to the card. It is an in-app view, not the Fullscreen API: WKWebView
+ * and WebKitGTK only allow element fullscreen when the host switches it on.
*/
export function HowItWorks({ topic, variant, placement = 'above', markSize = 11 }: Props) {
const entry = HOWTO[topic]
@@ -55,12 +62,19 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
const rootRef = useRef<HTMLDivElement>(null)
const cardRef = useRef<HTMLDivElement>(null)
const [place, setPlace] = useState<{ left: number; top: number } | null>(null)
- useDismissOnEscape(open, () => setOpen(false))
+ const [large, setLarge] = useState(false)
+ const largeRef = useRef<HTMLDivElement>(null)
+ /** Where the film was when it changed size, so it goes on from there. */
+ const resumeAt = useRef(0)
+ useDismissOnEscape(open, () => { if (large) setLarge(false); else setOpen(false) })
useEffect(() => {
if (!open) return
const outside = (e: MouseEvent) => {
const t = e.target as Node
+ // The large view's own backdrop shrinks it back (its onClick), it does
+ // not close the whole thing.
+ if (largeRef.current?.contains(t)) return
if (!rootRef.current?.contains(t) && !cardRef.current?.contains(t)) setOpen(false)
}
document.addEventListener('mousedown', outside)
@@ -70,7 +84,7 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
// The card is drawn on the body, so no stage or toolbar can clip it, and
// placed again whenever its own size changes (film loaded, list shown).
useLayoutEffect(() => {
- if (!open) return
+ if (!open || large) return
const card = cardRef.current
const root = rootRef.current
if (!card || !root) return
@@ -93,7 +107,7 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
seen.observe(card)
window.addEventListener('resize', put)
return () => { seen.disconnect(); window.removeEventListener('resize', put) }
- }, [open, placement])
+ }, [open, placement, large])
if (!entry) return null
const film = entry.films[Math.min(filmIndex, entry.films.length - 1)]
@@ -104,9 +118,63 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
setLine(entry.films[i].steps[0]?.text ?? '')
}
const toggle = () => {
- if (!open) pick(filmIndex)
+ if (!open) { pick(filmIndex); setLarge(false); resumeAt.current = 0 }
setOpen((o) => !o)
}
+ const resize = (to: boolean, from: HTMLVideoElement | null) => {
+ resumeAt.current = from?.currentTime ?? 0
+ setLarge(to)
+ }
+
+ const filmHeader = (closeLabel: string, onCloseClick: () => void, sizeButton: ReactNode) => (
+ <div className="flex items-center gap-2 mb-2">
+ <span className="t-control font-semibold text-gray-800 dark:text-gray-200">{entry.title}</span>
+ {entry.films.length > 1 && entry.films.map((f, i) => (
+ <button
+ key={f.id}
+ onClick={() => { resumeAt.current = 0; pick(i) }}
+ aria-pressed={i === filmIndex}
+ className={`t-control px-1.5 rounded transition-colors ${i === filmIndex
+ ? 'text-gray-800 dark:text-gray-200 bg-gray-100 dark:bg-white/[0.06]'
+ : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}`}
+ >
+ {f.label}
+ </button>
+ ))}
+ <div className="flex-1" />
+ {sizeButton}
+ <button
+ onClick={onCloseClick}
+ aria-label={closeLabel}
+ className="p-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"
+ >
+ <X size={12} />
+ </button>
+ </div>
+ )
+
+ const filmVideo = (big: boolean) => (
+ <video
+ key={`${film.id}-${big ? 'large' : 'card'}`}
+ src={howtoVideoUrl(film)}
+ autoPlay
+ loop
+ muted
+ playsInline
+ data-testid={big ? 'howto-video-large' : 'howto-video'}
+ title={big ? undefined : 'Double-click to enlarge'}
+ onLoadedMetadata={(e) => {
+ const at = resumeAt.current
+ if (at > 0 && at < e.currentTarget.duration) e.currentTarget.currentTime = at
+ }}
+ onDoubleClick={(e) => resize(!big, e.currentTarget)}
+ onTimeUpdate={(e) => setLine(howtoLineAt(film.steps, e.currentTarget.currentTime))}
+ onError={() => setFailed(true)}
+ className={big
+ ? 'block min-h-0 w-full flex-1 object-contain rounded-md bg-black'
+ : 'block w-full rounded-md border border-gray-200 dark:border-white/[0.06] bg-gray-200 dark:bg-lu-canvas cursor-zoom-in'}
+ />
+ )
// aria-haspopup: the trigger opens a card, it does not unfold a section.
// Screen readers announce it that way, and the settings walk in
@@ -143,46 +211,28 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
style={place ? { left: place.left, top: place.top } : { left: 0, top: 0, visibility: 'hidden' }}
className="fixed z-50 w-[340px] max-w-[90vw] p-2.5 rounded-lg text-left lu-elevated"
>
- <div className="flex items-center gap-2 mb-2">
- <span className="t-control font-semibold text-gray-800 dark:text-gray-200">{entry.title}</span>
- {entry.films.length > 1 && entry.films.map((f, i) => (
- <button
- key={f.id}
- onClick={() => pick(i)}
- aria-pressed={i === filmIndex}
- className={`t-control px-1.5 rounded transition-colors ${i === filmIndex
- ? 'text-gray-800 dark:text-gray-200 bg-gray-100 dark:bg-white/[0.06]'
- : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}`}
- >
- {f.label}
- </button>
- ))}
- <div className="flex-1" />
+ {filmHeader('Close', () => setOpen(false), !failed && (
<button
- onClick={() => setOpen(false)}
- aria-label="Close"
+ onClick={() => resize(true, cardRef.current?.querySelector('video') ?? null)}
+ aria-label="Enlarge video"
+ title="Enlarge"
+ data-testid="howto-enlarge"
className="p-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"
>
- <X size={12} />
+ <Maximize2 size={12} />
</button>
- </div>
+ ))}
{failed ? (
<ol className="t-control text-gray-600 dark:text-gray-400 space-y-1 list-decimal pl-4" data-testid="howto-lines">
{film.steps.map((s) => <li key={s.from}>{s.text}</li>)}
</ol>
) : (
<>
- <video
- key={film.id}
- src={howtoVideoUrl(film)}
- autoPlay
- loop
- muted
- playsInline
- onTimeUpdate={(e) => setLine(howtoLineAt(film.steps, e.currentTarget.currentTime))}
- onError={() => setFailed(true)}
- className="block w-full rounded-md border border-gray-200 dark:border-white/[0.06] bg-gray-200 dark:bg-lu-canvas"
- />
+ {large ? (
+ <div className="flex aspect-video w-full items-center justify-center rounded-md border border-gray-200 dark:border-white/[0.06] bg-gray-200 dark:bg-lu-canvas t-control text-gray-500">
+ Playing enlarged
+ </div>
+ ) : filmVideo(false)}
<p className="t-control mt-2 min-h-[2.6em] text-gray-600 dark:text-gray-400" data-testid="howto-line">{line}</p>
</>
)}
@@ -198,6 +248,35 @@ export function HowItWorks({ topic, variant, placement = 'above', markSize = 11
</div>,
document.body,
)}
+ {open && large && !failed && createPortal(
+ <div
+ ref={largeRef}
+ className="fixed inset-0 z-[60] flex items-center justify-center p-6 lu-dialog-scrim"
+ onClick={(e) => { if (e.target === e.currentTarget) setLarge(false) }}
+ data-testid={`howto-large-${topic}`}
+ >
+ <div
+ role="dialog"
+ aria-modal="true"
+ aria-label={`${entry.title}, enlarged`}
+ className="flex max-h-full w-full max-w-[1280px] flex-col rounded-xl p-3 lu-dialog"
+ >
+ {filmHeader('Close enlarged video', () => setLarge(false), (
+ <button
+ onClick={() => resize(false, largeRef.current?.querySelector('video') ?? null)}
+ aria-label="Shrink video"
+ title="Shrink"
+ className="p-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"
+ >
+ <Minimize2 size={12} />
+ </button>
+ ))}
+ {filmVideo(true)}
+ <p className="t-body mt-2 min-h-[2.6em] text-center text-gray-700 dark:text-gray-300" data-testid="howto-line-large">{line}</p>
+ </div>
+ </div>,
+ document.body,
+ )}
</div>
)
}
diff --git a/src/components/ui/__tests__/howto-video-large.test.tsx b/src/components/ui/__tests__/howto-video-large.test.tsx
new file mode 100644
index 00000000..1cd694c7
--- /dev/null
+++ b/src/components/ui/__tests__/howto-video-large.test.tsx
@@ -0,0 +1,92 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * C26 (3.1.0): the How-it-works films were only ever 340 px wide, "so small
+ * they are unwatchable" (Discord, 1 Nov). The card now opens them over the
+ * whole window: by its enlarge button or a double click on the film, back by
+ * Escape, the shrink button or a click beside it, and Escape a second time
+ * closes the card as before.
+ *
+ * Run: npx vitest run src/components/ui/__tests__/howto-video-large.test.tsx
+ */
+import { describe, it, expect, afterEach, vi } from 'vitest'
+import { createElement } from 'react'
+import { render, screen, fireEvent, cleanup } from '@testing-library/react'
+
+vi.mock('../../../api/backend', () => ({ openExternal: vi.fn() }))
+
+import { HowItWorks } from '../HowItWorks'
+import { HOWTO } from '../../../lib/howto'
+
+// jsdom has no ResizeObserver; the card only uses it to place itself.
+globalThis.ResizeObserver ??= class { observe() {} unobserve() {} disconnect() {} } as unknown as typeof ResizeObserver
+
+afterEach(cleanup)
+
+const TOPIC = Object.keys(HOWTO)[0]
+
+function openCard() {
+ render(createElement(HowItWorks, { topic: TOPIC, variant: 'line' }))
+ fireEvent.click(screen.getByText(HOWTO[TOPIC].title))
+ return screen.getByTestId(`howto-card-${TOPIC}`)
+}
+
+describe('How it works, enlarged', () => {
+ it('the card has an enlarge button and starts small', () => {
+ openCard()
+ expect(screen.getByTestId('howto-enlarge')).toBeTruthy()
+ expect(screen.getByTestId('howto-video')).toBeTruthy()
+ expect(screen.queryByTestId(`howto-large-${TOPIC}`)).toBeNull()
+ })
+
+ it('the button opens the film over the window, one film at a time', () => {
+ openCard()
+ fireEvent.click(screen.getByTestId('howto-enlarge'))
+ const large = screen.getByTestId(`howto-large-${TOPIC}`)
+ expect(large.className).toContain('fixed')
+ expect(large.className).toContain('inset-0')
+ expect(screen.getByTestId('howto-video-large')).toBeTruthy()
+ expect(screen.queryByTestId('howto-video')).toBeNull()
+ expect(screen.getByRole('dialog', { name: `${HOWTO[TOPIC].title}, enlarged` })).toBeTruthy()
+ })
+
+ it('a double click on the film enlarges it too', () => {
+ openCard()
+ fireEvent.doubleClick(screen.getByTestId('howto-video'))
+ expect(screen.getByTestId('howto-video-large')).toBeTruthy()
+ })
+
+ it('Escape shrinks first, then closes the card', () => {
+ openCard()
+ fireEvent.click(screen.getByTestId('howto-enlarge'))
+ fireEvent.keyDown(document, { key: 'Escape' })
+ expect(screen.queryByTestId(`howto-large-${TOPIC}`)).toBeNull()
+ expect(screen.getByTestId(`howto-card-${TOPIC}`)).toBeTruthy()
+ fireEvent.keyDown(document, { key: 'Escape' })
+ expect(screen.queryByTestId(`howto-card-${TOPIC}`)).toBeNull()
+ })
+
+ it('a click beside the film shrinks it and keeps the card', () => {
+ openCard()
+ fireEvent.click(screen.getByTestId('howto-enlarge'))
+ const backdrop = screen.getByTestId(`howto-large-${TOPIC}`)
+ fireEvent.mouseDown(backdrop)
+ fireEvent.click(backdrop)
+ expect(screen.queryByTestId(`howto-large-${TOPIC}`)).toBeNull()
+ expect(screen.getByTestId(`howto-card-${TOPIC}`)).toBeTruthy()
+ })
+
+ it('the shrink button goes back to the card', () => {
+ openCard()
+ fireEvent.click(screen.getByTestId('howto-enlarge'))
+ fireEvent.click(screen.getByLabelText('Shrink video'))
+ expect(screen.getByTestId('howto-video')).toBeTruthy()
+ })
+
+ it('without a connection there is nothing to enlarge', () => {
+ openCard()
+ fireEvent.error(screen.getByTestId('howto-video'))
+ expect(screen.getByTestId('howto-lines')).toBeTruthy()
+ expect(screen.queryByTestId('howto-enlarge')).toBeNull()
+ })
+})