|
| 1 | +import { useModalTransition } from '../../hooks/useModalTransition' |
| 2 | +import { useI18n } from '../../i18n' |
| 3 | +import { formatStudioTime, truncateStudioText } from '../theme' |
| 4 | +import type { StudioSessionHistoryEntry } from '../hooks/use-studio-session' |
| 5 | + |
| 6 | +interface StudioSessionHistoryModalProps { |
| 7 | + isOpen: boolean |
| 8 | + isLoading: boolean |
| 9 | + entries: StudioSessionHistoryEntry[] |
| 10 | + currentSessionId: string | null |
| 11 | + onClose: () => void |
| 12 | + onSelectSession: (sessionId: string) => Promise<void> | void |
| 13 | +} |
| 14 | + |
| 15 | +export function StudioSessionHistoryModal({ |
| 16 | + isOpen, |
| 17 | + isLoading, |
| 18 | + entries, |
| 19 | + currentSessionId, |
| 20 | + onClose, |
| 21 | + onSelectSession, |
| 22 | +}: StudioSessionHistoryModalProps) { |
| 23 | + const { t } = useI18n() |
| 24 | + const { shouldRender, isExiting } = useModalTransition(isOpen) |
| 25 | + |
| 26 | + if (!shouldRender) { |
| 27 | + return null |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <div className="fixed inset-0 z-[150] flex items-center justify-center p-4"> |
| 32 | + <div |
| 33 | + className={`absolute inset-0 bg-bg-primary/60 backdrop-blur-md transition-opacity duration-300 ${ |
| 34 | + isExiting ? 'opacity-0' : 'animate-overlay-wash-in' |
| 35 | + }`} |
| 36 | + onClick={onClose} |
| 37 | + /> |
| 38 | + |
| 39 | + <section |
| 40 | + className={`relative flex max-h-[min(80vh,52rem)] w-full max-w-2xl flex-col overflow-hidden rounded-[2.2rem] border border-border/10 bg-bg-secondary shadow-2xl ${ |
| 41 | + isExiting ? 'animate-fade-out-soft' : 'animate-fade-in-soft' |
| 42 | + }`} |
| 43 | + > |
| 44 | + <header className="flex items-start justify-between gap-4 border-b border-border/8 px-8 py-7"> |
| 45 | + <div> |
| 46 | + <div className="font-mono text-[10px] uppercase tracking-[0.38em] text-text-secondary/45">History</div> |
| 47 | + <h2 className="mt-3 text-xl font-medium tracking-tight text-text-primary"> |
| 48 | + {t('studio.sessionLabel')} |
| 49 | + </h2> |
| 50 | + <p className="mt-2 text-sm leading-7 text-text-secondary/68"> |
| 51 | + `/history` opens this list. `/new` starts a fresh studio session. |
| 52 | + </p> |
| 53 | + </div> |
| 54 | + <button |
| 55 | + type="button" |
| 56 | + onClick={onClose} |
| 57 | + className="rounded-2xl p-2.5 text-text-secondary/50 transition-all hover:bg-bg-primary/50 hover:text-text-primary" |
| 58 | + aria-label={t('common.close')} |
| 59 | + title={t('common.close')} |
| 60 | + > |
| 61 | + <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 62 | + <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> |
| 63 | + </svg> |
| 64 | + </button> |
| 65 | + </header> |
| 66 | + |
| 67 | + <div className="min-h-0 flex-1 overflow-y-auto px-5 py-5 sm:px-6"> |
| 68 | + {isLoading && ( |
| 69 | + <div className="flex h-40 items-center justify-center text-sm text-text-secondary/65"> |
| 70 | + Loading sessions... |
| 71 | + </div> |
| 72 | + )} |
| 73 | + |
| 74 | + {!isLoading && entries.length === 0 && ( |
| 75 | + <div className="flex h-40 items-center justify-center text-center text-sm text-text-secondary/65"> |
| 76 | + No recent sessions on this device yet. |
| 77 | + </div> |
| 78 | + )} |
| 79 | + |
| 80 | + {!isLoading && entries.length > 0 && ( |
| 81 | + <div className="space-y-3"> |
| 82 | + {entries.map((entry) => { |
| 83 | + const isCurrent = entry.id === currentSessionId |
| 84 | + return ( |
| 85 | + <button |
| 86 | + key={entry.id} |
| 87 | + type="button" |
| 88 | + onClick={() => void onSelectSession(entry.id)} |
| 89 | + className={`w-full rounded-[1.6rem] border px-5 py-4 text-left transition-all ${ |
| 90 | + isCurrent |
| 91 | + ? 'border-black/10 bg-bg-primary/72 dark:border-white/10 dark:bg-bg-primary/45' |
| 92 | + : 'border-transparent bg-bg-primary/35 hover:border-border/10 hover:bg-bg-primary/58' |
| 93 | + }`} |
| 94 | + > |
| 95 | + <div className="flex items-start justify-between gap-4"> |
| 96 | + <div className="min-w-0"> |
| 97 | + <div className="truncate text-sm font-medium text-text-primary">{entry.title}</div> |
| 98 | + <div className="mt-1 font-mono text-[10px] uppercase tracking-[0.26em] text-text-secondary/42"> |
| 99 | + {entry.studioKind} · {formatStudioTime(entry.updatedAt)} |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + {isCurrent && ( |
| 103 | + <span className="shrink-0 rounded-full bg-accent/10 px-2.5 py-1 text-[10px] font-medium uppercase tracking-[0.18em] text-accent"> |
| 104 | + Current |
| 105 | + </span> |
| 106 | + )} |
| 107 | + </div> |
| 108 | + <p className="mt-3 text-sm leading-6 text-text-secondary/72"> |
| 109 | + {truncateStudioText(entry.previewText, 140)} |
| 110 | + </p> |
| 111 | + </button> |
| 112 | + ) |
| 113 | + })} |
| 114 | + </div> |
| 115 | + )} |
| 116 | + </div> |
| 117 | + </section> |
| 118 | + </div> |
| 119 | + ) |
| 120 | +} |
0 commit comments