refactor: unify note, post and nav actions

There was a bunch of redundant responses. Let's unify them under
the RenderNavAction enum. We unify all action processing under this
type.

This also centralizes all of our side effects into a single function
instead of scattering them everywhere
This commit is contained in:
William Casarin
2024-11-19 11:07:42 -08:00
parent d97c957e67
commit 7f234935cc
15 changed files with 372 additions and 404 deletions

View File

@@ -1,3 +1,4 @@
use crate::ui::note::PostType;
use std::collections::HashMap;
#[derive(Default)]
@@ -17,6 +18,14 @@ impl Drafts {
&mut self.compose
}
pub fn get_from_post_type(&mut self, post_type: &PostType) -> &mut Draft {
match post_type {
PostType::New => self.compose_mut(),
PostType::Quote(note_id) => self.quote_mut(note_id.bytes()),
PostType::Reply(note_id) => self.reply_mut(note_id.bytes()),
}
}
pub fn reply_mut(&mut self, id: &[u8; 32]) -> &mut Draft {
self.replies.entry(*id).or_default()
}
@@ -26,23 +35,6 @@ impl Drafts {
}
}
pub enum DraftSource<'a> {
Compose,
Reply(&'a [u8; 32]), // note id
Quote(&'a [u8; 32]), // note id
}
/*
impl<'a> DraftSource<'a> {
pub fn draft(&self, drafts: &'a mut Drafts) -> &'a mut Draft {
match self {
DraftSource::Compose => drafts.compose_mut(),
DraftSource::Reply(id) => drafts.reply_mut(id),
}
}
}
*/
impl Draft {
pub fn new() -> Self {
Draft::default()