feat(web): rudimentary likes tab

This commit is contained in:
əlemi 2024-12-27 02:06:47 +01:00
parent 43de8334e2
commit 408f760672
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 25 additions and 2 deletions

View file

@ -124,6 +124,9 @@ pub fn ActorHeader() -> impl IntoView {
<span class:tab-active=move || matches!(matched_route.get(), FeedRoute::User)>
<a class="clean" href=web_path.clone()><span class="emoji">"🖂 "</span>"outbox"</a>
</span>
<span class="ml-1" class:tab-active=move || matches!(matched_route.get(), FeedRoute::Likes)>
<a class="clean" href=format!("{web_path}/likes")><span class="emoji">""</span>"likes"</a>
</span>
<span class="ml-1" style="float: right" class:tab-active=move || matches!(matched_route.get(), FeedRoute::Followers)>
<a class="clean" href=format!("{web_path}/followers")><span class="emoji">"📢"</span><span class:hidden-on-mobile=move || !matches!(matched_route.get(), FeedRoute::Followers)>" followers"</span></a>
</span>

View file

@ -17,3 +17,19 @@ pub fn ActorPosts() -> impl IntoView {
<Feed tl=feeds.user />
}
}
#[component]
pub fn ActorLikes() -> impl IntoView {
let feeds = use_context::<Feeds>().expect("missing feeds context");
let params = use_params::<IdParam>();
create_effect(move |_| {
let id = params.get().ok().and_then(|x| x.id).unwrap_or_default();
let likes_url = format!("{}/likes/page", Uri::api(U::Actor, &id, false));
if !feeds.user.next.get_untracked().starts_with(&likes_url) {
feeds.user_likes.reset(Some(likes_url));
}
});
view! {
<Feed tl=feeds.user_likes />
}
}

View file

@ -23,6 +23,7 @@ pub struct Feeds {
pub notifications: Timeline,
// exploration feeds
pub user: Timeline,
pub user_likes: Timeline,
pub server: Timeline,
pub context: Timeline,
pub replies: Timeline,
@ -36,6 +37,7 @@ impl Feeds {
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")),
user_likes: Timeline::new(format!("{URL_BASE}/actors/{username}/likes")),
server: Timeline::new(format!("{URL_BASE}/outbox/page")),
tag: Timeline::new(format!("{URL_BASE}/tags/upub/page")),
context: Timeline::new(format!("{URL_BASE}/outbox/page")), // TODO ehhh
@ -48,6 +50,7 @@ impl Feeds {
self.notifications.reset(None);
self.global.reset(None);
self.user.reset(None);
self.user_likes.reset(None);
self.server.reset(None);
self.context.reset(None);
self.replies.reset(None);
@ -177,6 +180,7 @@ pub fn App() -> impl IntoView {
<Route path="actors/:id" view=ActorHeader > // TODO can we avoid this?
<Route path="" view=ActorPosts />
<Route path="likes" view=ActorLikes />
<Route path="following" view=move || view! { <FollowList outgoing=true /> } />
<Route path="followers" view=move || view! { <FollowList outgoing=false /> } />
</Route>
@ -249,7 +253,7 @@ fn Scrollable() -> impl IntoView {
},
Some("likes") => {
set_route.set(FeedRoute::Likes);
None
Some(feeds.user_likes)
},
_ => {
set_route.set(FeedRoute::User);

View file

@ -10,7 +10,7 @@ pub use crate::{
actors::{
header::ActorHeader,
follow::FollowList,
posts::ActorPosts,
posts::{ActorPosts, ActorLikes},
},
activities::{
item::Item,