Navigate based on person and community ids instead of names

This commit is contained in:
Bnyro 2023-06-24 12:53:54 +02:00
parent 52da877e17
commit 9e4cfe6eee
8 changed files with 25 additions and 24 deletions

View File

@ -2,9 +2,9 @@ use lemmy_api_common::{community::{GetCommunity, GetCommunityResponse, Community
use crate::settings; 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 { let params = GetCommunity {
name: Some(name), id: Some(id),
auth: settings::get_current_account().jwt, auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };

View File

@ -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; 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 { let params = GetPersonDetails {
page: Some(page), page: Some(page),
username: Some(username), person_id: Some(id),
auth: settings::get_current_account().jwt, auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };

View File

@ -131,7 +131,7 @@ impl FactoryComponent for CommentRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) { fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message { match message {
CommentRowMsg::OpenPerson => { 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 => { CommentRowMsg::DeleteComment => {
let comment_id = self.comment.comment.id; let comment_id = self.comment.comment.id;

View File

@ -95,7 +95,7 @@ impl FactoryComponent for CommunityRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) { fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message { match message {
CommunityRowMsg::OpenCommunity => { CommunityRowMsg::OpenCommunity => {
sender.output(crate::AppMsg::OpenCommunity(self.community.community.name.clone())) sender.output(crate::AppMsg::OpenCommunity(self.community.community.id.clone()))
} }
} }
} }

View File

@ -138,13 +138,13 @@ impl FactoryComponent for MentionRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) { fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message { match message {
MentionRowMsg::OpenPerson => { MentionRowMsg::OpenPerson => {
sender.output(crate::AppMsg::OpenPerson(self.comment.creator.name.clone())); sender.output(crate::AppMsg::OpenPerson(self.comment.creator.id.clone()));
} }
MentionRowMsg::OpenPost => { MentionRowMsg::OpenPost => {
sender.output(crate::AppMsg::OpenPost(self.comment.post.id.clone())); sender.output(crate::AppMsg::OpenPost(self.comment.post.id.clone()));
} }
MentionRowMsg::OpenCommunity => { MentionRowMsg::OpenCommunity => {
sender.output(crate::AppMsg::OpenCommunity(self.comment.community.name.clone())); sender.output(crate::AppMsg::OpenCommunity(self.comment.community.id.clone()));
} }
} }
} }

View File

@ -240,12 +240,12 @@ impl SimpleComponent for PostPage {
} }
} }
PostInput::OpenPerson => { PostInput::OpenPerson => {
let name = self.info.post_view.creator.name.clone(); let person_id = self.info.post_view.creator.id.clone();
let _ = sender.output(crate::AppMsg::OpenPerson(name)); let _ = sender.output(crate::AppMsg::OpenPerson(person_id));
} }
PostInput::OpenCommunity => { PostInput::OpenCommunity => {
let community_name = self.info.community_view.community.name.clone(); let community_id = self.info.community_view.community.id.clone();
let _ = sender.output(crate::AppMsg::OpenCommunity(community_name)); let _ = sender.output(crate::AppMsg::OpenCommunity(community_id));
} }
PostInput::OpenLink => { PostInput::OpenLink => {
let post = self.info.post_view.post.clone(); let post = self.info.post_view.post.clone();

View File

@ -150,10 +150,10 @@ impl FactoryComponent for PostRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) { fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message { match message {
PostViewMsg::OpenCommunity => { PostViewMsg::OpenCommunity => {
sender.output(crate::AppMsg::OpenCommunity(self.post.community.name.clone())) sender.output(crate::AppMsg::OpenCommunity(self.post.community.id.clone()))
} }
PostViewMsg::OpenPerson => { PostViewMsg::OpenPerson => {
sender.output(crate::AppMsg::OpenPerson(self.post.creator.name.clone())) sender.output(crate::AppMsg::OpenPerson(self.post.creator.id.clone()))
} }
PostViewMsg::OpenPost => { PostViewMsg::OpenPost => {
sender.output(crate::AppMsg::OpenPost(self.post.post.id.clone())) sender.output(crate::AppMsg::OpenPost(self.post.post.id.clone()))

View File

@ -7,7 +7,7 @@ pub mod dialogs;
use api::{user::default_person, community::default_community, post::default_post}; 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 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 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 relm4::{prelude::*, factory::FactoryVecDeque, set_global_css, actions::{RelmAction, RelmActionGroup}};
use settings::get_current_account; use settings::get_current_account;
@ -58,9 +58,9 @@ pub enum AppMsg {
DoneFetchPosts(Vec<PostView>), DoneFetchPosts(Vec<PostView>),
DoneFetchCommunities(Vec<CommunityView>), DoneFetchCommunities(Vec<CommunityView>),
FetchCommunities(Option<ListingType>, bool), FetchCommunities(Option<ListingType>, bool),
OpenCommunity(String), OpenCommunity(CommunityId),
DoneFetchCommunity(GetCommunityResponse), DoneFetchCommunity(GetCommunityResponse),
OpenPerson(String), OpenPerson(PersonId),
DoneFetchPerson(GetPersonDetailsResponse), DoneFetchPerson(GetPersonDetailsResponse),
OpenPost(PostId), OpenPost(PostId),
DoneFetchPost(GetPostResponse), DoneFetchPost(GetPostResponse),
@ -241,6 +241,7 @@ impl SimpleComponent for App {
set_hexpand: true, set_hexpand: true,
set_tooltip_text: Some("Search"), set_tooltip_text: Some("Search"),
set_margin_end: 10, set_margin_end: 10,
set_buffer: &model.community_search_buffer,
}, },
gtk::Button { gtk::Button {
set_label: "Search", set_label: "Search",
@ -355,8 +356,8 @@ impl SimpleComponent for App {
}); });
let profile_sender = sender.clone(); let profile_sender = sender.clone();
let profile_action: RelmAction<ProfileAction> = RelmAction::new_stateless(move |_| { let profile_action: RelmAction<ProfileAction> = RelmAction::new_stateless(move |_| {
let person = settings::get_current_account().name; let person = settings::get_current_account();
if !person.is_empty() { profile_sender.input(AppMsg::OpenPerson(person)); } if !person.name.is_empty() { profile_sender.input(AppMsg::OpenPerson(PersonId(person.id))); }
}); });
let login_sender = sender.clone(); let login_sender = sender.clone();
let login_action: RelmAction<LoginAction> = RelmAction::new_stateless(move |_| { let login_action: RelmAction<LoginAction> = RelmAction::new_stateless(move |_| {
@ -438,10 +439,10 @@ impl SimpleComponent for App {
self.communities.guard().push_back(community); self.communities.guard().push_back(community);
} }
} }
AppMsg::OpenPerson(person_name) => { AppMsg::OpenPerson(person_id) => {
self.state = AppState::Loading; self.state = AppState::Loading;
std::thread::spawn(move || { 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), Ok(person) => AppMsg::DoneFetchPerson(person),
Err(err) => AppMsg::ShowMessage(err.to_string()) 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.profile_page.sender().emit(profile_page::ProfileInput::UpdatePerson(person));
self.state = AppState::Person; self.state = AppState::Person;
} }
AppMsg::OpenCommunity(community_name) => { AppMsg::OpenCommunity(community_id) => {
self.state = AppState::Loading; self.state = AppState::Loading;
std::thread::spawn(move || { 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), Ok(community) => AppMsg::DoneFetchCommunity(community),
Err(err) => AppMsg::ShowMessage(err.to_string()) Err(err) => AppMsg::ShowMessage(err.to_string())
}; };