Skip to main content

orbital_discussion/context/
composer.rs

1use leptos::prelude::*;
2
3use crate::{DiscussionAttachmentDraft, DiscussionReply};
4
5/// Composer draft state shared within a discussion thread.
6#[derive(Clone, Copy)]
7pub struct ComposerContext {
8    pub draft: RwSignal<String>,
9    pub attachment_drafts: RwSignal<Vec<DiscussionAttachmentDraft>>,
10    pub citation_drafts: RwSignal<Vec<crate::DiscussionCitation>>,
11}
12
13impl ComposerContext {
14    pub fn new() -> Self {
15        Self {
16            draft: RwSignal::new(String::new()),
17            attachment_drafts: RwSignal::new(Vec::new()),
18            citation_drafts: RwSignal::new(Vec::new()),
19        }
20    }
21}
22
23impl Default for ComposerContext {
24    fn default() -> Self {
25        Self::new()
26    }
27}
28
29/// Reply target resolved from composer `reply_to` state.
30#[derive(Clone, Copy)]
31pub struct ComposerReplyTarget {
32    pub reply: Signal<Option<DiscussionReply>>,
33}
34
35/// Read the active reply-to target from the nearest composer root.
36pub fn use_composer_reply_target() -> Signal<Option<DiscussionReply>> {
37    expect_context::<ComposerReplyTarget>().reply
38}