From 319188bbccac9c614faddc6d401c838b59070c6e Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sat, 21 Oct 2023 01:21:45 +0100 Subject: [PATCH] Add share with friends functionality --- .../ShareOptions/ShareFriendList.tsx | 117 ++++++++++++++---- 1 file changed, 90 insertions(+), 27 deletions(-) diff --git a/src/components/ShareOptions/ShareFriendList.tsx b/src/components/ShareOptions/ShareFriendList.tsx index f1e146d1a..59e8b6366 100644 --- a/src/components/ShareOptions/ShareFriendList.tsx +++ b/src/components/ShareOptions/ShareFriendList.tsx @@ -1,8 +1,11 @@ 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"; +import { Check, Copy, Group, UserPlus2, Users2 } from 'lucide-react'; +import { httpGet } from '../../lib/http'; +import { getUser } from '../../lib/jwt.ts'; +import { useCopyText } from '../../hooks/use-copy-text.ts'; +import { cn } from '../../lib/classname.ts'; export type FriendshipStatus = | 'none' @@ -41,10 +44,13 @@ type ShareFriendListProps = { }; export function ShareFriendList(props: ShareFriendListProps) { + const userId = getUser()?.id!; const { setFriends, friends, sharedFriendIds, setSharedFriendIds } = props; const toast = useToast(); + const { isCopied, copyText } = useCopyText(); const [isLoading, setIsLoading] = useState(true); + const [isAddingFriend, setIsAddingFriend] = useState(false); async function loadFriends() { if (friends.length > 0) { @@ -53,7 +59,7 @@ export function ShareFriendList(props: ShareFriendListProps) { setIsLoading(true); const { response, error } = await httpGet( - `${import.meta.env.PUBLIC_API_URL}/v1-list-friends` + `${import.meta.env.PUBLIC_API_URL}/v1-list-friends`, ); if (error || !response) { @@ -87,6 +93,10 @@ export function ShareFriendList(props: ShareFriendListProps) { ); + const isDev = import.meta.env.DEV; + const baseWebUrl = isDev ? 'http://localhost:3000' : 'https://roadmap.sh'; + const befriendUrl = `${baseWebUrl}/befriend?u=${userId}`; + return ( <> {(friends.length > 0 || isLoading) && ( @@ -112,32 +122,85 @@ export function ShareFriendList(props: ShareFriendListProps) { {loadingFriends} {friends.length > 0 && !isLoading && ( - + + + + )} + )} {friends.length === 0 && !isLoading && (