1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 12:01:08 +00:00

Also show connect button on article page

This commit is contained in:
Felix Ableitner 2024-11-11 11:41:28 +01:00
parent 627b0067b5
commit a099181085
4 changed files with 53 additions and 43 deletions

View file

@ -0,0 +1,25 @@
use crate::frontend::app::GlobalState;
use leptos::{component, *};
use url::Url;
#[component]
pub fn ConnectView<T: Clone + 'static, R: 'static>(res: Resource<T, R>) -> impl IntoView {
let connect_ibis_wiki = create_action(move |_: &()| async move {
GlobalState::api_client()
.resolve_instance(Url::parse("https://ibis.wiki").unwrap())
.await
.unwrap();
res.refetch();
});
view! {
<div class="flex justify-center h-screen">
<button
class="btn btn-primary place-self-center"
on:click=move |_| connect_ibis_wiki.dispatch(())
>
Connect with ibis.wiki
</button>
</div>
}
}

View file

@ -1,4 +1,5 @@
pub mod article_nav; pub mod article_nav;
pub mod connect;
pub mod credentials; pub mod credentials;
pub mod editor; pub mod editor;
pub mod instance_follow_button; pub mod instance_follow_button;

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
common::ListArticlesForm, common::ListArticlesForm,
frontend::{app::GlobalState, article_link, article_title}, frontend::{app::GlobalState, article_link, article_title, components::connect::ConnectView},
}; };
use html::Input; use html::Input;
use leptos::*; use leptos::*;
@ -50,26 +50,31 @@ pub fn ListArticles() -> impl IntoView {
} }
/> />
</div> </div>
<ul class="list-none my-4"> <Show
{move || { when=move || { articles.get().unwrap_or_default().len() > 1 || only_local.get() }
articles fallback=move || view! { <ConnectView res=articles /> }
.get() >
.map(|a| { <ul class="list-none my-4">
a.into_iter() {move || {
.map(|a| { articles
view! { .get()
<li> .map(|a| {
<a class="link text-lg" href=article_link(&a)> a.into_iter()
{article_title(&a)} .map(|a| {
</a> view! {
</li> <li>
} <a class="link text-lg" href=article_link(&a)>
}) {article_title(&a)}
.collect::<Vec<_>>() </a>
}) </li>
}} }
})
.collect::<Vec<_>>()
})
}}
</ul> </ul>
</Show>
</Suspense> </Suspense>
} }
} }

View file

@ -1,6 +1,5 @@
use crate::frontend::app::GlobalState; use crate::frontend::{app::GlobalState, components::connect::ConnectView};
use leptos::*; use leptos::*;
use url::Url;
#[component] #[component]
pub fn ListInstances() -> impl IntoView { pub fn ListInstances() -> impl IntoView {
@ -9,32 +8,12 @@ pub fn ListInstances() -> impl IntoView {
|_| async move { GlobalState::api_client().list_instances().await.unwrap() }, |_| 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! {
<div class="flex justify-center h-screen">
<button
class="btn btn-primary place-self-center"
on:click=move |_| connect_ibis_wiki.dispatch(())
>
Connect with ibis.wiki
</button>
</div>
}
};
view! { view! {
<h1 class="text-4xl font-bold font-serif my-4">Instances</h1> <h1 class="text-4xl font-bold font-serif my-4">Instances</h1>
<Suspense fallback=|| view! { "Loading..." }> <Suspense fallback=|| view! { "Loading..." }>
<Show <Show
when=move || { !instances.get().unwrap_or_default().is_empty() } when=move || { !instances.get().unwrap_or_default().is_empty() }
fallback=fallback fallback=move || view! { <ConnectView res=instances /> }
> >
<ul class="list-none my-4"> <ul class="list-none my-4">
{move || { {move || {