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:
@@ -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,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>
|
||||
);
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user