feat(web): we're back to activity timelines babyyyy

This commit is contained in:
əlemi 2024-06-28 04:11:25 +02:00
parent 37a812f3c6
commit 157c97694e
Signed by: alemi
GPG key ID: A4895B84D311642C
8 changed files with 38 additions and 71 deletions

View file

@ -1,25 +0,0 @@
use leptos::*;
use leptos_router::*;
use crate::prelude::*;
#[component]
pub fn ActorActivity() -> impl IntoView {
let feeds = use_context::<Feeds>().expect("missing feeds context");
let params = use_params::<super::IdParam>();
let id = Signal::derive(move || {
let id = params.get_untracked().ok().and_then(|x| x.id).unwrap_or_default();
let tl_url = format!("{}/outbox/page", Uri::api(U::Actor, &id, false));
if !feeds.user.next.get_untracked().starts_with(&tl_url) {
feeds.user.reset(Some(tl_url));
}
id
});
view! {
<code class="cw color center mt-1 mb-1 ml-3 mr-3">
<a class="clean" href={format!("/web/actors/{}", id.get())}><span class="emoji">"🖂"</span>" posts"</a>
" | "
<b>activity</b>" "<span class="emoji">"@"</span>
</code>
<Feed tl=feeds.user />
}
}

View file

@ -1,7 +1,6 @@
pub mod follow;
pub mod posts;
pub mod header;
pub mod activity;
use leptos_router::Params; // TODO can i remove this?
#[derive(Clone, leptos::Params, PartialEq)]

View file

