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( pub(in crate::backend::api) async fn get_local_instance(
data: Data<IbisData>, data: Data<IbisData>,
) -> MyResult<Json<InstanceView>> { ) -> 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)) Ok(Json(local_instance))
} }

View File

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

View File

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

View File

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