diff --git a/src/api/posts.rs b/src/api/posts.rs index 244c6a1..3e4bed8 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -1,10 +1,11 @@ -use lemmy_api_common::{post::{GetPostsResponse, GetPosts}, lemmy_db_views::structs::PostView}; +use lemmy_api_common::{post::{GetPostsResponse, GetPosts}, lemmy_db_views::structs::PostView, lemmy_db_schema::ListingType}; use crate::util; -pub fn list_posts(page: i64, community_name: Option) -> std::result::Result, reqwest::Error> { +pub fn list_posts(page: i64, community_name: Option, listing_type: Option) -> std::result::Result, reqwest::Error> { let params = GetPosts { page: Some(page), + type_: listing_type, community_name, auth: util::get_auth_token(), ..Default::default() diff --git a/src/components/community_page.rs b/src/components/community_page.rs index 59cc651..6ae7f40 100644 --- a/src/components/community_page.rs +++ b/src/components/community_page.rs @@ -123,7 +123,7 @@ impl SimpleComponent for CommunityPage { std::thread::spawn(move || { if community.community_view.counts.posts == 0 { return; } - let community_posts = api::posts::list_posts(1, Some(community.community_view.community.name)); + let community_posts = api::posts::list_posts(1, Some(community.community_view.community.name), None); if let Ok(community_posts) = community_posts { sender.input(CommunityInput::DoneFetchPosts(community_posts)); } diff --git a/src/components/post_page.rs b/src/components/post_page.rs index 0ebb012..0e81889 100644 --- a/src/components/post_page.rs +++ b/src/components/post_page.rs @@ -65,6 +65,7 @@ impl SimpleComponent for PostPage { set_margin_top: 10, set_spacing: 10, set_vexpand: false, + set_halign: gtk::Align::Center, gtk::Label { set_text: "posted by " @@ -119,16 +120,12 @@ impl SimpleComponent for PostPage { set_orientation: gtk::Orientation::Horizontal, set_margin_top: 10, set_margin_bottom: 10, + set_halign: gtk::Align::Center, gtk::Label { #[watch] - set_text: &format!("{} comments, ", model.info.post_view.counts.comments), + set_text: &format!("{} comments, {} score", model.info.post_view.counts.comments, model.info.post_view.counts.score), }, - gtk::Label { - #[watch] - set_text: &format!("{} score", model.info.post_view.counts.score), - }, - gtk::Button { set_label: "Comment", set_margin_start: 10, diff --git a/src/main.rs b/src/main.rs index 7d170f1..fa3cac3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ pub mod dialogs; use api::{user::default_person, community::default_community, post::default_post}; use components::{post_row::PostRow, community_row::CommunityRow, profile_page::{ProfilePage, self}, community_page::{CommunityPage, self}, post_page::{PostPage, self}}; use gtk::prelude::*; -use lemmy_api_common::{lemmy_db_views_actor::structs::CommunityView, lemmy_db_views::structs::PostView, person::GetPersonDetailsResponse, lemmy_db_schema::newtypes::PostId, post::GetPostResponse, community::GetCommunityResponse}; +use lemmy_api_common::{lemmy_db_views_actor::structs::CommunityView, lemmy_db_views::structs::PostView, person::GetPersonDetailsResponse, lemmy_db_schema::{newtypes::PostId, ListingType}, post::GetPostResponse, community::GetCommunityResponse}; use relm4::{prelude::*, factory::FactoryVecDeque, set_global_css, actions::{RelmAction, RelmActionGroup}}; static APP_ID: &str = "com.lemmy-gtk.lemoa"; @@ -45,7 +45,7 @@ pub enum AppMsg { Retry, ShowMessage(String), DoneChoosingInstance(String), - StartFetchPosts, + StartFetchPosts(Option), DoneFetchPosts(Vec), DoneFetchCommunities(Vec), ViewCommunities(Option), @@ -76,8 +76,12 @@ impl SimpleComponent for App { set_menu_model: Some(&menu_model), }, pack_start = >k::Button { - set_label: "Posts", - connect_clicked => AppMsg::StartFetchPosts, + set_label: "Recommended", + connect_clicked => AppMsg::StartFetchPosts(None), + }, + pack_start = >k::Button { + set_label: "Subscribed", + connect_clicked => AppMsg::StartFetchPosts(Some(ListingType::Subscribed)), }, pack_start = >k::Button { set_label: "Communities", @@ -160,7 +164,7 @@ impl SimpleComponent for App { gtk::Button { set_label: "Cancel", - connect_clicked => AppMsg::StartFetchPosts, + connect_clicked => AppMsg::StartFetchPosts(None), set_margin_end: 10, }, gtk::Button { @@ -274,7 +278,7 @@ impl SimpleComponent for App { let model = App { state, posts, communities, profile_page, community_page, post_page, message: None, latest_action: None }; // fetch posts if that's the initial page - if !instance_url.is_empty() { sender.input(AppMsg::StartFetchPosts) }; + if !instance_url.is_empty() { sender.input(AppMsg::StartFetchPosts(None)) }; // setup all widgets and different stack pages let posts_box = model.posts.widget(); @@ -315,14 +319,14 @@ impl SimpleComponent for App { preferences.instance_url = instance_url; settings::save_prefs(&preferences); self.state = AppState::Loading; - sender.input(AppMsg::StartFetchPosts); + sender.input(AppMsg::StartFetchPosts(None)); } AppMsg::ChooseInstance => { self.state = AppState::ChooseInstance; } - AppMsg::StartFetchPosts => { + AppMsg::StartFetchPosts(type_) => { std::thread::spawn(move || { - let message = match api::posts::list_posts(1, None) { + let message = match api::posts::list_posts(1, None, type_) { Ok(posts) => AppMsg::DoneFetchPosts(posts), Err(err) => AppMsg::ShowMessage(err.to_string()) }; @@ -406,7 +410,7 @@ impl SimpleComponent for App { Ok(login) => { if let Some(token) = login.jwt { util::set_auth_token(Some(token)); - AppMsg::StartFetchPosts + AppMsg::StartFetchPosts(None) } else { AppMsg::ShowMessage("Wrong credentials!".to_string()) } @@ -424,7 +428,7 @@ impl SimpleComponent for App { self.state = AppState::Message; } AppMsg::Retry => { - sender.input(self.latest_action.clone().unwrap_or(AppMsg::StartFetchPosts)); + sender.input(self.latest_action.clone().unwrap_or(AppMsg::StartFetchPosts(None))); } } }