feat: add a site info dialog

This commit is contained in:
Bnyro 2023-08-07 16:54:56 +02:00
parent c401ca54a2
commit 0540bb3ae2
13 changed files with 2535 additions and 29 deletions

View File

@ -20,7 +20,7 @@ pub fn follow_community(
follow: bool, follow: bool,
) -> Result<CommunityResponse, reqwest::Error> { ) -> Result<CommunityResponse, reqwest::Error> {
let params = FollowCommunity { let params = FollowCommunity {
community_id: community_id, community_id,
follow, follow,
auth: settings::get_current_account().jwt.unwrap(), auth: settings::get_current_account().jwt.unwrap(),
}; };

View File

@ -8,3 +8,7 @@ pub fn fetch_site() -> std::result::Result<GetSiteResponse, reqwest::Error> {
}; };
super::get("/site", &params) super::get("/site", &params)
} }
pub fn default_site_info() -> GetSiteResponse {
serde_json::from_str(include_str!("../examples/site.json")).unwrap()
}

View File

@ -155,7 +155,6 @@ impl SimpleComponent for CommunityPage {
connect_clicked => CommunityInput::FetchPosts, connect_clicked => CommunityInput::FetchPosts,
} }
} }
} }
} }

View File

@ -0,0 +1,22 @@
use relm4::prelude::*;
use gtk::prelude::*;
#[relm4::widget_template(pub)]
impl WidgetTemplate for LoadingIndicator {
view! {
gtk::Box {
set_hexpand: true,
set_orientation: gtk::Orientation::Vertical,
set_spacing: 12,
set_valign: gtk::Align::Center,
set_halign: gtk::Align::Center,
gtk::Spinner {
set_spinning: true,
set_height_request: 80,
},
gtk::Label {
set_text: "Loading",
},
}
}
}

View File

@ -7,6 +7,7 @@ pub mod community_row;
pub mod inbox_page; pub mod inbox_page;
pub mod instance_row; pub mod instance_row;
pub mod instances_page; pub mod instances_page;
pub mod loading_indicator;
pub mod login_page; pub mod login_page;
pub mod mention_row; pub mod mention_row;
pub mod moderates_row; pub mod moderates_row;

View File

@ -60,6 +60,11 @@ impl SimpleComponent for EditorDialog {
set_visible: model.visible, set_visible: model.visible,
set_modal: true, set_modal: true,
connect_close_request[sender] => move |_| {
sender.input(DialogMsg::Hide);
gtk::Inhibit(false)
},
#[wrap(Some)] #[wrap(Some)]
set_child = &gtk::Box { set_child = &gtk::Box {
set_orientation: gtk::Orientation::Vertical, set_orientation: gtk::Orientation::Vertical,
@ -145,11 +150,6 @@ impl SimpleComponent for EditorDialog {
} }
} }
}, },
connect_close_request[sender] => move |_| {
sender.input(DialogMsg::Hide);
gtk::Inhibit(false)
}
} }
} }

View File

@ -1,2 +1,3 @@
pub mod about; pub mod about;
pub mod editor; pub mod editor;
pub mod site_info;

86
src/dialogs/site_info.rs Normal file
View File

