@kaifronsdal/transcript-viewer
Version:
A web-based viewer for AI conversation transcripts with rollback support
81 lines (67 loc) • 2.95 kB
text/typescript
import { LocalStore } from './localStore.svelte';
import type { FilterState, ViewSettings, TranscriptViewSettings } from './types';
// Homepage filter state
export const filterState = new LocalStore<FilterState>('homepage-filters', {
filterExpression: '',
searchQuery: ''
});
// Homepage view settings
export const viewSettings = new LocalStore<ViewSettings>('homepage-view', {
viewMode: 'tree'
});
// Transcript view settings
export const transcriptViewSettings = new LocalStore<TranscriptViewSettings>('transcript-view-settings', {
selectedView: 'combined', // Default to combined view
showApiFailures: false,
showSharedHistory: false,
showSystemPrompt: false,
availableViews: [] // Will be populated dynamically from transcript data
});
// Custom serializer for Set type
class SetStore extends LocalStore<Set<string>> {
serialize(value: Set<string>): string {
return JSON.stringify(Array.from(value));
}
deserialize(item: string): Set<string> {
return new Set(JSON.parse(item));
}
}
// expandedFolders removed - now handled entirely by TranscriptTable
// Helper function to update available views in transcript view settings
export function updateAvailableViews(views: string[]) {
console.log('=== updateAvailableViews CALLED ===');
const currentSettings = transcriptViewSettings.value;
console.log('Current settings:', currentSettings);
console.log('Input views:', views);
// Add 'raw' as a special view option for debugging, but don't add 'combined' as special
const allViews = [...views, 'raw'].filter((v, i, arr) => arr.indexOf(v) === i).sort();
console.log('All views after processing:', allViews);
// Only update if the available views actually changed to prevent reactive loops
const currentAvailableViews = currentSettings.availableViews;
const viewsChanged = currentAvailableViews.length !== allViews.length ||
!currentAvailableViews.every((view, index) => view === allViews[index]);
if (!viewsChanged) {
console.log('Available views unchanged, skipping update');
console.log('===================================');
return;
}
const newSelectedView = allViews.includes(currentSettings.selectedView)
? currentSettings.selectedView
: (allViews.length > 0 ? allViews[0] : 'raw');
console.log('New selected view will be:', newSelectedView);
// Batch the update to prevent multiple reactive triggers
transcriptViewSettings.value = {
...currentSettings,
availableViews: allViews,
// Reset to first available view if current view is no longer available
selectedView: newSelectedView
};
console.log('Final transcriptViewSettings.value:', transcriptViewSettings.value);
console.log('===================================');
}
// Helper function to initialize all stores (call from components)
export function initializeStores() {
filterState.init();
viewSettings.init();
transcriptViewSettings.init();
}