diff --git a/Cargo.toml b/Cargo.toml index 9e94a2b..d94c9d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ ssr = [ "katex/duktape", "leptos/ssr", "leptos-use/ssr", - "leptos-use/axum" + "leptos-use/axum", ] hydrate = [ "leptos/hydrate", diff --git a/src/backend/api/instance.rs b/src/backend/api/instance.rs index 55d0c30..6e04ec1 100644 --- a/src/backend/api/instance.rs +++ b/src/backend/api/instance.rs @@ -42,3 +42,11 @@ pub(super) async fn resolve_instance( let instance: DbInstance = ObjectId::from(query.id).dereference(&data).await?; Ok(Json(instance)) } + +#[debug_handler] +pub(in crate::backend::api) async fn list_remote_instances( + data: Data, +) -> MyResult>> { + let instances = DbInstance::read_remote(&data)?; + Ok(Json(instances)) +} diff --git a/src/backend/api/mod.rs b/src/backend/api/mod.rs index 4f12863..f3882c2 100644 --- a/src/backend/api/mod.rs +++ b/src/backend/api/mod.rs @@ -41,6 +41,7 @@ use axum::{ use axum_extra::extract::CookieJar; use axum_macros::debug_handler; use futures::future::try_join_all; +use instance::list_remote_instances; pub mod article; pub mod instance; @@ -60,6 +61,7 @@ pub fn api_routes() -> Router<()> { .route("/instance", get(get_instance)) .route("/instance/follow", post(follow_instance)) .route("/instance/resolve", get(resolve_instance)) + .route("/instance/list", get(list_remote_instances)) .route("/search", get(search_article)) .route("/user", get(get_user)) .route("/account/register", post(register_user)) diff --git a/src/backend/database/instance.rs b/src/backend/database/instance.rs index b2e546c..c740e08 100644 --- a/src/backend/database/instance.rs +++ b/src/backend/database/instance.rs @@ -119,4 +119,11 @@ impl DbInstance { .select(person::all_columns) .get_results(conn.deref_mut())?) } + + pub fn read_remote(data: &Data) -> MyResult> { + let mut conn = data.db_pool.get()?; + Ok(instance::table + .filter(instance::local.eq(false)) + .get_results(conn.deref_mut())?) + } } diff --git a/src/frontend/api.rs b/src/frontend/api.rs index 12419bf..fc665f3 100644 --- a/src/frontend/api.rs +++ b/src/frontend/api.rs @@ -142,6 +142,10 @@ impl ApiClient { self.get_query("/api/v1/instance", Some(get_form)).await } + pub async fn list_instances(&self) -> MyResult> { + self.get_query("/api/v1/instance/list", None::).await + } + pub async fn follow_instance_with_resolve( &self, follow_instance: &str, diff --git a/src/frontend/app.rs b/src/frontend/app.rs index e4f10ba..2ebcaa0 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -15,7 +15,7 @@ use crate::{ }, conflicts::Conflicts, diff::EditDiff, - instance_details::InstanceDetails, + instance::{details::InstanceDetails, list::ListInstances}, login::Login, register::Register, search::Search, @@ -120,6 +120,7 @@ pub fn App() -> impl IntoView { + diff --git a/src/frontend/components/nav.rs b/src/frontend/components/nav.rs index fc8a52d..509d83a 100644 --- a/src/frontend/components/nav.rs +++ b/src/frontend/components/nav.rs @@ -47,7 +47,10 @@ pub fn Nav() -> impl IntoView { "Main Page"
  • - "List Articles" + "Instances" +
  • +
  • + "Articles"
  • diff --git a/src/frontend/pages/instance_details.rs b/src/frontend/pages/instance/details.rs similarity index 100% rename from src/frontend/pages/instance_details.rs rename to src/frontend/pages/instance/details.rs diff --git a/src/frontend/pages/instance/list.rs b/src/frontend/pages/instance/list.rs new file mode 100644 index 0000000..23b27a8 --- /dev/null +++ b/src/frontend/pages/instance/list.rs @@ -0,0 +1,65 @@ +use crate::frontend::app::GlobalState; +use leptos::*; +use url::Url; + +#[component] +pub fn ListInstances() -> impl IntoView { + let instances = create_resource( + move || (), + |_| async move { GlobalState::api_client().list_instances().await.unwrap() }, + ); + + let connect_ibis_wiki = create_action(move |_: &()| async move { + GlobalState::api_client() + .resolve_instance(Url::parse("https://ibis.wiki").unwrap()) + .await + .unwrap(); + instances.refetch(); + }); + let fallback = move || { + view! { +
    + +
    + } + }; + + view! { +

    Instances

    + + +
      + {move || { + instances + .get() + .map(|a| { + a.into_iter() + .map(|i| { + view! { +
    • + + {i.domain} + +
    • + } + }) + .collect::>() + }) + }} + +
    +
    +
    + } +} diff --git a/src/frontend/pages/instance/mod.rs b/src/frontend/pages/instance/mod.rs new file mode 100644 index 0000000..bbd0b02 --- /dev/null +++ b/src/frontend/pages/instance/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod details; +pub(crate) mod list; diff --git a/src/frontend/pages/mod.rs b/src/frontend/pages/mod.rs index d92ece4..76e5080 100644 --- a/src/frontend/pages/mod.rs +++ b/src/frontend/pages/mod.rs @@ -8,7 +8,7 @@ use leptos_router::use_params_map; pub(crate) mod article; pub(crate) mod conflicts; pub(crate) mod diff; -pub(crate) mod instance_details; +pub(crate) mod instance; pub(crate) mod login; pub(crate) mod register; pub(crate) mod search;