@ -0,0 +1,86 @@
use gtk::prelude::*;
use lemmy_api_common::site::GetSiteResponse;
use relm4::prelude::*;
use crate::components::loading_indicator::LoadingIndicator;
use crate::api;
pub struct SiteInfo {
visible: bool,
loading: bool,
site_info: GetSiteResponse,
}
#[derive(Debug)]
pub enum SiteInfoInput {
Fetch,
Update(GetSiteResponse),
Hide,
}
#[relm4::component(pub)]
impl SimpleComponent for SiteInfo {
type Init = ();
type Input = SiteInfoInput;
type Output = crate::AppMsg;
view! {
dialog = gtk::Dialog {
#[watch]
set_visible: model.visible,
set_modal: true,
connect_close_request[sender] => move |_| {
sender.input(SiteInfoInput::Hide);
gtk::Inhibit(false)
},
gtk::Box {
match model.loading {
true => gtk::Box {
#[template]
LoadingIndicator,
}
false => gtk::Box {
}
}
},
}
}
fn init(
_init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self { visible: false, loading: true, site_info: api::site::default_site_info() };
let widgets = view_output!();
ComponentParts { model, widgets }
}
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
match message {
SiteInfoInput::Fetch => {
self.loading = true;
self.visible = true;
std::thread::spawn(move || {
match api::site::fetch_site() {
Ok(site_info) => sender.input(SiteInfoInput::Update(site_info)),
Err(err) => {
sender.output_sender().emit(crate::AppMsg::ShowMessage(err.to_string()));
sender.input_sender().emit(SiteInfoInput::Hide);
}
}
});
}
SiteInfoInput::Update(site_info) => {
self.site_info = site_info;
self.loading = false;
}
SiteInfoInput::Hide => {
self.visible = false;
}
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

379
src/examples/site.json Normal file
View File

@ -0,0 +1,379 @@
{
"site_view": {
"site": {
"id": 1,
"name": "programming.dev",
"sidebar": "# Welcome Programmers\n[programming.dev](https://programming.dev) is a collection of programming communities aimed at topics relevant to software engineers, hackers, hardware and software enthusiasts, script kiddies, cryptographers, researchers, roboticists, and more.\n\nTo begin with this site we will have a limited number of communities. Please visit[/c/community_request](https://programming.dev/c/community_request) to request more communities, and upvote those you see there so we can make a decision on which to choose next. \n\nThe instance is primarily english with some communities in other languages\n\n# Donations \nIf you would like to help support the server you can donate on [@snowe](https://programming.dev/u/snowe)'s [GitHub Sponsors page](https://github.com/sponsors/snowe2010/). We will be setting up a different method to donate later, but for now, we've been getting asked a ton for how to donate. \n\n# Finding Communities\n\nYou can find communities on other instances by using one of the following:\n\n- [lemmyverse](https://lemmyverse.net/)\n- [sub.rehab](https://sub.rehab/?visibleServices=lemmy)\n- [feddit](https://browse.feddit.de/)\n- [redditmigration](https://redditmigration.com/)\n\n### Notice: MAJOR BUG\n\nCurrently there is a major bug with TOTP. Please see the discord #user-help page or the matrix for more information. \n\n",
"published": "2023-06-06T06:35:12.365276",
"updated": "2023-07-29T18:02:56.713573",
"icon": "https://programming.dev/pictrs/image/1e947440-0f0d-4768-ba4b-1480551e7cc9.png",
"banner": "https://programming.dev/pictrs/image/52f986a9-7020-4442-8224-6499d5e84ed2.png",
"description": "A collection of programming communities",
"actor_id": "https://programming.dev/",
"last_refreshed_at": "2023-06-06T06:35:12.362138",
"inbox_url": "https://programming.dev/site_inbox",
"public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtNaplH0kO+ic1Fusl/oS\nTnhReaHPmafik2tsa/YM3jlp2FRjESKPsWMuedvyWQZklSATI3SI0q305vU4fSRM\ncz/r/gjhmE2tlQA9I8qMTAk1LGhutmAcGUeSWxQRmG9DVhHOW9RE/7goPF7q+o+4\nQ1N+FpIsxAeHZDYxDyJQAOdLnmuo/Y5FdueXzG6MV8iiZ0FoCYQ7q41b4PjLzCkY\npPeDaNuMqAD3eHnjLUCBKOYnAxtnAhpFbqyA0JKhWHjDTlwfdrHXQrejaPQutIy/\nYg5rCnMxq6IBefNlr68o2CkRBlmX01N7GJzuIsbRvr/Fdbe+/M/C7aTcnxJt3S4t\nzQIDAQAB\n-----END PUBLIC KEY-----\n",
"instance_id": 1
},
"local_site": {
"id": 1,
"site_id": 1,
"site_setup": true,
"enable_downvotes": true,
"enable_nsfw": true,
"community_creation_admin_only": true,
"require_email_verification": false,
"application_question": "to verify that you are human, please explain why you want to create an account on this site\n\nFor issues join the [discord](https://discord.com/invite/kwyxvYEYt4) or [matrix](https://matrix.to/#/#programming.dev:matrix.org)",
"private_instance": false,
"default_theme": "browser",
"default_post_listing_type": "Local",
"legal_information": "Logo is created using `Fira Code`, used under the OFL-1.1",
"hide_modlog_mod_names": true,
"application_email_admins": false,
"actor_name_max_length": 50,
"federation_enabled": true,
"captcha_enabled": false,
"captcha_difficulty": "medium",
"published": "2023-06-06T06:35:12.436871",
"updated": "2023-07-29T18:02:56.714758",
"registration_mode": "RequireApplication",
"reports_email_admins": true
},
"local_site_rate_limit": {
"id": 1,
"local_site_id": 1,
"message": 999,
"message_per_second": 60,
"post": 999,
"post_per_second": 600,
"register": 999,
"register_per_second": 3600,
"image": 999,
"image_per_second": 3600,
"comment": 999,
"comment_per_second": 600,
"search": 999,
"search_per_second": 600,
"published": "2023-06-06T06:35:12.438204"
},
"counts": {
"id": 1,
"site_id": 1,
"users": 5977,
"posts": 3426,
"comments": 23673,
"communities": 152,
"users_active_day": 191,
"users_active_week": 543,
"users_active_month": 1096,
"users_active_half_year": 1641
}
},
"admins": [
{
"person": {
"id": 2,
"name": "snowe",
"display_name": "snowe",
"avatar": "https://programming.dev/pictrs/image/234e8715-6cb9-465f-ab9b-08bc736f19e9.jpeg",
"banned": false,
"published": "2023-06-06T06:35:11.863885",
"actor_id": "https://programming.dev/u/snowe",
"bio": "I'm a staff software engineer at Sunrun, the USA's largest residential solar installer. \n\nI mostly work with kotlin, but also java, python, ruby, javascript, typescript. My hobby is picking up new hobbies. Currently bird photography and camping. ",
"local": true,
"deleted": false,
"matrix_user_id": "@snowe:matrix.org",
"admin": true,
"bot_account": false,
"instance_id": 1
},
"counts": {
"id": 1,
"person_id": 2,
"post_count": 17,
"post_score": 219,
"comment_count": 273,
"comment_score": 454
}
},
{
"person": {
"id": 6720,
"name": "erlingur",
"display_name": "Erlingur",
"avatar": "https://programming.dev/pictrs/image/b6bbaea7-9e3e-4210-97ca-cbaded5c320f.jpeg",
"banned": false,
"published": "2023-06-08T23:20:19.502444",
"actor_id": "https://programming.dev/u/erlingur",
"local": true,
"deleted": false,
"admin": true,
"bot_account": false,
"instance_id": 1
},
"counts": {
"id": 4998,
"person_id": 6720,
"post_count": 36,
"post_score": 29,
"comment_count": 69,
"comment_score": 93
}
},
{
"person": {
"id": 6861,
"name": "Ategon",
"display_name": "Ategon",
"avatar": "https://programming.dev/pictrs/image/8c68e034-020a-4513-9567-574c26f76a9d.png",
"banned": false,
"published": "2023-06-08T23:54:01.599070",
"actor_id": "https://programming.dev/u/Ategon",
"bio": "Indie game developer 🇨🇦\n\nWorking on some games for game jams in my free time\n\nSocials: https://ategon.carrd.co/",
"local": true,
"banner": "https://programming.dev/pictrs/image/2ba1df13-1d16-4a36-bb88-647b5d4c165c.png",
"deleted": false,
"matrix_user_id": "@ategon:matrix.org",
"admin": true,
"bot_account": false,
"instance_id": 1
},
"counts": {
"id": 5117,
"person_id": 6861,
"post_count": 176,
"post_score": 1207,
"comment_count": 442,
"comment_score": 399
}
},
{
"person": {
"id": 16482,
"name": "nibblebit",
"avatar": "https://programming.dev/pictrs/image/31de4d67-90fd-43cd-9266-d902c14237fd.png",
"banned": false,
"published": "2023-06-10T08:28:18.077456",
"actor_id": "https://programming.dev/u/nibblebit",
"bio": "Azure | .NET | Godot | nibble.blog\n ",
"local": true,
"banner": "https://programming.dev/pictrs/image/83dde52d-0bb6-4f47-8248-d01c6245236e.png",
"deleted": false,
"matrix_user_id": "@nibblebit:matrix.org",
"admin": true,
"bot_account": false,
"instance_id": 1
},
"counts": {
"id": 11496,
"person_id": 16482,
"post_count": 15,
"post_score": 31,
"comment_count": 107,
"comment_score": 100
}
}
],
"version": "0.18.3",
"all_languages": [
{ "id": 0, "code": "und", "name": "Undetermined" },
{ "id": 1, "code": "aa", "name": "Afaraf" },
{ "id": 2, "code": "ab", "name": "аҧсуа бызшәа" },
{ "id": 3, "code": "ae", "name": "avesta" },
{ "id": 4, "code": "af", "name": "Afrikaans" },
{ "id": 5, "code": "ak", "name": "Akan" },
{ "id": 6, "code": "am", "name": "አማርኛ" },
{ "id": 7, "code": "an", "name": "aragonés" },
{ "id": 8, "code": "ar", "name": "اَلْعَرَبِيَّةُ" },
{ "id": 9, "code": "as", "name": "অসমীয়া" },
{ "id": 10, "code": "av", "name": "авар мацӀ" },
{ "id": 11, "code": "ay", "name": "aymar aru" },
{ "id": 12, "code": "az", "name": "azərbaycan dili" },
{ "id": 13, "code": "ba", "name": "башҡорт теле" },
{ "id": 14, "code": "be", "name": "беларуская мова" },
{ "id": 15, "code": "bg", "name": "български език" },
{ "id": 16, "code": "bi", "name": "Bislama" },
{ "id": 17, "code": "bm", "name": "bamanankan" },
{ "id": 18, "code": "bn", "name": "বাংলা" },
{ "id": 19, "code": "bo", "name": "བོད་ཡིག" },
{ "id": 20, "code": "br", "name": "brezhoneg" },
{ "id": 21, "code": "bs", "name": "bosanski jezik" },
{ "id": 22, "code": "ca", "name": "Català" },
{ "id": 23, "code": "ce", "name": "нохчийн мотт" },
{ "id": 24, "code": "ch", "name": "Chamoru" },
{ "id": 25, "code": "co", "name": "corsu" },
{ "id": 26, "code": "cr", "name": "ᓀᐦᐃᔭᐍᐏᐣ" },
{ "id": 27, "code": "cs", "name": "čeština" },
{ "id": 28, "code": "cu", "name": "ѩзыкъ словѣньскъ" },
{ "id": 29, "code": "cv", "name": "чӑваш чӗлхи" },
{ "id": 30, "code": "cy", "name": "Cymraeg" },
{ "id": 31, "code": "da", "name": "dansk" },
{ "id": 32, "code": "de", "name": "Deutsch" },
{ "id": 33, "code": "dv", "name": "ދިވެހި" },
{ "id": 34, "code": "dz", "name": "རྫོང་ཁ" },
{ "id": 35, "code": "ee", "name": "Eʋegbe" },
{ "id": 36, "code": "el", "name": "Ελληνικά" },
{ "id": 37, "code": "en", "name": "English" },
{ "id": 38, "code": "eo", "name": "Esperanto" },
{ "id": 39, "code": "es", "name": "Español" },
{ "id": 40, "code": "et", "name": "eesti" },
{ "id": 41, "code": "eu", "name": "euskara" },
{ "id": 42, "code": "fa", "name": "فارسی" },
{ "id": 43, "code": "ff", "name": "Fulfulde" },
{ "id": 44, "code": "fi", "name": "suomi" },
{ "id": 45, "code": "fj", "name": "vosa Vakaviti" },
{ "id": 46, "code": "fo", "name": "føroyskt" },
{ "id": 47, "code": "fr", "name": "Français" },
{ "id": 48, "code": "fy", "name": "Frysk" },
{ "id": 49, "code": "ga", "name": "Gaeilge" },
{ "id": 50, "code": "gd", "name": "Gàidhlig" },
{ "id": 51, "code": "gl", "name": "galego" },
{ "id": 52, "code": "gn", "name": "Avañe'ẽ" },
{ "id": 53, "code": "gu", "name": "ગુજરાતી" },
{ "id": 54, "code": "gv", "name": "Gaelg" },
{ "id": 55, "code": "ha", "name": "هَوُسَ" },
{ "id": 56, "code": "he", "name": "עברית" },
{ "id": 57, "code": "hi", "name": "हिन्दी" },
{ "id": 58, "code": "ho", "name": "Hiri Motu" },
{ "id": 59, "code": "hr", "name": "Hrvatski" },
{ "id": 60, "code": "ht", "name": "Kreyòl ayisyen" },
{ "id": 61, "code": "hu", "name": "magyar" },
{ "id": 62, "code": "hy", "name": "Հայերեն" },
{ "id": 63, "code": "hz", "name": "Otjiherero" },
{ "id": 64, "code": "ia", "name": "Interlingua" },
{ "id": 65, "code": "id", "name": "Bahasa Indonesia" },
{ "id": 66, "code": "ie", "name": "Interlingue" },
{ "id": 67, "code": "ig", "name": "Asụsụ Igbo" },
{ "id": 68, "code": "ii", "name": "ꆈꌠ꒿ Nuosuhxop" },
{ "id": 69, "code": "ik", "name": "Iñupiaq" },
{ "id": 70, "code": "io", "name": "Ido" },
{ "id": 71, "code": "is", "name": "Íslenska" },
{ "id": 72, "code": "it", "name": "Italiano" },
{ "id": 73, "code": "iu", "name": "ᐃᓄᒃᑎᑐᑦ" },
{ "id": 74, "code": "ja", "name": "日本語" },
{ "id": 75, "code": "jv", "name": "basa Jawa" },
{ "id": 76, "code": "ka", "name": "ქართული" },
{ "id": 77, "code": "kg", "name": "Kikongo" },
{ "id": 78, "code": "ki", "name": "Gĩkũyũ" },
{ "id": 79, "code": "kj", "name": "Kuanyama" },
{ "id": 80, "code": "kk", "name": "қазақ тілі" },
{ "id": 81, "code": "kl", "name": "kalaallisut" },
{ "id": 82, "code": "km", "name": "ខេមរភាសា" },
{ "id": 83, "code": "kn", "name": "ಕನ್ನಡ" },
{ "id": 84, "code": "ko", "name": "한국어" },
{ "id": 85, "code": "kr", "name": "Kanuri" },
{ "id": 86, "code": "ks", "name": "कश्मीरी" },
{ "id": 87, "code": "ku", "name": "Kurdî" },
{ "id": 88, "code": "kv", "name": "коми кыв" },
{ "id": 89, "code": "kw", "name": "Kernewek" },
{ "id": 90, "code": "ky", "name": "Кыргызча" },
{ "id": 91, "code": "la", "name": "latine" },
{ "id": 92, "code": "lb", "name": "Lëtzebuergesch" },
{ "id": 93, "code": "lg", "name": "Luganda" },
{ "id": 94, "code": "li", "name": "Limburgs" },
{ "id": 95, "code": "ln", "name": "Lingála" },
{ "id": 96, "code": "lo", "name": "ພາສາລາວ" },
{ "id": 97, "code": "lt", "name": "lietuvių kalba" },
{ "id": 98, "code": "lu", "name": "Kiluba" },
{ "id": 99, "code": "lv", "name": "latviešu valoda" },
{ "id": 100, "code": "mg", "name": "fiteny malagasy" },
{ "id": 101, "code": "mh", "name": "Kajin M̧ajeļ" },
{ "id": 102, "code": "mi", "name": "te reo Māori" },
{ "id": 103, "code": "mk", "name": "македонски јазик" },
{ "id": 104, "code": "ml", "name": "മലയാളം" },
{ "id": 105, "code": "mn", "name": "Монгол хэл" },
{ "id": 106, "code": "mr", "name": "मराठी" },
{ "id": 107, "code": "ms", "name": "Bahasa Melayu" },
{ "id": 108, "code": "mt", "name": "Malti" },
{ "id": 109, "code": "my", "name": "ဗမာစာ" },
{ "id": 110, "code": "na", "name": "Dorerin Naoero" },
{ "id": 111, "code": "nb", "name": "Norsk bokmål" },
{ "id": 112, "code": "nd", "name": "isiNdebele" },
{ "id": 113, "code": "ne", "name": "नेपाली" },
{ "id": 114, "code": "ng", "name": "Owambo" },
{ "id": 115, "code": "nl", "name": "Nederlands" },
{ "id": 116, "code": "nn", "name": "Norsk nynorsk" },
{ "id": 117, "code": "no", "name": "Norsk" },
{ "id": 118, "code": "nr", "name": "isiNdebele" },
{ "id": 119, "code": "nv", "name": "Diné bizaad" },
{ "id": 120, "code": "ny", "name": "chiCheŵa" },
{ "id": 121, "code": "oc", "name": "occitan" },
{ "id": 122, "code": "oj", "name": "ᐊᓂᔑᓈᐯᒧᐎᓐ" },
{ "id": 123, "code": "om", "name": "Afaan Oromoo" },
{ "id": 124, "code": "or", "name": "ଓଡ଼ିଆ" },
{ "id": 125, "code": "os", "name": "ирон æвзаг" },
{ "id": 126, "code": "pa", "name": "ਪੰਜਾਬੀ" },
{ "id": 127, "code": "pi", "name": "पाऴि" },
{ "id": 128, "code": "pl", "name": "Polski" },
{ "id": 129, "code": "ps", "name": "پښتو" },
{ "id": 130, "code": "pt", "name": "Português" },
{ "id": 131, "code": "qu", "name": "Runa Simi" },
{ "id": 132, "code": "rm", "name": "rumantsch grischun" },
{ "id": 133, "code": "rn", "name": "Ikirundi" },
{ "id": 134, "code": "ro", "name": "Română" },
{ "id": 135, "code": "ru", "name": "Русский" },
{ "id": 136, "code": "rw", "name": "Ikinyarwanda" },
{ "id": 137, "code": "sa", "name": "संस्कृतम्" },
{ "id": 138, "code": "sc", "name": "sardu" },
{ "id": 139, "code": "sd", "name": "सिन्धी" },
{ "id": 140, "code": "se", "name": "Davvisámegiella" },
{ "id": 141, "code": "sg", "name": "yângâ tî sängö" },
{ "id": 142, "code": "si", "name": "සිංහල" },
{ "id": 143, "code": "sk", "name": "slovenčina" },
{ "id": 144, "code": "sl", "name": "slovenščina" },
{ "id": 145, "code": "sm", "name": "gagana fa'a Samoa" },
{ "id": 146, "code": "sn", "name": "chiShona" },
{ "id": 147, "code": "so", "name": "Soomaaliga" },
{ "id": 148, "code": "sq", "name": "Shqip" },
{ "id": 149, "code": "sr", "name": "српски језик" },
{ "id": 150, "code": "ss", "name": "SiSwati" },
{ "id": 151, "code": "st", "name": "Sesotho" },
{ "id": 152, "code": "su", "name": "Basa Sunda" },
{ "id": 153, "code": "sv", "name": "Svenska" },
{ "id": 154, "code": "sw", "name": "Kiswahili" },
{ "id": 155, "code": "ta", "name": "தமிழ்" },
{ "id": 156, "code": "te", "name": "తెలుగు" },
{ "id": 157, "code": "tg", "name": "тоҷикӣ" },
{ "id": 158, "code": "th", "name": "ไทย" },
{ "id": 159, "code": "ti", "name": "ትግርኛ" },
{ "id": 160, "code": "tk", "name": "Türkmençe" },
{ "id": 161, "code": "tl", "name": "Wikang Tagalog" },
{ "id": 162, "code": "tn", "name": "Setswana" },
{ "id": 163, "code": "to", "name": "faka Tonga" },
{ "id": 164, "code": "tr", "name": "Türkçe" },
{ "id": 165, "code": "ts", "name": "Xitsonga" },
{ "id": 166, "code": "tt", "name": "татар теле" },
{ "id": 167, "code": "tw", "name": "Twi" },
{ "id": 168, "code": "ty", "name": "Reo Tahiti" },
{ "id": 169, "code": "ug", "name": "ئۇيغۇرچە‎" },
{ "id": 170, "code": "uk", "name": "Українська" },
{ "id": 171, "code": "ur", "name": "اردو" },
{ "id": 172, "code": "uz", "name": "Ўзбек" },
{ "id": 173, "code": "ve", "name": "Tshivenḓa" },
{ "id": 174, "code": "vi", "name": "Tiếng Việt" },
{ "id": 175, "code": "vo", "name": "Volapük" },
{ "id": 176, "code": "wa", "name": "walon" },
{ "id": 177, "code": "wo", "name": "Wollof" },
{ "id": 178, "code": "xh", "name": "isiXhosa" },
{ "id": 179, "code": "yi", "name": "ייִדיש" },
{ "id": 180, "code": "yo", "name": "Yorùbá" },
{ "id": 181, "code": "za", "name": "Saɯ cueŋƅ" },
{ "id": 182, "code": "zh", "name": "中文" },
{ "id": 183, "code": "zu", "name": "isiZulu" }
],
"discussion_languages": [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183
],
"taglines": [],
"custom_emojis": []
}

View File

@ -12,11 +12,12 @@ use components::{
community_page::{self, CommunityPage}, community_page::{self, CommunityPage},
inbox_page::{InboxInput, InboxPage}, inbox_page::{InboxInput, InboxPage},
instances_page::{InstancesPage, InstancesPageInput}, instances_page::{InstancesPage, InstancesPageInput},
loading_indicator::LoadingIndicator,
post_page::{self, PostPage}, post_page::{self, PostPage},
posts_page::{PostsPage, PostsPageInput}, posts_page::{PostsPage, PostsPageInput},
profile_page::{ProfileInput, ProfilePage}, profile_page::{ProfileInput, ProfilePage},
}; };
use dialogs::about::AboutDialog; use dialogs::{about::AboutDialog, site_info::{SiteInfo, SiteInfoInput}};
use gtk::prelude::*; use gtk::prelude::*;
use lemmy_api_common::{ use lemmy_api_common::{
community::GetCommunityResponse, community::GetCommunityResponse,
@ -64,8 +65,9 @@ struct App {
login_page: Controller<LoginPage>, login_page: Controller<LoginPage>,
accounts_page: Controller<AccountsPage>, accounts_page: Controller<AccountsPage>,
saved_page: Controller<ProfilePage>, saved_page: Controller<ProfilePage>,
logged_in: bool,
about_dialog: Controller<AboutDialog>, about_dialog: Controller<AboutDialog>,
site_info: Controller<SiteInfo>,
logged_in: bool,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -139,18 +141,8 @@ impl SimpleComponent for App {
posts_page -> gtk::ScrolledWindow {} posts_page -> gtk::ScrolledWindow {}
} }
AppState::Loading => gtk::Box { AppState::Loading => gtk::Box {
set_hexpand: true, #[template]
set_orientation: gtk::Orientation::Vertical, LoadingIndicator,
set_spacing: 12,
set_valign: gtk::Align::Center,
set_halign: gtk::Align::Center,
gtk::Spinner {
set_spinning: true,
set_height_request: 80,
},
gtk::Label {
set_text: "Loading",
},
} }
AppState::ChooseInstance => gtk::Box { AppState::ChooseInstance => gtk::Box {
#[local_ref] #[local_ref]
@ -226,6 +218,7 @@ impl SimpleComponent for App {
"Accounts" => AccountsAction, "Accounts" => AccountsAction,
"Login" => LoginAction, "Login" => LoginAction,
"Profile" => ProfileAction, "Profile" => ProfileAction,
"Site Info" => SiteInfoAction,
"About" => AboutAction "About" => AboutAction
} }
} }
@ -278,11 +271,14 @@ impl SimpleComponent for App {
let saved_page = ProfilePage::builder() let saved_page = ProfilePage::builder()
.launch((default_person(), true)) .launch((default_person(), true))
.forward(sender.input_sender(), |msg| msg); .forward(sender.input_sender(), |msg| msg);
let site_info = SiteInfo::builder()
.transient_for(root)
.launch(())
.forward(sender.input_sender(), |msg| msg);
let model = App { let model = App {
state, state,
back_queue: vec![], back_queue: vec![],
logged_in,
posts_page, posts_page,
instances_page, instances_page,
profile_page, profile_page,
@ -295,6 +291,8 @@ impl SimpleComponent for App {
message: None, message: None,
about_dialog, about_dialog,
saved_page, saved_page,
site_info,
logged_in,
}; };
// fetch posts if that's the initial page // fetch posts if that's the initial page
@ -333,9 +331,16 @@ impl SimpleComponent for App {
profile_sender.input(AppMsg::OpenPerson(PersonId(person.id))); profile_sender.input(AppMsg::OpenPerson(PersonId(person.id)));
} }
}); });
let sender = sender.clone();
let login_action: RelmAction<LoginAction> = RelmAction::new_stateless(move |_| { let login_action: RelmAction<LoginAction> = RelmAction::new_stateless(move |_| {
sender.input(AppMsg::UpdateState(AppState::Login)); sender.input(AppMsg::UpdateState(AppState::Login));
}); });
let site_info_action: RelmAction<SiteInfoAction> = {
let sender = model.site_info.sender().clone();
RelmAction::new_stateless(move |_| {
sender.emit(SiteInfoInput::Fetch);
})
};
let about_action = { let about_action = {
let sender = model.about_dialog.sender().clone(); let sender = model.about_dialog.sender().clone();
RelmAction::<AboutAction>::new_stateless(move |_| { RelmAction::<AboutAction>::new_stateless(move |_| {
@ -348,6 +353,7 @@ impl SimpleComponent for App {
group.add_action(accounts_action); group.add_action(accounts_action);
group.add_action(profile_action); group.add_action(profile_action);
group.add_action(login_action); group.add_action(login_action);
group.add_action(site_info_action);
group.add_action(about_action); group.add_action(about_action);
group.register_for_widget(&widgets.main_window); group.register_for_widget(&widgets.main_window);
@ -462,10 +468,11 @@ impl SimpleComponent for App {
AppMsg::UpdateState(state) => { AppMsg::UpdateState(state) => {
self.state = state; self.state = state;
} }
AppMsg::OpenPosts => self AppMsg::OpenPosts => self.posts_page.sender().emit(PostsPageInput::FetchPosts(
.posts_page ListingType::Local,
.sender() SortType::Hot,
.emit(PostsPageInput::FetchPosts(ListingType::Local, SortType::Hot, true)), true,
)),
} }
} }
} }
@ -475,6 +482,7 @@ relm4::new_stateless_action!(ChangeInstanceAction, WindowActionGroup, "instance"
relm4::new_stateless_action!(AccountsAction, WindowActionGroup, "accounts"); relm4::new_stateless_action!(AccountsAction, WindowActionGroup, "accounts");
relm4::new_stateless_action!(LoginAction, WindowActionGroup, "login"); relm4::new_stateless_action!(LoginAction, WindowActionGroup, "login");
relm4::new_stateless_action!(ProfileAction, WindowActionGroup, "profile"); relm4::new_stateless_action!(ProfileAction, WindowActionGroup, "profile");
relm4::new_stateless_action!(SiteInfoAction, WindowActionGroup, "site_info");
relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about"); relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about");
fn main() { fn main() {