@ -6,19 +6,17 @@ use crate::prelude::*;
pub fn ActorPosts() -> impl IntoView {
let feeds = use_context::<Feeds>().expect("missing feeds context");
let params = use_params::<super::IdParam>();
let id = Signal::derive(move || {
Signal::derive(move || {
let id = params.get_untracked().ok().and_then(|x| x.id).unwrap_or_default();
let tl_url = format!("{}/streams/page", Uri::api(U::Actor, &id, false));
let tl_url = format!("{}/outbox/page", Uri::api(U::Actor, &id, false));
if !feeds.user.next.get_untracked().starts_with(&tl_url) {
feeds.user.reset(Some(tl_url));
}
id
});
}).track();
view! {
<code class="cw color center mt-1 mb-1 ml-3 mr-3">
<span class="emoji">"🖂"</span>" "<b>posts</b>
" | "
<a class="clean" href={format!("/web/actors/{}/activity", id.get())}>"activity "<span class="emoji">"@"</span></a>
</code>
<Feed tl=feeds.user />
}

View file

@ -7,12 +7,9 @@ use leptos_use::{signal_debounced, storage::use_local_storage, use_cookie, use_e
#[derive(Clone, Copy)]
pub struct Feeds {
// object feeds
pub home: Timeline,
pub global: Timeline,
// notification feeds
pub private: Timeline,
pub public: Timeline,
pub notifications: Timeline,
// exploration feeds
pub user: Timeline,
pub server: Timeline,
@ -22,10 +19,9 @@ pub struct Feeds {
impl Feeds {
pub fn new(username: &str) -> Self {
Feeds {
home: Timeline::new(format!("{URL_BASE}/actors/{username}/feed/page")),
global: Timeline::new(format!("{URL_BASE}/feed/page")),
private: Timeline::new(format!("{URL_BASE}/actors/{username}/inbox/page")),
public: Timeline::new(format!("{URL_BASE}/inbox/page")),
home: Timeline::new(format!("{URL_BASE}/actors/{username}/inbox/page")),
notifications: Timeline::new(format!("{URL_BASE}/actors/{username}/notifications/page")),
global: Timeline::new(format!("{URL_BASE}/inbox/page")),
user: Timeline::new(format!("{URL_BASE}/actors/{username}/outbox/page")),
server: Timeline::new(format!("{URL_BASE}/outbox/page")),
context: Timeline::new(format!("{URL_BASE}/outbox/page")), // TODO ehhh
@ -34,9 +30,8 @@ impl Feeds {
pub fn reset(&self) {
self.home.reset(None);
self.notifications.reset(None);
self.global.reset(None);
self.private.reset(None);
self.public.reset(None);
self.user.reset(None);
self.server.reset(None);
self.context.reset(None);
@ -122,9 +117,9 @@ pub fn App() -> impl IntoView {
}
/>
<Route path="home" view=move || view! { <Feed tl=feeds.home /> } />
<Route path="server" view=move || view! { <Feed tl=feeds.global /> } />
<Route path="global" view=move || view! { <Feed tl=feeds.global /> } />
<Route path="local" view=move || view! { <Feed tl=feeds.server /> } />
<Route path="inbox" view=move || view! { <Feed tl=feeds.private /> } />
<Route path="notifications" view=move || view! { <Feed tl=feeds.notifications /> } />
<Route path="about" view=AboutPage />
<Route path="config" view=move || view! { <ConfigPage setter=set_config /> } />
@ -134,7 +129,6 @@ pub fn App() -> impl IntoView {
<Route path="" view=ActorPosts />
<Route path="following" view=move || view! { <FollowList outgoing=true /> } />
<Route path="followers" view=move || view! { <FollowList outgoing=false /> } />
<Route path="activity" view=ActorActivity />
</Route>
<Route path="objects/:id" view=ObjectView />
@ -165,12 +159,12 @@ fn Scrollable() -> impl IntoView {
let path = location.pathname.get();
if path.contains("/web/home") {
Some(feeds.home)
} else if path.contains("/web/server") {
} else if path.contains("/web/global") {
Some(feeds.global)
} else if path.starts_with("/web/local") {
} else if path.contains("/web/local") {
Some(feeds.server)
} else if path.starts_with("/web/inbox") {
Some(feeds.private)
} else if path.starts_with("/web/notifications") {
Some(feeds.notifications)
} else if path.starts_with("/web/actors") {
Some(feeds.user)
} else if path.starts_with("/web/objects") {

View file

@ -19,20 +19,22 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
_ => Uri::web(U::Object, &object_id),
};
view! {
<div>
<span class="ml-1-l">
<ActorStrip object=actor />
</span>
<span style="float:right">
<code class="color moreinfo" title={activity.published().ok().map(|x| x.to_rfc2822())} >
<a class="upub-title clean" title={object_id} href={href} >
{kind.as_ref().to_string()}
</a>
{activity_url}
<PrivacyMarker addressed=activity.addressed() />
</code>
</span>
</div>
<table class="align w-100">
<tr>
<td class="ml-1-r">
<ActorStrip object=actor />
</td>
<td class="rev">
<code class="color moreinfo" title={activity.published().ok().map(|x| x.to_rfc2822())} >
<a class="upub-title clean" title={object_id} href={href} >
{kind.as_ref().to_string()}
</a>
{activity_url}
<PrivacyMarker addressed=activity.addressed() />
</code>
</td>
</tr>
</table>
}
}

View file

@ -18,7 +18,7 @@ pub fn LoginBox(
token_tx.set(None);
feeds.reset();
feeds.global.spawn_more(auth);
feeds.public.spawn_more(auth);
feeds.server.spawn_more(auth);
} />
</div>
<div class:hidden=move || auth.present() >
@ -44,14 +44,14 @@ pub fn LoginBox(
userid_tx.set(Some(auth_response.user));
token_tx.set(Some(auth_response.token));
// reset home feed and point it to our user's inbox
feeds.home.reset(Some(format!("{URL_BASE}/actors/{username}/feed/page")));
feeds.home.reset(Some(format!("{URL_BASE}/actors/{username}/inbox/page")));
feeds.home.spawn_more(auth);
feeds.private.reset(Some(format!("{URL_BASE}/actors/{username}/inbox/page")));
feeds.private.spawn_more(auth);
feeds.notifications.reset(Some(format!("{URL_BASE}/actors/{username}/notifications/page")));
feeds.notifications.spawn_more(auth);
// reset server feed: there may be more content now that we're authed
feeds.global.reset(Some(format!("{URL_BASE}/feed/page")));
feeds.global.reset(Some(format!("{URL_BASE}/inbox/page")));
feeds.global.spawn_more(auth);
feeds.server.reset(Some(format!("{URL_BASE}/inbox/page")));
feeds.server.reset(Some(format!("{URL_BASE}/outbox/page")));
feeds.server.spawn_more(auth);
});
} >

View file

@ -38,9 +38,9 @@ pub fn Navigator() -> impl IntoView {
</form>
<table class="align w-100">
<tr><td colspan="2"><a href="/web/home"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="home timeline" /></a></td></tr>
<tr><td colspan="2"><a href="/web/server"><input class="w-100" type="submit" value="server timeline" /></a></td></tr>
<tr><td colspan="2"><a href="/web/global"><input class="w-100" type="submit" value="global timeline" /></a></td></tr>
<tr><td colspan="2"><a href="/web/local"><input class="w-100" type="submit" value="local timeline" /></a></td></tr>
<tr><td colspan="2"><a href="/web/inbox"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="notifications" /></a></td></tr>
<tr><td colspan="2"><a href="/web/notifications"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="notifications" /></a></td></tr>
<tr>
<td class="w-50"><a href="/web/about"><input class="w-100" type="submit" value="about" /></a></td>
<td class="w-50"><a href="/web/config"><input class="w-100" type="submit" value="config" /></a></td>

View file

@ -9,7 +9,6 @@ pub use crate::{
header::ActorHeader,
follow::FollowList,
posts::ActorPosts,
activity::ActorActivity,
},
timeline::{
Timeline,