hide signup button if registrations closed

This commit is contained in:
Felix Ableitner 2024-02-09 16:04:19 +01:00
parent daa5412271
commit e908d3da33
4 changed files with 22 additions and 8 deletions

View File

@ -15,7 +15,7 @@ use axum_macros::debug_handler;
pub(in crate::backend::api) async fn get_local_instance(
data: Data<IbisData>,
) -> MyResult<Json<InstanceView>> {
let local_instance = DbInstance::read_local_view(&data.db_connection)?;
let local_instance = DbInstance::read_local_view(&data)?;
Ok(Json(local_instance))
}

View File

@ -61,13 +61,14 @@ impl DbInstance {
.get_result(conn.deref_mut())?)
}
pub fn read_local_view(conn: &Mutex<PgConnection>) -> MyResult<InstanceView> {
let instance = DbInstance::read_local_instance(conn)?;
let followers = DbInstance::read_followers(instance.id, conn)?;
pub fn read_local_view(data: &Data<IbisData>) -> MyResult<InstanceView> {
let instance = DbInstance::read_local_instance(&data.db_connection)?;
let followers = DbInstance::read_followers(instance.id, &data.db_connection)?;
Ok(InstanceView {
instance,
followers,
registration_open: data.config.registration_open,
})
}

View File

@ -247,6 +247,7 @@ pub struct DbInstance {
pub struct InstanceView {
pub instance: DbInstance,
pub followers: Vec<DbPerson>,
pub registration_open: bool,
}
#[test]

View File

@ -12,8 +12,18 @@ pub fn Nav() -> impl IntoView {
.get_untracked()
.update_my_profile();
});
let registration_open = create_local_resource(
|| (),
move |_| async move {
GlobalState::api_client()
.get_local_instance()
.await
.unwrap()
.registration_open
},
);
let (search_query, set_search_query) = create_signal(String::new());
// TODO: hide register button if disabled in config
view! {
<nav class="inner">
<li>
@ -62,10 +72,12 @@ pub fn Nav() -> impl IntoView {
<li>
<A href="/login">"Login"</A>
</li>
<Show when=move || registration_open.get().unwrap_or_default()>
<li>
<A href="/register">"Register"</A>
</li>
</Show>
</Show>
</nav>
}
}