summaryrefslogtreecommitdiffstats
path: root/gui/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/app.rs')
-rw-r--r--gui/src/app.rs57
1 files changed, 44 insertions, 13 deletions
diff --git a/gui/src/app.rs b/gui/src/app.rs
index f9dedaa..8f4d579 100644
--- a/gui/src/app.rs
+++ b/gui/src/app.rs
@@ -11,8 +11,9 @@ use iced::scrollable;
use iced::text_input;
use distrox_lib::profile::Profile;
-use distrox_lib::config::Config;
use crate::timeline::Timeline;
+use crate::timeline::PostLoadingRecipe;
+use crate::post::Post;
#[derive(Debug)]
enum Distrox {
@@ -41,6 +42,11 @@ pub enum Message {
PostCreated(cid::Cid),
PostCreationFailed(String),
+
+ PostLoaded((distrox_lib::types::Payload, String)),
+ PostLoadingFailed,
+
+ TimelineScrolled(f32),
}
impl Application for Distrox {
@@ -52,7 +58,7 @@ impl Application for Distrox {
(
Distrox::Loading,
iced::Command::perform(async move {
- match Profile::load(Config::default(), &name).await {
+ match Profile::load(&name).await {
Err(_) => Message::FailedToLoad,
Ok(instance) => {
Message::Loaded(Arc::new(instance))
@@ -76,7 +82,7 @@ impl Application for Distrox {
scroll: scrollable::State::default(),
input: text_input::State::default(),
input_value: String::default(),
- timeline: Timeline::new()
+ timeline: Timeline::new(),
};
*self = Distrox::Loaded(state);
}
@@ -99,10 +105,10 @@ impl Application for Distrox {
Message::CreatePost => {
if !state.input_value.is_empty() {
- let profile = state.profile.clone();
let input = state.input_value.clone();
+ let client = state.profile.client().clone();
iced::Command::perform(async move {
- profile.client().post_text_blob(input).await
+ client.post_text_blob(input).await
},
|res| match res {
Ok(cid) => Message::PostCreated(cid),
@@ -111,6 +117,18 @@ impl Application for Distrox {
}
}
+ Message::PostLoaded((payload, content)) => {
+ state.timeline.push(payload, content);
+ }
+
+ Message::PostLoadingFailed => {
+ log::error!("Failed to load some post, TODO: Better error logging");
+ }
+
+ Message::TimelineScrolled(f) => {
+ log::trace!("Timeline scrolled: {}", f);
+ }
+
_ => {}
}
}
@@ -149,17 +167,12 @@ impl Application for Distrox {
.size(12)
.on_submit(Message::CreatePost);
- let content = Column::new()
- .max_width(800)
- .spacing(20)
- .push(input)
- .push(state.timeline.view());
+ let timeline = state.timeline.view();
Scrollable::new(&mut state.scroll)
.padding(40)
- .push(
- Container::new(content).width(Length::Fill).center_x(),
- )
+ .push(input)
+ .push(timeline)
.into()
}
@@ -169,6 +182,24 @@ impl Application for Distrox {
}
}
+ fn subscription(&self) -> iced::Subscription<Self::Message> {
+ match self {
+ Distrox::Loaded(state) => {
+ let head = state.profile.head();
+
+ match head {
+ None => iced::Subscription::none(),
+ Some(head) => {
+ iced::Subscription::from_recipe({
+ PostLoadingRecipe::new(state.profile.client().clone(), head.clone())
+ })
+ }
+ }
+ }
+ _ => iced::Subscription::none(),
+ }
+ }
+
}
pub fn run(name: String) -> Result<()> {