Skip to content

Commit ae989ae

Browse files
committed
feat: added open chat button in trading views
1 parent 11f20e6 commit ae989ae

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

frontend/src/components/ui/friend-id-display.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Copy } from 'lucide-react'
1+
import { Copy, MessageSquare } from 'lucide-react'
22
import type { FC } from 'react'
33
import { useToast } from '@/hooks/use-toast.ts'
44
import { cn, formatFriendId } from '@/lib/utils'
@@ -9,9 +9,10 @@ interface FriendIdDisplayProps {
99
className?: string
1010
showCopyButton?: boolean
1111
showFriendId?: boolean
12+
onChat?: () => void
1213
}
1314

14-
export const FriendIdDisplay: FC<FriendIdDisplayProps> = ({ friendId, className = '', showFriendId = true, showCopyButton = true }) => {
15+
export const FriendIdDisplay: FC<FriendIdDisplayProps> = ({ friendId, className = '', showFriendId = true, showCopyButton = true, onChat }) => {
1516
const { toast } = useToast()
1617

1718
const handleCopy = async () => {
@@ -41,6 +42,7 @@ export const FriendIdDisplay: FC<FriendIdDisplayProps> = ({ friendId, className
4142
{showFriendId && <span className="font-mono">{formatFriendId(friendId)}</span>}
4243
{showCopyButton && (
4344
<Button
45+
title="copy id"
4446
variant="ghost"
4547
size="icon"
4648
onClick={handleCopy}
@@ -50,6 +52,18 @@ export const FriendIdDisplay: FC<FriendIdDisplayProps> = ({ friendId, className
5052
<Copy className="h-2.5 w-2.5" />
5153
</Button>
5254
)}
55+
{onChat && (
56+
<Button
57+
title="open chat"
58+
variant="ghost"
59+
size="icon"
60+
onClick={onChat}
61+
className="h-4 w-4 text-neutral-500 hover:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-200"
62+
aria-label="Open chat"
63+
>
64+
<MessageSquare className="h-2.5 w-2.5" />
65+
</Button>
66+
)}
5367
</span>
5468
)
5569
}

frontend/src/pages/trade/TradeWith.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Spinner } from '@/components/Spinner'
66
import { Button } from '@/components/ui/button'
77
import { FriendIdDisplay } from '@/components/ui/friend-id-display'
88
import { Switch } from '@/components/ui/switch'
9+
import { useChatContext } from '@/context/ChatContext'
910
import { useToast } from '@/hooks/use-toast'
1011
import { getCardByInternalId, tradeableExpansions } from '@/lib/CardsDB.ts'
1112
import { getExtraCards, getNeededCards } from '@/lib/utils'
@@ -40,6 +41,7 @@ function TradeWith() {
4041
const { data: friends = [] } = useFriends()
4142
const manageFriend = useManageFriend()
4243
const { toast } = useToast()
44+
const { openChat } = useChatContext()
4345

4446
const [viewHistory, setViewHistory] = useState(false)
4547
const [pageHistory, setPageHistory] = useState(0)
@@ -121,7 +123,10 @@ function TradeWith() {
121123
<span className="text-2xl font-light">{t('tradingWith')}</span>
122124
<span className="text-2xl font-bold"> {friendAccount.username} </span>
123125
<span className="block sm:inline text-sm">
124-
<FriendIdDisplay friendId={friendAccount.friend_id} />
126+
<FriendIdDisplay
127+
friendId={friendAccount.friend_id}
128+
onChat={isAlreadyFriend ? () => openChat(friendAccount.friend_id, friendAccount.username || friendAccount.friend_id) : undefined}
129+
/>
125130
</span>
126131
</h1>
127132
<div className="flex flex-col-reverse sm:flex-row gap-2">

frontend/src/pages/trade/components/TradePartner.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { Spinner } from '@/components/Spinner'
66
import { Button } from '@/components/ui/button.tsx'
77
import { FriendIdDisplay } from '@/components/ui/friend-id-display.tsx'
88
import { Switch } from '@/components/ui/switch.tsx'
9+
import { useChatContext } from '@/context/ChatContext'
910
import TradeList from '@/pages/trade/components/TradeList.tsx'
1011
import { usePublicAccount } from '@/services/account/useAccount.ts'
12+
import { useFriends } from '@/services/friends/useFriends'
1113
import { useAllTrades } from '@/services/trade/useTrade'
1214
import type { TradeRow } from '@/types'
1315

@@ -20,6 +22,9 @@ function TradePartner({ friendId, activeTrades }: TradePartnerProps) {
2022
const { t } = useTranslation(['trade-matches', 'common'])
2123

2224
const { data: friendAccount, isLoading: isLoadingAccount } = usePublicAccount(friendId)
25+
const { data: friends = [] } = useFriends()
26+
const { openChat } = useChatContext()
27+
const isAlreadyFriend = friends.some((f) => f.friend_id === friendId)
2328

2429
const [viewHistory, setViewHistory] = useState(false)
2530
const [pageHistory, setPageHistory] = useState(0)
@@ -35,7 +40,14 @@ function TradePartner({ friendId, activeTrades }: TradePartnerProps) {
3540
<p>
3641
<span className="text-md">{t('tradingWith')}</span>
3742
<span className="text-md font-bold"> {friendAccount?.username || 'unknown'} </span>
38-
{friendAccount && <FriendIdDisplay friendId={friendAccount.friend_id} showFriendId={false} className="ml-1" />}
43+
{friendAccount && (
44+
<FriendIdDisplay
45+
friendId={friendAccount.friend_id}
46+
showFriendId={false}
47+
className="ml-1"
48+
onChat={isAlreadyFriend ? () => openChat(friendAccount.friend_id, friendAccount.username || friendAccount.friend_id) : undefined}
49+
/>
50+
)}
3951
</p>
4052
<span className="flex gap-4">
4153
<label htmlFor={`history-${friendId}`} className="my-auto flex items-center">

0 commit comments

Comments
 (0)