Fully Automated - 100% Backpressure - Pipeline runner ๐Ÿƒ for AI workflows. ๐Ÿš€

Commit 8efc45d6

8efc45d649d4Merged

Scott Nixon <[email protected]> ยท 9 months ago ยท 2 files ยท ~2 modified

Description

[attractor-piu] Update DocumentViewer for project-scoped SSE with cached documents

  • Add project_id prop to DocumentViewer component
  • Load cached documents from SQLite on mount using get_cached_documents()
  • Update SSE URL to include project_id query parameter
  • Fix server/projects.rs module visibility for Leptos client stubs
  • Multiple DocumentViewer instances can now coexist with different projects

Details

Commit
8efc45d649d4
Parent
d40604704c6a

crates/attractor-web/src/components/document_viewer.rsmodifiedView file

@@ -3,6 +3,8 @@
33 #[allow(unused_imports)]
44 use crate::components::markdown_render::render_markdown;
55
6+use crate::server::projects::get_cached_documents;
7+
68 #[cfg(feature = "hydrate")]
79 use serde::Deserialize;
810
@@ -22,14 +24,18 @@
2224 Spec,
2325 }
2426
25-/// Document viewer that subscribes to SSE at `/api/documents/stream`
27+/// Document viewer that subscribes to SSE at `/api/documents/stream?project_id=<id>`
2628 /// for live updates as Claude Code writes PRD/Spec files.
2729 ///
30+/// Loads cached documents from SQLite on mount for instant display, then connects
31+/// to SSE for live updates.
32+///
2833 /// At narrow widths, PRD and Spec are shown as tabs in a single panel.
2934 /// At wide widths (fullscreen), each gets its own column โ€” the parent
3035 /// layout switches to 3-column mode via CSS.
3136 #[component]
3237 pub fn DocumentViewer<FP, FS>(
38+ project_id: i64,
3339 on_prd_change: FP,
3440 on_spec_change: FS,
3541 ) -> impl IntoView
@@ -41,6 +47,23 @@
4147 let (prd_content, set_prd_content) = signal(String::new());
4248 let (spec_content, set_spec_content) = signal(String::new());
4349
50+ // Load cached documents from SQLite on mount
51+ let cached = Resource::new(move || project_id, |id| get_cached_documents(id));
52+
53+ // Update signals when cached data loads
54+ Effect::new(move || {
55+ if let Some(Ok(docs)) = cached.get() {
56+ if let Some(prd) = docs.prd {
57+ set_prd_content.set(prd.clone());
58+ on_prd_change(!prd.is_empty());
59+ }
60+ if let Some(spec) = docs.spec {
61+ set_spec_content.set(spec.clone());
62+ on_spec_change(!spec.is_empty());
63+ }
64+ }
65+ });
66+
4467 // Subscribe to document updates via SSE
4568 #[cfg(feature = "hydrate")]
4669 {
@@ -48,7 +71,7 @@
4871 leptos::task::spawn_local(async move {
4972 use futures::StreamExt as _;
5073
51- let url = "/api/documents/stream";
74+ let url = format!("/api/documents/stream?project_id={}", project_id);
5275 match gloo_net::eventsource::futures::EventSource::new(url) {
5376 Ok(mut es) => {
5477 let mut stream = es.subscribe("document_update").unwrap();