forked from alemi/upub
fix(web): scroll to top, refactor, title url, about
This commit is contained in:
parent
8aa80c7670
commit
17d746071b
3 changed files with 34 additions and 17 deletions
|
@ -7,9 +7,9 @@ use leptos_use::{use_cookie, utils::FromToStringCodec};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
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");
|
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 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"));
|
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);
|
let (menu, set_menu) = create_signal(screen_width <= 786);
|
||||||
|
|
||||||
spawn_local(async move {
|
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}");
|
tracing::error!("error populating timeline: {e}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if token.get().is_some() {
|
if auth.get().is_some() {
|
||||||
spawn_local(async move {
|
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}");
|
tracing::error!("error populating timeline: {e}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let title_target = if auth.present() { "/web/home" } else { "/web/server" };
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<nav class="w-100 mt-1 mb-1 pb-s">
|
<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>
|
<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="/web/server" >micro social network, federated</a></small>
|
<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 */
|
/* 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" />
|
<input type="submit" class="mr-2 rev" on:click=move |_| set_menu.set(!menu.get()) value="menu" style="float: right" />
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -44,8 +46,8 @@ pub fn App() -> impl IntoView {
|
||||||
<div class="two-col" >
|
<div class="two-col" >
|
||||||
<div class="col-side sticky" class:hidden=move || menu.get() >
|
<div class="col-side sticky" class:hidden=move || menu.get() >
|
||||||
<LoginBox
|
<LoginBox
|
||||||
token_tx=set_token
|
token_tx=set_auth
|
||||||
token=token
|
token=auth
|
||||||
username_tx=set_username
|
username_tx=set_username
|
||||||
username=username
|
username=username
|
||||||
home_tl=home_tl
|
home_tl=home_tl
|
||||||
|
@ -75,7 +77,7 @@ pub fn App() -> impl IntoView {
|
||||||
<main>
|
<main>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/web" view=move ||
|
<Route path="/web" view=move ||
|
||||||
if token.get().is_some() {
|
if auth.get().is_some() {
|
||||||
view! { <Redirect path="/web/home" /> }
|
view! { <Redirect path="/web/home" /> }
|
||||||
} else {
|
} else {
|
||||||
view! { <Redirect path="/web/server" /> }
|
view! { <Redirect path="/web/server" /> }
|
||||||
|
@ -102,7 +104,7 @@ pub fn App() -> impl IntoView {
|
||||||
<footer>
|
<footer>
|
||||||
<div>
|
<div>
|
||||||
<hr class="sep" />
|
<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>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,13 @@ use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
|
||||||
|
pub type Auth = Signal<Option<String>>;
|
||||||
|
pub trait AuthToken {
|
||||||
|
fn present(&self) -> bool;
|
||||||
|
fn token(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn LoginBox(
|
pub fn LoginBox(
|
||||||
token_tx: WriteSignal<Option<String>>,
|
token_tx: WriteSignal<Option<String>>,
|
||||||
|
@ -84,12 +91,6 @@ struct AuthResponse {
|
||||||
expires: chrono::DateTime<chrono::Utc>,
|
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>> {
|
impl AuthToken for Signal<Option<String>> {
|
||||||
fn token(&self) -> String {
|
fn token(&self) -> String {
|
||||||
match self.get() {
|
match self.get() {
|
||||||
|
|
|
@ -11,6 +11,20 @@ pub fn AboutPage() -> impl IntoView {
|
||||||
<Breadcrumb>about</Breadcrumb>
|
<Breadcrumb>about</Breadcrumb>
|
||||||
<div class="mt-s mb-s" >
|
<div class="mt-s mb-s" >
|
||||||
<p><code>μpub</code>" is a micro social network powered by "<a href="">ActivityPub</a></p>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue