diff --git a/islands/Me.tsx b/islands/Me.tsx index 5735545..ad5fcc6 100644 --- a/islands/Me.tsx +++ b/islands/Me.tsx @@ -1,18 +1,34 @@ -import { useEffect } from "preact/hooks"; +import { useEffect, useState } from "preact/hooks"; import Spinner from "~/components/Spinner.tsx"; import { fetchMe, me } from "~/state/me.ts"; +import { feed, fetchFeed } from "~/state/feed.ts"; import { fetchFriends, friends } from "~/state/friends.ts"; +import Post from "~/islands/Post.tsx"; +import IconArrowBigLeft from "icons/arrow-big-left.tsx"; +import IconArrowBigRight from "icons/arrow-big-right.tsx"; +import { type SelfPost } from "~/types.ts"; export default function Me() { - useEffect(() => { - fetchMe(); - fetchFriends(); - }, []); + const [index, setIndex] = useState(0); + const [post, setPost] = useState(null); const user = me.value; + const feedList = feed.value; const friendList = friends.value; - if (user === null || friendList === null) { + useEffect(() => { + (async () => await Promise.all([fetchMe(), fetchFeed(), fetchFriends()]))(); + }, []); + + useEffect(() => { + if (feedList !== null) { + setPost(feedList.userPosts.posts[index]); + } + }, [index, feedList]); + + if ( + user === null || friendList === null || feedList === null || post === null + ) { return ; } @@ -22,7 +38,7 @@ export default function Me() { Profile { (d.target as HTMLImageElement).src = "/raven.png"; }} @@ -33,8 +49,48 @@ export default function Me() {

@{user.username}

{user.biography}

- {friendList.data.length && ( -
+ {feedList.userPosts.posts.length > 0 && ( +
+
+

+ Posts ({feedList.userPosts.posts.length}) +

+
+ { + if (index > 0) { + setIndex((i) => i - 1); + } + }} + /> + { + if (index < feedList.userPosts.posts.length - 1) { + setIndex((i) => i + 1); + } + }} + /> +
+
+
+ +
+
+ )} + {friendList.data.length > 0 && ( +

Friends ({friendList.data.length})

@@ -45,20 +101,20 @@ export default function Me() { {friend.fullname} { (d.target as HTMLImageElement).src = "/raven.png"; }} /> -

@{friend.username}

+

@{friend.username}

))}
)} - {user.realmojis.length && ( -
+ {user.realmojis.length > 0 && ( +

Realmojis ({user.realmojis.length})

@@ -73,12 +129,12 @@ export default function Me() { Realmoji { (d.target as HTMLImageElement).src = "/raven.png"; }} /> -

{realmoji.emoji}

+

{realmoji.emoji}

))}