From 766c71fbdb24dc482300fb7eb8685bdaa65f506d Mon Sep 17 00:00:00 2001 From: Ben Floyd Date: Mon, 8 Dec 2025 10:26:25 -0700 Subject: [PATCH] load stream/day on cold start --- .../ComponentLifecycleManager.ts | 22 +++++++++++++++++-- .../EventHandlerService.ts | 7 ++++++ .../calendar-navigation/StreamSelector.ts | 2 ++ src/slices/file-operations/CreateFileView.ts | 4 ++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/slices/calendar-navigation/ComponentLifecycleManager.ts b/src/slices/calendar-navigation/ComponentLifecycleManager.ts index 559534d..4a744bc 100644 --- a/src/slices/calendar-navigation/ComponentLifecycleManager.ts +++ b/src/slices/calendar-navigation/ComponentLifecycleManager.ts @@ -229,8 +229,26 @@ export class ComponentLifecycleManager { // Check if component already exists const existingComponent = this.getComponentForLeaf(leaf); if (existingComponent) { - // Do NOT force update to streamToUse (which might be default) - // Let the component handle its own context via updateStreamContext + // For CreateFileView, we force an update if we have fresh state + // This handles the case where view state is restored after component creation + if (viewType === configurationService.getViewConfig().CREATE_FILE_VIEW_TYPE) { + const view = leaf.view as any; + if (view.getState) { + const state = view.getState(); + if (state) { + if (state.stream) { + existingComponent.updateActiveStream(state.stream); + } + if (state.date) { + const date = new Date(state.date); + if (!isNaN(date.getTime())) { + const dateString = date.toISOString().split('T')[0]; + existingComponent.setCurrentViewedDate(dateString); + } + } + } + } + } return; } diff --git a/src/slices/calendar-navigation/EventHandlerService.ts b/src/slices/calendar-navigation/EventHandlerService.ts index 359aa92..c567ab3 100644 --- a/src/slices/calendar-navigation/EventHandlerService.ts +++ b/src/slices/calendar-navigation/EventHandlerService.ts @@ -89,6 +89,13 @@ export class EventHandlerService { } }); + // Listen for create file view updated + eventBus.subscribe('create-file-view-updated', (event) => { + if (event.data) { + this.handleViewOpened(event.data); + } + }); + // Listen for install meld view opened eventBus.subscribe('install-meld-view-opened', (event) => { if (event.data) { diff --git a/src/slices/calendar-navigation/StreamSelector.ts b/src/slices/calendar-navigation/StreamSelector.ts index 0c4b676..e9c1272 100644 --- a/src/slices/calendar-navigation/StreamSelector.ts +++ b/src/slices/calendar-navigation/StreamSelector.ts @@ -124,6 +124,8 @@ export class StreamSelector extends Component { * Select a stream and navigate to it */ private async selectStream(stream: Stream): Promise { + this.hide(); + // Update the plugin's active stream - REMOVED // if (this.plugin) { // await this.plugin.setActiveStream(stream.id, true, true); diff --git a/src/slices/file-operations/CreateFileView.ts b/src/slices/file-operations/CreateFileView.ts index c55555f..9c64d19 100644 --- a/src/slices/file-operations/CreateFileView.ts +++ b/src/slices/file-operations/CreateFileView.ts @@ -6,6 +6,7 @@ import { FileCreationService } from './FileCreationService'; import { EmptyStateObserver } from './EmptyStateObserver'; import { StreamManager } from '../../shared/interfaces'; import { MeldDetectionService } from '../../slices/meld-integration'; +import { eventBus } from '../../shared/EventBus'; // Interface for accessing app.plugins interface AppWithPlugins extends App { @@ -125,6 +126,9 @@ export class CreateFileView extends ItemView { this.contentEl.addClass('streams-create-file-container'); this.createFileViewContent(this.contentEl); } + + // Emit update event to sync components (like StreamsBarComponent) + eventBus.emit('create-file-view-updated', this.leaf); } } catch (error) { centralizedLogger.error(`Error in CreateFileView setState:`, error);