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

@@ -1,190 +1,0 @@
1-use leptos::prelude::*;
2-
3-#[allow(unused_imports)]
4-use crate::components::markdown_render::render_markdown;
5-
6-#[cfg(feature = "hydrate")]
7-use serde::Deserialize;
8-
9-/// SSE document update event
10-#[cfg(feature = "hydrate")]
11-#[derive(Deserialize, Clone, Debug)]
12-struct DocumentUpdate {
13- doc_type: String,
14- #[serde(default)]
15- content: Option<String>,
16-}
17-
18-/// Active tab in the document viewer (used in narrow/tabbed mode)
19-#[derive(Clone, Copy, PartialEq)]
20-enum DocTab {
21- Prd,
22- Spec,
23-}
24-
25-/// Document viewer that subscribes to SSE at `/api/documents/stream`
26-/// for live updates as Claude Code writes PRD/Spec files.
27-///
28-/// At narrow widths, PRD and Spec are shown as tabs in a single panel.
29-/// At wide widths (fullscreen), each gets its own column โ€” the parent
30-/// layout switches to 3-column mode via CSS.
31-#[component]
32-pub fn DocumentViewer<FP, FS>(
33- on_prd_change: FP,
34- on_spec_change: FS,
35-) -> impl IntoView
36-where
37- FP: Fn(bool) + Copy + Send + Sync + 'static,
38- FS: Fn(bool) + Copy + Send + Sync + 'static,
39-{
40- let (active_tab, set_active_tab) = signal(DocTab::Prd);
41- let (prd_content, set_prd_content) = signal(String::new());
42- let (spec_content, set_spec_content) = signal(String::new());
43-
44- // Subscribe to document updates via SSE
45- #[cfg(feature = "hydrate")]
46- {
47- Effect::new(move || {
48- leptos::task::spawn_local(async move {
49- use futures::StreamExt as _;
50-
51- let url = "/api/documents/stream";
52- match gloo_net::eventsource::futures::EventSource::new(url) {
53- Ok(mut es) => {
54- let mut stream = es.subscribe("document_update").unwrap();
55-
56- while let Some(Ok((_, msg))) = stream.next().await {
57- if let Some(data_str) = msg.data().as_string() {
58- if let Ok(update) =
59- serde_json::from_str::<DocumentUpdate>(&data_str)
60- {
61- let content = update.content.unwrap_or_default();
62- let has_content = !content.is_empty();
63-
64- match update.doc_type.as_str() {
65- "prd" => {
66- set_prd_content.set(content);
67- on_prd_change(has_content);
68- }
69- "spec" => {
70- set_spec_content.set(content);
71- on_spec_change(has_content);
72- }
73- _ => {}
74- }
75- }
76- }
77- }
78-
79- es.close();
80- }
81- Err(e) => {
82- tracing::error!("Failed to connect to document SSE: {:?}", e);
83- }
84- }
85- });
86- });
87- }
88-
89- let prd_html = move || render_markdown(&prd_content.get());
90- let spec_html = move || render_markdown(&spec_content.get());
91-
92- view! {
93- // Tabbed view for narrow widths โ€” hidden at wide breakpoint
94- <div class="document-viewer doc-tabbed">
95- <div class="doc-tabs">
96- <button
97- class=move || if active_tab.get() == DocTab::Prd { "doc-tab active" } else { "doc-tab" }
98- on:click=move |_| set_active_tab.set(DocTab::Prd)
99- >
100- "PRD"
101- </button>
102- <button
103- class=move || if active_tab.get() == DocTab::Spec { "doc-tab active" } else { "doc-tab" }
104- on:click=move |_| set_active_tab.set(DocTab::Spec)
105- >
106- "Spec"
107- </button>
108- </div>
109-
110- <div class="doc-content">
111- {move || match active_tab.get() {
112- DocTab::Prd => {
113- let html = prd_html();
114- if html.is_empty() {
115- view! {
116- <div class="doc-placeholder">
117- <p>"No PRD yet. Use Claude Code to create one:"</p>
118- <code>"\"Create a PRD for ...\""</code>
119- </div>
120- }.into_any()
121- } else {
122- view! {
123- <div class="markdown-rendered" inner_html=html></div>
124- }.into_any()
125- }
126- }
127- DocTab::Spec => {
128- let html = spec_html();
129- if html.is_empty() {
130- view! {
131- <div class="doc-placeholder">
132- <p>"No Spec yet. Use Claude Code to create one:"</p>
133- <code>"\"Now create the technical spec\""</code>
134- </div>
135- }.into_any()
136- } else {
137- view! {
138- <div class="markdown-rendered" inner_html=html></div>
139- }.into_any()
140- }
141- }
142- }}
143- </div>
144- </div>
145-
146- // PRD column โ€” visible only at wide breakpoint
147- <div class="doc-column doc-column-prd">
148- <div class="doc-column-header">"PRD"</div>
149- <div class="doc-content">
150- {move || {
151- let html = prd_html();
152- if html.is_empty() {
153- view! {
154- <div class="doc-placeholder">
155- <p>"No PRD yet."</p>
156- <code>"\"Create a PRD for ...\""</code>
157- </div>
158- }.into_any()
159- } else {
160- view! {
161- <div class="markdown-rendered" inner_html=html></div>
162- }.into_any()
163- }
164- }}
165- </div>
166- </div>
167-
168- // Spec column โ€” visible only at wide breakpoint
169- <div class="doc-column doc-column-spec">
170- <div class="doc-column-header">"Spec"</div>
171- <div class="doc-content">
172- {move || {
173- let html = spec_html();
174- if html.is_empty() {
175- view! {
176- <div class="doc-placeholder">
177- <p>"No Spec yet."</p>
178- <code>"\"Now create the technical spec\""</code>
179- </div>
180- }.into_any()
181- } else {
182- view! {
183- <div class="markdown-rendered" inner_html=html></div>
184- }.into_any()
185- }
186- }}
187- </div>
188- </div>
189- }
190-}