Refactor card components for improved layout and functionality

- Updated card styles in viewer.html and viewer-template.html to enhance padding, margins, and overall layout.
- Introduced new header structure with left-aligned type and project name, and added view mode toggle buttons for facts and narrative.
- Simplified content rendering logic in ObservationCard, allowing for toggling between facts and narrative.
- Updated metadata display in ObservationCard, PromptCard, and SummaryCard to include formatted date and improved layout.
- Removed unnecessary verbose content sections and streamlined the presentation of facts and narrative.
This commit is contained in:
Alex Newman
2025-11-07 17:03:05 -05:00
parent 740d65b5a5
commit 700e3253fa
6 changed files with 293 additions and 437 deletions
+98 -163
View File
@@ -482,7 +482,7 @@
.card {
margin-bottom: 24px;
padding: 20px 24px;
padding: 24px;
background: var(--color-bg-card);
border: 1px solid var(--color-border-primary);
border-radius: 8px;
@@ -510,13 +510,19 @@
.card-header {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
justify-content: space-between;
margin-bottom: 14px;
font-size: 12px;
color: var(--color-text-muted);
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}
.card-header-left {
display: flex;
align-items: center;
gap: 10px;
}
.card-type {
padding: 2px 8px;
background: var(--color-type-badge-bg);
@@ -530,214 +536,142 @@
.card-title {
font-size: 17px;
margin-bottom: 8px;
margin-bottom: 14px;
color: var(--color-text-title);
font-weight: 600;
line-height: 1.4;
letter-spacing: -0.01em;
}
.card-subtitle {
font-size: 14px;
color: var(--color-text-subtitle);
margin-bottom: 8px;
line-height: 1.6;
}
.card-meta {
font-size: 12px;
color: var(--color-text-tertiary);
margin-top: 8px;
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
.view-mode-toggles {
display: flex;
gap: 8px;
flex-shrink: 0;
}
.view-mode-toggle {
display: flex;
justify-content: space-between;
align-items: center;
}
/* Expanded card state */
.card-expanded {
/* Increased shadow when expanded */
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
/* Expand toggle button */
.expand-toggle {
background: none;
border: none;
color: var(--color-text-secondary);
cursor: pointer;
font-size: 12px;
gap: 4px;
background: var(--color-bg-tertiary);
border: 1px solid var(--color-border-primary);
padding: 4px 8px;
border-radius: 4px;
cursor: pointer;
color: var(--color-text-secondary);
transition: all 0.15s ease;
font-family: inherit;
font-size: 11px;
font-weight: 500;
text-transform: lowercase;
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}
.expand-toggle:hover {
background: var(--color-bg-secondary);
.view-mode-toggle svg {
flex-shrink: 0;
opacity: 0.7;
transition: opacity 0.15s ease;
}
.view-mode-toggle:hover {
background: var(--color-bg-card-hover);
border-color: var(--color-border-hover);
color: var(--color-text-primary);
}
/* Verbose content container (narrative and facts - collapsible) */
.card-verbose-content {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid var(--color-border-primary);
animation: expandDown 0.2s ease-out;
.view-mode-toggle:hover svg {
opacity: 1;
}
@keyframes expandDown {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: translateY(0);
}
.view-mode-toggle.active {
background: var(--color-accent-primary);
border-color: var(--color-accent-primary);
color: var(--color-text-button);
}
/* Metadata grid (concepts, files, session info - always visible) */
.card-metadata-grid {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid var(--color-border-primary);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
grid-auto-flow: dense;
.view-mode-toggle.active svg {
opacity: 1;
}
/* Files section spans full width */
.card-metadata-grid .card-section.files-section {
grid-column: 1 / -1;
.view-mode-content {
margin-bottom: 12px;
}
/* Responsive: stack on smaller screens */
@media (max-width: 768px) {
.card-metadata-grid {
grid-template-columns: 1fr;
}
.card-metadata-grid .card-section.files-section {
grid-column: 1;
}
}
/* Compact section styling for grid items */
.card-section.compact {
.view-mode-content .card-subtitle {
margin-bottom: 0;
}
.card-section.compact .section-header {
font-size: 12px;
margin-bottom: 6px;
}
.card-section.compact .section-content {
padding-left: 0;
font-size: 12px;
}
/* Section styling */
.card-section {
margin-bottom: 16px;
}
.card-section:last-child {
margin-bottom: 0;
}
.section-header {
font-weight: 600;
font-size: 13px;
color: var(--color-text-primary);
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 6px;
}
.section-content {
.view-mode-content .facts-list {
list-style: disc;
margin: 0;
padding-left: 20px;
color: var(--color-text-secondary);
font-size: 13px;
line-height: 1.6;
line-height: 1.7;
}
/* Narrative styling */
.narrative {
.view-mode-content .facts-list li {
margin-bottom: 6px;
}
.view-mode-content .narrative {
max-height: 300px;
overflow-y: auto;
white-space: pre-wrap;
word-wrap: break-word;
color: var(--color-text-secondary);
font-size: 13px;
line-height: 1.7;
}
/* Facts list styling */
.facts-list {
list-style: disc;
margin: 0;
padding-left: 20px;
.card-subtitle {
font-size: 14px;
color: var(--color-text-subtitle);
line-height: 1.7;
margin-bottom: 10px;
}
.facts-list li {
margin-bottom: 4px;
}
/* Concepts tags */
.concepts {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.concept-tag {
background: var(--color-type-badge-bg);
color: var(--color-type-badge-text);
padding: 4px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 500;
}
/* File paths */
.file-group {
margin-bottom: 8px;
}
.file-group:last-child {
.card-subtitle:last-child {
margin-bottom: 0;
}
.file-group-label {
font-weight: 500;
margin-bottom: 4px;
color: var(--color-text-primary);
}
.file-path {
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
font-size: 12px;
padding: 4px 8px;
background: var(--color-bg-secondary);
border-radius: 4px;
margin-bottom: 2px;
overflow-x: auto;
white-space: nowrap;
}
/* Session info */
.session-info {
.card-meta {
font-size: 11px;
color: var(--color-text-tertiary);
margin-top: 18px;
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
display: flex;
gap: 16px;
font-size: 12px;
flex-wrap: wrap;
gap: 6px;
line-height: 1.5;
}
.session-id {
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
.meta-date {
color: var(--color-text-tertiary);
}
.meta-concepts {
font-style: italic;
color: var(--color-text-muted);
}
.meta-files {
color: var(--color-text-muted);
font-size: 10px;
}
.meta-files .file-label {
font-weight: 500;
color: var(--color-text-tertiary);
}
/* Stack single column on narrow screens (removed - no longer using card-files) */
@media (max-width: 600px) {
}
/* Project badge styling */
.card-project {
color: var(--color-text-muted);
@@ -864,8 +798,9 @@
}
.card-content {
margin-top: 12px;
line-height: 1.6;
margin-top: 14px;
margin-bottom: 12px;
line-height: 1.7;
color: var(--color-text-primary);
white-space: pre-wrap;
word-wrap: break-word;
+79 -101
View File
@@ -31,7 +31,8 @@ function stripProjectRoot(filePath: string): string {
}
export function ObservationCard({ observation }: ObservationCardProps) {
const [isExpanded, setIsExpanded] = useState(false);
const [showFacts, setShowFacts] = useState(false);
const [showNarrative, setShowNarrative] = useState(false);
const date = formatDate(observation.created_at_epoch);
// Parse JSON fields
@@ -40,117 +41,94 @@ export function ObservationCard({ observation }: ObservationCardProps) {
const filesRead = observation.files_read ? JSON.parse(observation.files_read).map(stripProjectRoot) : [];
const filesModified = observation.files_modified ? JSON.parse(observation.files_modified).map(stripProjectRoot) : [];
// Check if there's verbose content to expand
const hasVerboseContent = observation.narrative || facts.length > 0;
// Show summary when both are off
const showSummary = !showFacts && !showNarrative;
return (
<div className="card">
{/* Header - always visible */}
{/* Header with toggle buttons in top right */}
<div className="card-header">
<span className={`card-type type-${observation.type}`}>
{observation.type}
</span>
<span className="card-project">{observation.project}</span>
</div>
{/* Title/Subtitle - always visible */}
<div className="card-title">{observation.title || 'Untitled'}</div>
{observation.subtitle && (
<div className="card-subtitle">{observation.subtitle}</div>
)}
{/* Metadata + Expand button - always visible */}
<div className="card-meta">
<span>#{observation.id} {date}</span>
{hasVerboseContent && (
<button
className="expand-toggle"
onClick={() => setIsExpanded(!isExpanded)}
>
{isExpanded ? '▲ Less' : '▼ More'}
</button>
)}
</div>
{/* Collapsible verbose content - Narrative and Facts */}
{isExpanded && hasVerboseContent && (
<div className="card-verbose-content">
{/* Narrative Section */}
{observation.narrative && (
<div className="card-section">
<div className="section-header">📝 Narrative</div>
<div className="section-content narrative">
{observation.narrative}
</div>
</div>
)}
{/* Facts Section */}
<div className="card-header-left">
<span className={`card-type type-${observation.type}`}>
{observation.type}
</span>
<span className="card-project">{observation.project}</span>
</div>
<div className="view-mode-toggles">
{facts.length > 0 && (
<div className="card-section">
<div className="section-header">📌 Key Facts</div>
<ul className="section-content facts-list">
{facts.map((fact: string, i: number) => (
<li key={i}>{fact}</li>
))}
</ul>
</div>
<button
className={`view-mode-toggle ${showFacts ? 'active' : ''}`}
onClick={() => {
setShowFacts(!showFacts);
if (!showFacts) setShowNarrative(false); // Turn off narrative when turning on facts
}}
>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<polyline points="9 11 12 14 22 4"></polyline>
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path>
</svg>
<span>facts</span>
</button>
)}
{observation.narrative && (
<button
className={`view-mode-toggle ${showNarrative ? 'active' : ''}`}
onClick={() => {
setShowNarrative(!showNarrative);
if (!showNarrative) setShowFacts(false); // Turn off facts when turning on narrative
}}
>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
</svg>
<span>narrative</span>
</button>
)}
</div>
)}
</div>
{/* Always visible metadata grid - Concepts, Files, Session Info */}
<div className="card-metadata-grid">
{/* Concepts Section */}
{concepts.length > 0 && (
<div className="card-section compact">
<div className="section-header">Concepts</div>
<div className="section-content concepts">
{concepts.map((concept: string, i: number) => (
<span key={i} className="concept-tag">{concept}</span>
))}
</div>
{/* Title */}
<div className="card-title">{observation.title || 'Untitled'}</div>
{/* Content based on toggle state */}
<div className="view-mode-content">
{showSummary && observation.subtitle && (
<div className="card-subtitle">{observation.subtitle}</div>
)}
{showFacts && facts.length > 0 && (
<ul className="facts-list">
{facts.map((fact: string, i: number) => (
<li key={i}>{fact}</li>
))}
</ul>
)}
{showNarrative && observation.narrative && (
<div className="narrative">
{observation.narrative}
</div>
)}
</div>
{/* Session Info Section */}
<div className="card-section compact">
<div className="section-header">Session Info</div>
<div className="section-content session-info">
{observation.prompt_number && (
<span>Prompt #{observation.prompt_number}</span>
)}
{observation.sdk_session_id && (
<span className="session-id">
Session: {observation.sdk_session_id.substring(0, 8)}...
</span>
)}
</div>
</div>
{/* Files Section - spans full width */}
{(filesRead.length > 0 || filesModified.length > 0) && (
<div className="card-section compact files-section">
<div className="section-header">Files</div>
<div className="section-content files">
{filesRead.length > 0 && (
<div className="file-group">
<div className="file-group-label">Read:</div>
{filesRead.map((file: string, i: number) => (
<div key={i} className="file-path">{file}</div>
))}
</div>
)}
{filesModified.length > 0 && (
<div className="file-group">
<div className="file-group-label">Modified:</div>
{filesModified.map((file: string, i: number) => (
<div key={i} className="file-path">{file}</div>
))}
</div>
)}
</div>
</div>
{/* Metadata with concepts and files inline */}
<div className="card-meta">
<span className="meta-date">#{observation.id} {date}</span>
{concepts.length > 0 && (
<span className="meta-concepts">
{concepts.join(', ')}
</span>
)}
{filesRead.length > 0 && (
<span className="meta-files">
<span className="file-label">read:</span> {filesRead.join(', ')}
</span>
)}
{filesModified.length > 0 && (
<span className="meta-files">
<span className="file-label">modified:</span> {filesModified.join(', ')}
</span>
)}
</div>
</div>
+7 -3
View File
@@ -7,17 +7,21 @@ interface PromptCardProps {
}
export function PromptCard({ prompt }: PromptCardProps) {
const date = formatDate(prompt.created_at_epoch);
return (
<div className="card prompt-card">
<div className="card-header">
<span className="card-type">Prompt</span>
<span>{prompt.project}</span>
<div className="card-header-left">
<span className="card-type">Prompt</span>
<span className="card-project">{prompt.project}</span>
</div>
</div>
<div className="card-content">
{prompt.prompt_text}
</div>
<div className="card-meta">
{formatDate(prompt.created_at_epoch)}
<span className="meta-date">#{prompt.id} {date}</span>
</div>
</div>
);
+7 -3
View File
@@ -12,8 +12,10 @@ export function SummaryCard({ summary }: SummaryCardProps) {
return (
<div className="card summary-card">
<div className="card-header">
<span className="card-type">SUMMARY</span>
<span>{summary.project}</span>
<div className="card-header-left">
<span className="card-type">SUMMARY</span>
<span className="card-project">{summary.project}</span>
</div>
</div>
{summary.request && (
<div className="card-title">Request: {summary.request}</div>
@@ -27,7 +29,9 @@ export function SummaryCard({ summary }: SummaryCardProps) {
{summary.next_steps && (
<div className="card-subtitle">Next: {summary.next_steps}</div>
)}
<div className="card-meta">#{summary.id} {date}</div>
<div className="card-meta">
<span className="meta-date">#{summary.id} {date}</span>
</div>
</div>
);
}