From fb3fe8be421e15166e67bc21548b0b141032ad40 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 7 Aug 2023 19:48:22 +0100 Subject: [PATCH] Friends listing page --- src/components/Befriend.tsx | 10 ++-- src/components/Friends/FriendsPage.tsx | 57 ++++++++++++++++++++--- src/components/ReactIcons/AddUserIcon.tsx | 27 +++++++++++ 3 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 src/components/ReactIcons/AddUserIcon.tsx diff --git a/src/components/Befriend.tsx b/src/components/Befriend.tsx index 32ead3ace..b972471d9 100644 --- a/src/components/Befriend.tsx +++ b/src/components/Befriend.tsx @@ -1,6 +1,5 @@ import { useEffect, useState } from 'preact/hooks'; import { httpDelete, httpGet, httpPatch, httpPost } from '../lib/http'; -import ErrorIcon from '../icons/error.svg'; import { pageProgressMessage } from '../stores/page'; import { isLoggedIn } from '../lib/jwt'; import { showLoginPopup } from '../lib/popup'; @@ -10,7 +9,8 @@ import { DeleteUserIcon } from './ReactIcons/DeleteUserIcon'; import { useToast } from '../hooks/use-toast'; import { useAuth } from '../hooks/use-auth'; import { AddedUserIcon } from './ReactIcons/AddedUserIcon'; -import {StopIcon} from "./ReactIcons/StopIcon"; +import { StopIcon } from './ReactIcons/StopIcon'; +import { ErrorIcon } from './ReactIcons/ErrorIcon'; export type FriendshipStatus = | 'none' @@ -106,11 +106,7 @@ export function Befriend() { if (!user) { return (
- {'error'} +

Error

diff --git a/src/components/Friends/FriendsPage.tsx b/src/components/Friends/FriendsPage.tsx index d0d5be541..a6b27de6c 100644 --- a/src/components/Friends/FriendsPage.tsx +++ b/src/components/Friends/FriendsPage.tsx @@ -1,12 +1,53 @@ -import { useEffect } from 'preact/hooks'; -import UserPlus from '../../icons/user-plus.svg'; +import { useEffect, useState } from 'preact/hooks'; import { pageProgressMessage } from '../../stores/page'; import { useAuth } from '../../hooks/use-auth'; +import { AddUserIcon } from '../ReactIcons/AddUserIcon'; +import { httpGet } from '../../lib/http'; +import type { FriendshipStatus } from '../Befriend'; +import { useToast } from '../../hooks/use-toast'; import { EmptyFriends } from './EmptyFriends'; +type FriendResourceProgress = { + updatedAt: string; + title: string; + resourceId: string; + resourceType: string; + learning: number; + skipped: number; + done: number; + total: number; +}; + +type ListFriendsResponse = { + userId: string; + name: string; + avatar: string; + status: FriendshipStatus; + roadmaps: FriendResourceProgress[]; + bestPractices: FriendResourceProgress[]; +}[]; + export function FriendsPage() { + const toast = useToast(); + const [friends, setFriends] = useState([]); + + async function loadFriends() { + const { response, error } = await httpGet( + `${import.meta.env.PUBLIC_API_URL}/v1-list-friends` + ); + + if (error || !response) { + toast.error(error?.message || 'Something went wrong'); + return; + } + + setFriends(response); + } + useEffect(() => { - pageProgressMessage.set(''); + loadFriends().finally(() => { + pageProgressMessage.set(''); + }); }, []); const user = useAuth(); @@ -15,16 +56,18 @@ export function FriendsPage() { : 'https://roadmap.sh'; const befriendUrl = `${baseUrl}/befriend?u=${user?.id}`; - return ; + if (friends.length === 0) { + return ; + } return (

- You have 4 friends on Roadmap.sh + You have 4 active friends -
diff --git a/src/components/ReactIcons/AddUserIcon.tsx b/src/components/ReactIcons/AddUserIcon.tsx new file mode 100644 index 000000000..cd8dab93a --- /dev/null +++ b/src/components/ReactIcons/AddUserIcon.tsx @@ -0,0 +1,27 @@ +type CheckIconProps = { + additionalClasses?: string; +}; + +export function AddUserIcon(props: CheckIconProps) { + const { additionalClasses = 'mr-2 w-[20px] h-[20px]' } = props; + + return ( + + + + + + + ); +}