mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-15 22:34:19 +01:00
39 lines
754 B
Rust
39 lines
754 B
Rust
use std::collections::HashMap;
|
|
|
|
#[derive(Default)]
|
|
pub struct Draft {
|
|
pub buffer: String,
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub struct Drafts {
|
|
pub replies: HashMap<[u8; 32], Draft>,
|
|
pub compose: Draft,
|
|
}
|
|
|
|
impl Drafts {
|
|
pub fn clear(&mut self, source: DraftSource) {
|
|
source.draft(self).buffer = "".to_string();
|
|
}
|
|
}
|
|
|
|
pub enum DraftSource<'a> {
|
|
Compose,
|
|
Reply(&'a [u8; 32]), // note id
|
|
}
|
|
|
|
impl<'a> DraftSource<'a> {
|
|
pub fn draft(&self, drafts: &'a mut Drafts) -> &'a mut Draft {
|
|
match self {
|
|
DraftSource::Compose => &mut drafts.compose,
|
|
DraftSource::Reply(id) => drafts.replies.entry(**id).or_default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Draft {
|
|
pub fn new() -> Self {
|
|
Draft::default()
|
|
}
|
|
}
|