1
0
Fork 0
forked from alemi/upub

chore(web): component for tl nav

This commit is contained in:
əlemi 2024-04-16 06:42:02 +02:00
parent f8b135d242
commit 1e6d11b5dc
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 26 additions and 17 deletions

View file

@ -89,6 +89,29 @@ pub fn LoginBox(
} }
} }
#[component]
pub fn TimelineNavigation() -> impl IntoView {
let auth = use_context::<Signal<Option<Auth>>>().expect("missing auth context");
view! {
<a href="/web/home" >
<input class="w-100"
type="submit"
class:hidden=move || !auth.get().present()
class:active=move || use_location().pathname.get().ends_with("/home")
value="home timeline"
/>
</a>
<a href="/web/server" >
<input
class="w-100"
class:active=move || use_location().pathname.get().ends_with("/server")
type="submit"
value="server timeline"
/>
</a>
}
}
#[component] #[component]
pub fn PostBox() -> impl IntoView { pub fn PostBox() -> impl IntoView {
let auth = use_context::<Signal<Option<Auth>>>().expect("missing auth context"); let auth = use_context::<Signal<Option<Auth>>>().expect("missing auth context");

View file

@ -3,7 +3,8 @@ use leptos_router::*;
use leptos_use::{use_cookie, utils::JsonCodec}; use leptos_use::{use_cookie, utils::JsonCodec};
use upub_web::{ use upub_web::{
URL_BASE, context::Timeline, About, Auth, LoginBox, MaybeToken, ObjectPage, PostBox, TimelineFeed, UserPage URL_BASE, context::Timeline, About, Auth, LoginBox, MaybeToken, ObjectPage, PostBox,
TimelineFeed, TimelineNavigation, UserPage
}; };
fn main() { fn main() {
@ -63,22 +64,7 @@ fn main() {
rx=cookie rx=cookie
/> />
<hr class="mt-1 mb-1" /> <hr class="mt-1 mb-1" />
<a href="/web/home" > <TimelineNavigation />
<input class="w-100"
type="submit"
class:hidden=move || !cookie.get().present()
class:active=move || use_location().pathname.get().ends_with("/home")
value="home timeline"
/>
</a>
<a href="/web/server" >
<input
class="w-100"
class:active=move || use_location().pathname.get().ends_with("/server")
type="submit"
value="server timeline"
/>
</a>
<hr class="mt-1 mb-1" /> <hr class="mt-1 mb-1" />
<PostBox /> <PostBox />
</div> </div>