2024-04-16 06:34:50 +02:00
|
|
|
use leptos::{leptos_dom::logging::console_error, *};
|
2024-04-15 01:56:33 +02:00
|
|
|
use leptos_router::*;
|
2024-04-14 06:45:51 +02:00
|
|
|
|
2024-04-17 03:12:17 +02:00
|
|
|
use leptos_use::{use_cookie, utils::FromToStringCodec};
|
2024-04-14 06:45:51 +02:00
|
|
|
use upub_web::{
|
2024-04-17 03:12:17 +02:00
|
|
|
URL_BASE, context::Timeline, About, LoginBox, MaybeToken, ObjectPage, PostBox,
|
2024-04-16 08:02:03 +02:00
|
|
|
TimelinePage, TimelineNavigation, UserPage
|
2024-04-14 06:45:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
2024-04-16 08:26:56 +02:00
|
|
|
_ = console_log::init_with_level(log::Level::Info);
|
2024-04-14 06:45:51 +02:00
|
|
|
console_error_panic_hook::set_once();
|
2024-04-17 03:12:17 +02:00
|
|
|
let (cookie, set_cookie) = use_cookie::<String, FromToStringCodec>("token");
|
|
|
|
let (username, set_username) = use_cookie::<String, FromToStringCodec>("username");
|
2024-04-16 06:34:50 +02:00
|
|
|
provide_context(cookie);
|
|
|
|
|
2024-04-17 03:12:17 +02:00
|
|
|
let home_tl = Timeline::new(format!("{URL_BASE}/users/{}/inbox/page", username.get().unwrap_or_default()));
|
2024-04-16 06:34:50 +02:00
|
|
|
let server_tl = Timeline::new(format!("{URL_BASE}/inbox/page"));
|
|
|
|
|
2024-04-17 05:39:45 +02:00
|
|
|
let (menu, set_menu) = create_signal(false);
|
|
|
|
|
2024-04-16 06:34:50 +02:00
|
|
|
spawn_local(async move {
|
|
|
|
if let Err(e) = server_tl.more(cookie).await {
|
|
|
|
console_error(&format!("error populating timeline: {e}"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if cookie.get().is_some() {
|
|
|
|
spawn_local(async move {
|
|
|
|
if let Err(e) = home_tl.more(cookie).await {
|
|
|
|
console_error(&format!("error populating timeline: {e}"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-14 06:45:51 +02:00
|
|
|
mount_to_body(
|
|
|
|
move || view! {
|
2024-04-17 04:33:34 +02:00
|
|
|
<nav class="w-100 mt-1 mb-1 pb-s">
|
|
|
|
<code class="color ml-3" ><a class="upub-title" href=move || if cookie.get().present() { "/web/home" } else { "/web/server" } >μpub</a></code>
|
|
|
|
<small class="ml-1 mr-1" ><a class="clean" href="/web/server" >micro social network, federated</a></small>
|
|
|
|
/* TODO kinda jank with the float but whatever, will do for now */
|
2024-04-17 05:39:45 +02:00
|
|
|
<input type="submit" class="mr-2 rev" on:click=move |_| set_menu.set(!menu.get()) value="menu" style="float: right" />
|
2024-04-14 06:45:51 +02:00
|
|
|
</nav>
|
2024-04-17 05:39:45 +02:00
|
|
|
<hr class="sep" />
|
2024-04-17 04:33:34 +02:00
|
|
|
<div class="container mt-2 pt-2" >
|
2024-04-16 06:34:50 +02:00
|
|
|
<Router // TODO maybe set base="/web" ?
|
2024-04-16 08:19:09 +02:00
|
|
|
trailing_slash=TrailingSlash::Redirect
|
2024-04-16 06:34:50 +02:00
|
|
|
fallback=move || view! {
|
|
|
|
<div class="center">
|
|
|
|
<h3>nothing to see here!</h3>
|
|
|
|
<p><a href="/web"><button type="button">back to root</button></a></p>
|
|
|
|
</div>
|
|
|
|
}.into_view()
|
|
|
|
>
|
|
|
|
// TODO this is kind of ugly: the whole router gets rebuilt every time we log in/out
|
|
|
|
// in a sense it's what we want: refreshing the home tl is main purpose, but also
|
|
|
|
// server tl may contain stuff we can no longer see, or otherwise we may now be
|
|
|
|
// entitled to see new posts. so while being ugly it's techically correct ig?
|
|
|
|
{move || {
|
|
|
|
view! {
|
2024-04-15 01:56:33 +02:00
|
|
|
<main>
|
2024-04-16 06:34:50 +02:00
|
|
|
<div class="two-col" >
|
2024-04-17 05:39:45 +02:00
|
|
|
<div class="col-side sticky" class:hidden=move || menu.get() >
|
2024-04-16 06:34:50 +02:00
|
|
|
<LoginBox
|
2024-04-17 03:12:17 +02:00
|
|
|
token_tx=set_cookie
|
|
|
|
token=cookie
|
|
|
|
username_tx=set_username
|
|
|
|
username=username
|
|
|
|
home_tl=home_tl
|
2024-04-16 06:34:50 +02:00
|
|
|
/>
|
|
|
|
<hr class="mt-1 mb-1" />
|
2024-04-16 06:42:02 +02:00
|
|
|
<TimelineNavigation />
|
2024-04-16 06:34:50 +02:00
|
|
|
<hr class="mt-1 mb-1" />
|
|
|
|
<PostBox />
|
|
|
|
</div>
|
2024-04-17 05:39:45 +02:00
|
|
|
<div class="col-main" class:w-100=move || menu.get() >
|
2024-04-16 06:34:50 +02:00
|
|
|
<Routes>
|
|
|
|
<Route path="/web" view=About />
|
|
|
|
|
2024-04-16 08:02:03 +02:00
|
|
|
<Route path="/web/home" view=move || view! { <TimelinePage name="home" tl=home_tl /> } />
|
|
|
|
<Route path="/web/server" view=move || view! { <TimelinePage name="server" tl=server_tl /> } />
|
2024-04-16 06:34:50 +02:00
|
|
|
|
|
|
|
<Route path="/web/users/:id" view=UserPage />
|
|
|
|
<Route path="/web/objects/:id" view=ObjectPage />
|
|
|
|
|
|
|
|
<Route path="/" view=move || view! { <Redirect path="/web" /> } />
|
|
|
|
</Routes>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-15 01:56:33 +02:00
|
|
|
</main>
|
2024-04-16 06:34:50 +02:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
</Router>
|
2024-04-14 06:45:51 +02:00
|
|
|
</div>
|
2024-04-17 05:39:45 +02:00
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
</footer>
|
2024-04-14 06:45:51 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|