Added platform icons and fixed context menu scrolling

This commit is contained in:
patben8 committed 2026-09-25 15:23:39 +02:00
1 parent be80e572e5
commit f9497b391b
4 files changed
+147 -21

No files matched your search

+41 -18
View File
@@ -1,8 +1,10 @@
import { useState } from 'react'
import { useState, type ReactNode } from 'react'
import { useMutation, useQuery } from '@tanstack/react-query'
import { api, type CollectionCandidate, type CollectionStatus, type PlatformOption } from '../api'
import { FileBrowser, useFsListing } from './FileBrowser'
import { browsePrompt, platformAvailability } from '../lib/platformCopy'
import { Icon } from '../lib/icons'
import { PlatformIcon } from '../lib/platformIcons'
/**
* Choose a library to open, in two steps: WHICH PLATFORM, then which library.
@@ -35,13 +37,16 @@ function formatWhen(sec: number | null): string {
function OptionCard({
icon,
lit,
title,
subtitle,
disabled,
busy,
onClick,
}: {
icon: string
icon: ReactNode
/** A small lit dot on the icon tile: "something is here". */
lit?: boolean
title: string
subtitle: string
disabled?: boolean
@@ -52,14 +57,24 @@ function OptionCard({
<button
disabled={disabled || busy}
onClick={onClick}
className="flex w-full items-center gap-3 rounded-lg border border-line bg-ink-850 px-4 py-3 text-left transition-colors hover:border-accent hover:bg-ink-800 disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-line disabled:hover:bg-ink-850"
className="btn-glass group flex w-full items-center gap-3.5 rounded-2xl px-3 py-3 text-left disabled:cursor-not-allowed disabled:opacity-40"
>
<span className="text-xl">{icon}</span>
<span className="well relative flex h-11 w-11 shrink-0 items-center justify-center rounded-xl text-text">
{icon}
{lit && (
<span className="absolute -right-0.5 -top-0.5 h-2.5 w-2.5 rounded-full bg-mint shadow-[0_0_8px_var(--color-mint)] ring-2 ring-[rgb(12_14_24)]" />
)}
</span>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-text">{title}</div>
<div className="text-sm font-semibold text-text">{title}</div>
<div className="truncate text-xs text-faint">{subtitle}</div>
</div>
<span className="text-faint">›</span>
<Icon
name="chevronRight"
size={14}
strokeWidth={2.2}
className="text-faint transition-colors group-hover:text-text"
/>
</button>
)
}
@@ -124,6 +139,11 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
<div className="glass flex h-[600px] w-full max-w-2xl flex-col overflow-hidden">
{/* Header */}
<div className="flex items-center gap-3 border-b border-line px-5 py-4">
{platform && (
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-ink-800 text-text">
<PlatformIcon platform={platform.platform} size={22} />
</span>
)}
<div className="min-w-0 flex-1">
<div className="text-[15px] font-semibold tracking-tight">
{platform ? `Select your ${platform.name} library` : 'Select your DJ platform'}
@@ -133,23 +153,25 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
{step === 'browse' && (
<button
onClick={() => setStep('library')}
className="rounded-md px-2.5 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
className="flex items-center gap-1 rounded-full px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
‹ Back
<Icon name="chevronLeft" size={13} strokeWidth={2.2} />
Back
</button>
)}
{step === 'library' && (
<button
onClick={goPlatform}
className="rounded-md px-2.5 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
className="flex items-center gap-1 rounded-full px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
‹ Platforms
<Icon name="chevronLeft" size={13} strokeWidth={2.2} />
Platforms
</button>
)}
{onCancel && (
<button
onClick={onCancel}
className="rounded-md px-2.5 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
className="rounded-full px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
Cancel
</button>
@@ -166,7 +188,8 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
{platforms.data?.map((p) => (
<OptionCard
key={p.platform}
icon={p.removable ? '⬒' : p.found > 0 ? '●' : '○'}
icon={<PlatformIcon platform={p.platform} size={26} />}
lit={p.found > 0}
title={p.name}
subtitle={platformAvailability(p)}
onClick={() => {
@@ -180,7 +203,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
/* ---- Step 2: which library of that platform ---- */
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto p-5">
<OptionCard
icon="✨"
icon={<Icon name="sparkle" size={20} />}
title="Automatic"
subtitle={
auto
@@ -196,7 +219,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
onClick={() => auto && open.mutate(auto.path)}
/>
<OptionCard
icon="🕘"
icon={<Icon name="history" size={20} />}
title="Open last library"
subtitle={
recent
@@ -210,7 +233,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
onClick={() => recent && open.mutate(recent.path)}
/>
<OptionCard
icon="📂"
icon={<Icon name="folderOpen" size={20} />}
title="Find library manually"
subtitle={
picksDirectory
@@ -234,7 +257,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
key={c.path}
disabled={open.isPending}
onClick={() => open.mutate(c.path)}
className="flex w-full items-center gap-2 rounded-md border border-line bg-ink-850 px-3 py-2 text-left text-sm text-muted hover:border-accent hover:text-text disabled:opacity-40"
className="btn-glass flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm text-muted hover:text-text disabled:opacity-40"
>
<span className="truncate">{c.label}</span>
<span className="ml-auto shrink-0 text-[11px] text-faint">
@@ -247,7 +270,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
)}
{openError && (
<div className="rounded-md border border-pink/40 bg-ink-850 px-3 py-2 text-xs text-pink">
<div className="rounded-xl bg-pink/10 px-3 py-2 text-xs text-pink shadow-[inset_0_0_0_1px_rgb(255_122_154/0.35)]">
{openError}
</div>
)}
@@ -286,7 +309,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
{/* Manual path + errors */}
<div className="border-t border-line px-4 py-3">
{openError && (
<div className="mb-2 rounded-md border border-pink/40 bg-ink-850 px-3 py-2 text-xs text-pink">
<div className="mb-2 rounded-xl bg-pink/10 px-3 py-2 text-xs text-pink shadow-[inset_0_0_0_1px_rgb(255_122_154/0.35)]">
{openError}
</div>
)}
+15 -2
View File
@@ -21,6 +21,9 @@ interface Props {
const SUBMENU_WIDTH = 240
const SUBMENU_MAX_HEIGHT = 288
// A long menu (the header's column chooser lists every column) scrolls rather
// than running the height of the window.
const MENU_MAX_HEIGHT = 400
// Lightweight fixed-position menu. Closes on outside click, scroll, or Escape.
export function ContextMenu({ x, y, items, onClose }: Props) {
@@ -67,7 +70,11 @@ export function ContextMenu({ x, y, items, onClose }: Props) {
className="min-w-[160px]"
style={(() => {
const top = Math.min(y, window.innerHeight - 100)
return { top, left: Math.min(x, window.innerWidth - 180), maxHeight: window.innerHeight - top - 8 }
return {
top,
left: Math.min(x, window.innerWidth - 180),
maxHeight: Math.min(MENU_MAX_HEIGHT, window.innerHeight - top - 8),
}
})()}
/>
</div>,
@@ -102,10 +109,15 @@ function MenuPanel({
return (
<>
{/* The glass (tint, blur, rim) is painted by pseudo-elements of THIS box,
so it must not be the one that scrolls: its ::before/::after would
scroll away with the first screenful of items and leave the rest on
bare background. The frame stays put; the inner list scrolls. */}
<div
className={`glass-overlay fixed z-[70] overflow-y-auto rounded-2xl p-1.5 ${className}`}
className={`glass-overlay fixed z-[70] flex flex-col overflow-hidden rounded-2xl ${className}`}
style={style}
>
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain p-1.5">
{items.map((item, i) => {
if ('separator' in item) {
return <div key={i} className="mx-2 my-1 border-t border-line" />
@@ -181,6 +193,7 @@ function MenuPanel({
</button>
)
})}
</div>
</div>
{open && openItem && 'submenu' in openItem && (
<MenuPanel items={openItem.submenu} onClose={onClose} style={open.style} />