fix(web): scroll to top, refactor, title url, about

This commit is contained in:
əlemi 2024-04-17 23:07:56 +02:00
parent 8aa80c7670
commit 17d746071b
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 34 additions and 17 deletions

View file

@ -7,9 +7,9 @@ use leptos_use::{use_cookie, utils::FromToStringCodec};
#[component]
pub fn App() -> impl IntoView {
let (token, set_token) = use_cookie::<String, FromToStringCodec>("token");
let (auth, set_auth) = use_cookie::<String, FromToStringCodec>("token");
let (username, set_username) = use_cookie::<String, FromToStringCodec>("username");
provide_context(token);
provide_context(auth);
let home_tl = Timeline::new(format!("{URL_BASE}/users/{}/inbox/page", username.get().unwrap_or_default()));
let server_tl = Timeline::new(format!("{URL_BASE}/inbox/page"));
@ -19,23 +19,25 @@ pub fn App() -> impl IntoView {
let (menu, set_menu) = create_signal(screen_width <= 786);
spawn_local(async move {
if let Err(e) = server_tl.more(token).await {
if let Err(e) = server_tl.more(auth).await {
tracing::error!("error populating timeline: {e}");
}
});
if token.get().is_some() {
if auth.get().is_some() {
spawn_local(async move {
if let Err(e) = home_tl.more(token).await {
if let Err(e) = home_tl.more(auth).await {
tracing::error!("error populating timeline: {e}");
}
});
}
let title_target = if auth.present() { "/web/home" } else { "/web/server" };
view! {
<nav class="w-100 mt-1 mb-1 pb-s">
<code class="color ml-3" ><a class="upub-title" href=move || if token.present() { "/web/home" } else { "/web/server" } >μpub</a></code>
<small class="ml-1 mr-1 hidden-on-tiny" ><a class="clean" href="/web/server" >micro social network, federated</a></small>
<code class="color ml-3" ><a class="upub-title" href={title_target} >μpub</a></code>
<small class="ml-1 mr-1 hidden-on-tiny" ><a class="clean" href={title_target} >micro social network, federated</a></small>
/* TODO kinda jank with the float but whatever, will do for now */
<input type="submit" class="mr-2 rev" on:click=move |_| set_menu.set(!menu.get()) value="menu" style="float: right" />
</nav>
@ -44,8 +46,8 @@ pub fn App() -> impl IntoView {
<div class="two-col" >
<div class="col-side sticky" class:hidden=move || menu.get() >
<LoginBox
token_tx=set_token
token=token
token_tx=set_auth
token=auth
username_tx=set_username
username=username
home_tl=home_tl
@ -75,7 +77,7 @@ pub fn App() -> impl IntoView {
<main>
<Routes>
<Route path="/web" view=move ||
if token.get().is_some() {
if auth.get().is_some() {
view! { <Redirect path="/web/home" /> }
} else {
view! { <Redirect path="/web/server" /> }
@ -102,7 +104,7 @@ pub fn App() -> impl IntoView {
<footer>
<div>
<hr class="sep" />
<span class="footer" >"\u{26fc} woven under moonlight :: "<a href="https://git.alemi.dev/upub.git" target="_blank" >src</a>" :: wip by alemi "</span>
<span class="footer" >"\u{26fc} woven under moonlight :: "<a href="https://git.alemi.dev/upub.git" target="_blank" >src</a>" :: wip by alemi :: "<a href="javascript:window.scrollTo({top:0})">top</a></span>
</div>
</footer>
}

View file

@ -2,6 +2,13 @@ use leptos::*;
use crate::prelude::*;
pub type Auth = Signal<Option<String>>;
pub trait AuthToken {
fn present(&self) -> bool;
fn token(&self) -> String;
}
#[component]
pub fn LoginBox(
token_tx: WriteSignal<Option<String>>,
@ -84,12 +91,6 @@ struct AuthResponse {
expires: chrono::DateTime<chrono::Utc>,
}
pub type Auth = Signal<Option<String>>;
pub trait AuthToken {
fn present(&self) -> bool;
fn token(&self) -> String;
}
impl AuthToken for Signal<Option<String>> {
fn token(&self) -> String {
match self.get() {

View file

@ -11,6 +11,20 @@ pub fn AboutPage() -> impl IntoView {
<Breadcrumb>about</Breadcrumb>
<div class="mt-s mb-s" >
<p><code>μpub</code>" is a micro social network powered by "<a href="">ActivityPub</a></p>
<p><i>"the "<a href="https://en.wikipedia.org/wiki/Fediverse">fediverse</a>" is an ensemble of social networks, which, while independently hosted, can communicate with each other"</i></p>
<p>content is aggregated in timelines, logged out users can only access global server timeline</p>
</div>
</div>
}
}
#[component]
pub fn ConfigPage() -> impl IntoView {
view! {
<div>
<Breadcrumb>config</Breadcrumb>
<div class="mt-s mb-s" >
<p><code>"not implemented :("</code></p>
</div>
</div>
}