import { useEffect, useState } from 'react'; import { useToast } from '../../hooks/use-toast'; import { UserItem } from './UserItem'; import { Users2 } from 'lucide-react'; import {httpGet} from "../../lib/http"; export type FriendshipStatus = | 'none' | 'sent' | 'received' | 'accepted' | 'rejected' | 'got_rejected'; type FriendResourceProgress = { updatedAt: string; title: string; resourceId: string; resourceType: string; learning: number; skipped: number; done: number; total: number; }; export type ListFriendsResponse = { userId: string; name: string; email: string; avatar: string; status: FriendshipStatus; roadmaps: FriendResourceProgress[]; bestPractices: FriendResourceProgress[]; }[]; type ShareFriendListProps = { setFriends: (friends: ListFriendsResponse) => void; friends: ListFriendsResponse; sharedFriendIds: string[]; setSharedFriendIds: (friendIds: string[]) => void; }; export function ShareFriendList(props: ShareFriendListProps) { const { setFriends, friends, sharedFriendIds, setSharedFriendIds } = props; const toast = useToast(); const [isLoading, setIsLoading] = useState(true); async function loadFriends() { if (friends.length > 0) { return; } setIsLoading(true); 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.filter((friend) => friend.status === 'accepted')); } useEffect(() => { loadFriends().finally(() => { setIsLoading(false); }); }, []); const loadingFriends = isLoading && ( ); return ( <> {(friends.length > 0 || isLoading) && (

Select Friends to share the roadmap with

)} {loadingFriends} {friends.length > 0 && !isLoading && ( )} {friends.length === 0 && !isLoading && (

You do not have any friends yet.
{' '} Invite your friends to share roadmaps with.

)} ); }