79ff1849f0
* Add viewer HTML for claude-mem with live stream and settings interface - Implemented a responsive layout with left and right columns for observations and settings. - Added status indicators for connection state. - Integrated server-sent events (SSE) for real-time updates on observations and summaries. - Created dynamic project filter dropdown based on available observations. - Developed settings section for environment variables and worker stats. - Included functionality to save settings and load current stats from the server. - Enhanced UI with custom styles for better user experience. * Remove draft implementation plan for v5.1 web UI * feat: Implement viewer UI with sidebar, feed, and settings management - Add main viewer template (HTML) with styling for dark mode. - Create App component to manage state and render Header, Feed, and Sidebar. - Implement Feed component to display observations and summaries with filtering. - Develop Header component for project selection and connection status. - Create ObservationCard and SummaryCard components for displaying individual items. - Implement Sidebar for settings management and displaying worker/database stats. - Add hooks for managing SSE connections, settings, and stats fetching. - Define types for observations, summaries, settings, and stats. * Enhance UI components and improve layout - Updated padding and layout for the feed and card components in viewer.html, viewer-template.html, and viewer.html to improve visual spacing and alignment. - Increased card margins and padding for better readability and aesthetics. - Adjusted font sizes, weights, and line heights for card titles and subtitles to enhance text clarity and hierarchy. - Added a new feed-content class to center the feed items and limit their maximum width. - Modified the Header component to improve the settings icon's SVG structure for better rendering. - Enhanced the Sidebar component by adding a close button with an SVG icon, improving user experience for closing settings. - Updated the Sidebar component's props to include an onClose function for handling sidebar closure. * feat: Add user prompts feature with UI integration - Implemented a new method in SessionStore to retrieve recent user prompts. - Updated WorkerService to fetch and broadcast user prompts to clients. - Enhanced the Feed component to display user prompts alongside observations and summaries. - Created a new PromptCard component for rendering individual user prompts. - Modified useSSE hook to handle new prompt events and processing status. - Updated viewer templates and styles to accommodate the new prompts feature. * feat: Add project filtering and pagination for observations - Implemented `getAllProjects` method in `SessionStore` to retrieve unique projects from the database. - Added `/api/observations` endpoint in `WorkerService` for paginated observations fetching. - Enhanced `App` component to manage paginated observations and integrate with the new API. - Updated `Feed` component to support infinite scrolling and loading more observations. - Modified `Header` to display processing status. - Refactored `PromptCard` to remove unnecessary processing indicator. - Introduced `usePagination` hook to handle pagination logic for observations. - Updated `useSSE` hook to include projects in the state. - Adjusted types to accommodate new project data. * Refactor viewer build process and remove deprecated HTML template - Updated build-viewer.js to copy HTML template to build output with improved logging. - Removed src/ui/viewer.html as it is no longer needed. - Enhanced App component to merge observations while removing duplicates using useMemo. - Improved Feed component to utilize a ref for onLoadMore callback and adjusted infinite scroll logic. - Updated Sidebar component to use default settings from constants and removed redundant formatting functions. - Refactored usePagination hook to streamline loading logic and prevent concurrent requests. - Updated useSSE hook to use centralized API endpoints and improved reconnection logic. - Refactored useSettings and useStats hooks to utilize constants for API endpoints and timing. - Introduced ErrorBoundary component for better error handling in the viewer. - Centralized API endpoint paths, default settings, timing constants, and UI-related constants into dedicated files. - Added utility functions for formatting uptime and bytes for consistent display across components. * feat: Enhance session management and pagination for user prompts, summaries, and observations - Added project field to user prompts in the database and API responses. - Implemented new API endpoints for fetching summaries and prompts with pagination. - Updated WorkerService to handle new endpoints and filter results by project. - Modified App component to manage paginated data for prompts and summaries. - Refactored Feed component to remove unnecessary filtering and handle combined data. - Improved usePagination hook to support multiple data types and project filtering. - Adjusted useSSE hook to only load projects initially, with data fetched via pagination. - Updated types to include project information for user prompts. * feat: add SummarySkeleton component and data utility for merging items - Introduced SummarySkeleton component for displaying loading state in the UI. - Implemented mergeAndDeduplicateByProject utility function to merge real-time and paginated data while removing duplicates based on project filtering. * Enhance UI and functionality of the viewer component - Updated sidebar transition effects to use translate3d for improved performance. - Added a sidebar header with title and connection status indicators. - Modified the PromptCard to display project name instead of prompt number. - Introduced a GitHub and X (Twitter) link in the header for easy access. - Improved styling for setting descriptions and card hover effects. - Enhanced Sidebar component to include connection status and updated layout. * fix: reduce timeout for worker health checks and ensure proper responsiveness
132 lines
4.5 KiB
TypeScript
132 lines
4.5 KiB
TypeScript
import React, { useMemo, useRef, useEffect } from 'react';
|
|
import { Observation, Summary, UserPrompt, FeedItem } from '../types';
|
|
import { ObservationCard } from './ObservationCard';
|
|
import { SummaryCard } from './SummaryCard';
|
|
import { SummarySkeleton } from './SummarySkeleton';
|
|
import { PromptCard } from './PromptCard';
|
|
import { UI } from '../constants/ui';
|
|
|
|
interface FeedProps {
|
|
observations: Observation[];
|
|
summaries: Summary[];
|
|
prompts: UserPrompt[];
|
|
processingSessions: Set<string>;
|
|
onLoadMore: () => void;
|
|
isLoading: boolean;
|
|
hasMore: boolean;
|
|
}
|
|
|
|
export function Feed({ observations, summaries, prompts, processingSessions, onLoadMore, isLoading, hasMore }: FeedProps) {
|
|
const loadMoreRef = useRef<HTMLDivElement>(null);
|
|
const onLoadMoreRef = useRef(onLoadMore);
|
|
|
|
// Keep the callback ref up to date
|
|
useEffect(() => {
|
|
onLoadMoreRef.current = onLoadMore;
|
|
}, [onLoadMore]);
|
|
|
|
// Set up intersection observer for infinite scroll
|
|
useEffect(() => {
|
|
const element = loadMoreRef.current;
|
|
if (!element) return;
|
|
|
|
const observer = new IntersectionObserver(
|
|
(entries) => {
|
|
const first = entries[0];
|
|
if (first.isIntersecting && hasMore && !isLoading) {
|
|
onLoadMoreRef.current?.();
|
|
}
|
|
},
|
|
{ threshold: UI.LOAD_MORE_THRESHOLD }
|
|
);
|
|
|
|
observer.observe(element);
|
|
|
|
return () => {
|
|
if (element) {
|
|
observer.unobserve(element);
|
|
}
|
|
observer.disconnect();
|
|
};
|
|
}, [hasMore, isLoading]);
|
|
|
|
const items = useMemo<FeedItem[]>(() => {
|
|
// Create a set of session IDs that already have summaries
|
|
const sessionsWithSummaries = new Set(summaries.map(s => s.session_id));
|
|
|
|
// Find the most recent prompt for each processing session
|
|
const sessionPrompts = new Map<string, UserPrompt>();
|
|
prompts.forEach(p => {
|
|
const existing = sessionPrompts.get(p.claude_session_id);
|
|
if (!existing || p.created_at_epoch > existing.created_at_epoch) {
|
|
sessionPrompts.set(p.claude_session_id, p);
|
|
}
|
|
});
|
|
|
|
// Create skeleton items for sessions being processed that don't have summaries yet
|
|
const skeletons: FeedItem[] = [];
|
|
processingSessions.forEach(sessionId => {
|
|
if (!sessionsWithSummaries.has(sessionId)) {
|
|
const prompt = sessionPrompts.get(sessionId);
|
|
skeletons.push({
|
|
itemType: 'skeleton',
|
|
id: sessionId, // Don't add prefix - key construction adds itemType already
|
|
session_id: sessionId,
|
|
project: prompt?.project,
|
|
// Always use current time so skeletons appear at top of feed
|
|
created_at_epoch: Date.now()
|
|
});
|
|
}
|
|
});
|
|
|
|
// Data is already filtered by App.tsx - no need to filter again
|
|
const combined = [
|
|
...observations.map(o => ({ ...o, itemType: 'observation' as const })),
|
|
...summaries.map(s => ({ ...s, itemType: 'summary' as const })),
|
|
...prompts.map(p => ({ ...p, itemType: 'prompt' as const })),
|
|
...skeletons
|
|
];
|
|
|
|
return combined
|
|
.sort((a, b) => b.created_at_epoch - a.created_at_epoch);
|
|
}, [observations, summaries, prompts, processingSessions]);
|
|
|
|
return (
|
|
<div className="feed">
|
|
<div className="feed-content">
|
|
{items.map(item => {
|
|
const key = `${item.itemType}-${item.id}`;
|
|
if (item.itemType === 'observation') {
|
|
return <ObservationCard key={key} observation={item} />;
|
|
} else if (item.itemType === 'summary') {
|
|
return <SummaryCard key={key} summary={item} />;
|
|
} else if (item.itemType === 'skeleton') {
|
|
return <SummarySkeleton key={key} sessionId={item.session_id} project={item.project} />;
|
|
} else {
|
|
return <PromptCard key={key} prompt={item} />;
|
|
}
|
|
})}
|
|
{items.length === 0 && !isLoading && (
|
|
<div style={{ textAlign: 'center', padding: '40px', color: '#8b949e' }}>
|
|
No items to display
|
|
</div>
|
|
)}
|
|
{isLoading && (
|
|
<div style={{ textAlign: 'center', padding: '20px', color: '#8b949e' }}>
|
|
<div className="spinner" style={{ display: 'inline-block', marginRight: '10px' }}></div>
|
|
Loading more...
|
|
</div>
|
|
)}
|
|
{hasMore && !isLoading && items.length > 0 && (
|
|
<div ref={loadMoreRef} style={{ height: '20px', margin: '10px 0' }} />
|
|
)}
|
|
{!hasMore && items.length > 0 && (
|
|
<div style={{ textAlign: 'center', padding: '20px', color: '#8b949e', fontSize: '14px' }}>
|
|
No more items to load
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|