Navigate based on person and community ids instead of names
This commit is contained in:
parent
52da877e17
commit
9e4cfe6eee
|
@ -2,9 +2,9 @@ use lemmy_api_common::{community::{GetCommunity, GetCommunityResponse, Community
|
|||
|
||||
use crate::settings;
|
||||
|
||||
pub fn get_community(name: String) -> std::result::Result<GetCommunityResponse, reqwest::Error> {
|
||||
pub fn get_community(id: CommunityId) -> std::result::Result<GetCommunityResponse, reqwest::Error> {
|
||||
let params = GetCommunity {
|
||||
name: Some(name),
|
||||
id: Some(id),
|
||||
auth: settings::get_current_account().jwt,
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use lemmy_api_common::{person::{GetPersonDetailsResponse, GetPersonDetails, GetPersonMentionsResponse, GetRepliesResponse, MarkAllAsRead, GetReplies, GetPersonMentions}, lemmy_db_schema::CommentSortType};
|
||||
use lemmy_api_common::{person::{GetPersonDetailsResponse, GetPersonDetails, GetPersonMentionsResponse, GetRepliesResponse, MarkAllAsRead, GetReplies, GetPersonMentions}, lemmy_db_schema::{CommentSortType, newtypes::PersonId}};
|
||||
|
||||
use crate::settings;
|
||||
|
||||
pub fn get_user(username: String, page: i64) -> std::result::Result<GetPersonDetailsResponse, reqwest::Error> {
|
||||
pub fn get_user(id: PersonId, page: i64) -> std::result::Result<GetPersonDetailsResponse, reqwest::Error> {
|
||||
let params = GetPersonDetails {
|
||||
page: Some(page),
|
||||
username: Some(username),
|
||||
person_id: Some(id),
|
||||
auth: settings::get_current_account().jwt,
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -131,7 +131,7 @@ impl FactoryComponent for CommentRow {
|
|||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
CommentRowMsg::OpenPerson => {
|
||||
sender.output(PostInput::PassAppMessage(crate::AppMsg::OpenPerson(self.comment.creator.name.clone())));
|
||||
sender.output(PostInput::PassAppMessage(crate::AppMsg::OpenPerson(self.comment.creator.id.clone())));
|
||||
}
|
||||
CommentRowMsg::DeleteComment => {
|
||||
let comment_id = self.comment.comment.id;
|
||||
|
|
|
@ -95,7 +95,7 @@ impl FactoryComponent for CommunityRow {
|
|||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
CommunityRowMsg::OpenCommunity => {
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.community.community.name.clone()))
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.community.community.id.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,13 +138,13 @@ impl FactoryComponent for MentionRow {
|
|||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
MentionRowMsg::OpenPerson => {
|
||||
sender.output(crate::AppMsg::OpenPerson(self.comment.creator.name.clone()));
|
||||
sender.output(crate::AppMsg::OpenPerson(self.comment.creator.id.clone()));
|
||||
}
|
||||
MentionRowMsg::OpenPost => {
|
||||
sender.output(crate::AppMsg::OpenPost(self.comment.post.id.clone()));
|
||||
}
|
||||
MentionRowMsg::OpenCommunity => {
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.comment.community.name.clone()));
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.comment.community.id.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,12 +240,12 @@ impl SimpleComponent for PostPage {
|
|||
}
|
||||
}
|
||||
PostInput::OpenPerson => {
|
||||
let name = self.info.post_view.creator.name.clone();
|
||||
let _ = sender.output(crate::AppMsg::OpenPerson(name));
|
||||
let person_id = self.info.post_view.creator.id.clone();
|
||||
let _ = sender.output(crate::AppMsg::OpenPerson(person_id));
|
||||
}
|
||||
PostInput::OpenCommunity => {
|
||||
let community_name = self.info.community_view.community.name.clone();
|
||||
let _ = sender.output(crate::AppMsg::OpenCommunity(community_name));
|
||||
let community_id = self.info.community_view.community.id.clone();
|
||||
let _ = sender.output(crate::AppMsg::OpenCommunity(community_id));
|
||||
}
|
||||
PostInput::OpenLink => {
|
||||
let post = self.info.post_view.post.clone();
|
||||
|
|
|
@ -150,10 +150,10 @@ impl FactoryComponent for PostRow {
|
|||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
PostViewMsg::OpenCommunity => {
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.post.community.name.clone()))
|
||||
sender.output(crate::AppMsg::OpenCommunity(self.post.community.id.clone()))
|
||||
}
|
||||
PostViewMsg::OpenPerson => {
|
||||
sender.output(crate::AppMsg::OpenPerson(self.post.creator.name.clone()))
|
||||
sender.output(crate::AppMsg::OpenPerson(self.post.creator.id.clone()))
|
||||
}
|
||||
PostViewMsg::OpenPost => {
|
||||
sender.output(crate::AppMsg::OpenPost(self.post.post.id.clone()))
|
||||
|
|
19
src/main.rs
19
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}, inbox_page::{InboxPage, InboxInput}};
|
||||
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, ListingType}, 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, CommunityId, PersonId}, ListingType}, post::GetPostResponse, community::GetCommunityResponse};
|
||||
use relm4::{prelude::*, factory::FactoryVecDeque, set_global_css, actions::{RelmAction, RelmActionGroup}};
|
||||
use settings::get_current_account;
|
||||
|
||||
|
@ -58,9 +58,9 @@ pub enum AppMsg {
|
|||
DoneFetchPosts(Vec<PostView>),
|
||||
DoneFetchCommunities(Vec<CommunityView>),
|
||||
FetchCommunities(Option<ListingType>, bool),
|
||||
OpenCommunity(String),
|
||||
OpenCommunity(CommunityId),
|
||||
DoneFetchCommunity(GetCommunityResponse),
|
||||
OpenPerson(String),
|
||||
OpenPerson(PersonId),
|
||||
DoneFetchPerson(GetPersonDetailsResponse),
|
||||
OpenPost(PostId),
|
||||
DoneFetchPost(GetPostResponse),
|
||||
|
@ -241,6 +241,7 @@ impl SimpleComponent for App {
|
|||
set_hexpand: true,
|
||||
set_tooltip_text: Some("Search"),
|
||||
set_margin_end: 10,
|
||||
set_buffer: &model.community_search_buffer,
|
||||
},
|
||||
gtk::Button {
|
||||
set_label: "Search",
|
||||
|
@ -355,8 +356,8 @@ impl SimpleComponent for App {
|
|||
});
|
||||
let profile_sender = sender.clone();
|
||||
let profile_action: RelmAction<ProfileAction> = RelmAction::new_stateless(move |_| {
|
||||
let person = settings::get_current_account().name;
|
||||
if !person.is_empty() { profile_sender.input(AppMsg::OpenPerson(person)); }
|
||||
let person = settings::get_current_account();
|
||||
if !person.name.is_empty() { profile_sender.input(AppMsg::OpenPerson(PersonId(person.id))); }
|
||||
});
|
||||
let login_sender = sender.clone();
|
||||
let login_action: RelmAction<LoginAction> = RelmAction::new_stateless(move |_| {
|
||||
|
@ -438,10 +439,10 @@ impl SimpleComponent for App {
|
|||
self.communities.guard().push_back(community);
|
||||
}
|
||||
}
|
||||
AppMsg::OpenPerson(person_name) => {
|
||||
AppMsg::OpenPerson(person_id) => {
|
||||
self.state = AppState::Loading;
|
||||
std::thread::spawn(move || {
|
||||
let message = match api::user::get_user(person_name, 1) {
|
||||
let message = match api::user::get_user(person_id, 1) {
|
||||
Ok(person) => AppMsg::DoneFetchPerson(person),
|
||||
Err(err) => AppMsg::ShowMessage(err.to_string())
|
||||
};
|
||||
|
@ -452,10 +453,10 @@ impl SimpleComponent for App {
|
|||
self.profile_page.sender().emit(profile_page::ProfileInput::UpdatePerson(person));
|
||||
self.state = AppState::Person;
|
||||
}
|
||||
AppMsg::OpenCommunity(community_name) => {
|
||||
AppMsg::OpenCommunity(community_id) => {
|
||||
self.state = AppState::Loading;
|
||||
std::thread::spawn(move || {
|
||||
let message = match api::community::get_community(community_name) {
|
||||
let message = match api::community::get_community(community_id) {
|
||||
Ok(community) => AppMsg::DoneFetchCommunity(community),
|
||||
Err(err) => AppMsg::ShowMessage(err.to_string())
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue