Skip to content

Commit 54c852e

Browse files
committed
简化链接复制
1 parent 6dad0bf commit 54c852e

File tree

2 files changed

+93
-98
lines changed

2 files changed

+93
-98
lines changed

src/view/chat/components/group/GroupChatHeader.tsx

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { chatEvents } from '@/store/useChatStore'
2-
import useChatStore from '@/store/useChatStore'
1+
import useChatStore, { chatEvents } from '@/store/useChatStore'
32
import { GroupChat } from '@/types/chat'
43
import {
54
Action as AlertDialogAction, Cancel as AlertDialogCancel,
@@ -11,7 +10,6 @@ import {
1110
Title as AlertDialogTitle,
1211
Trigger as AlertDialogTrigger
1312
} from '@radix-ui/react-alert-dialog'
14-
import { Content, Description, Overlay, Portal, Root, Title, Trigger } from '@radix-ui/react-dialog'
1513
import React, { useEffect, useState } from 'react'
1614
import toast from 'react-hot-toast'
1715
import Avatar from '../common/Avatar'
@@ -34,7 +32,6 @@ const GroupChatHeader: React.FC = () => {
3432
const handleLinkCopied = () => {
3533
setIsCopying(false);
3634
toast.success('邀请链接已复制');
37-
setDialogOpen(false);
3835
};
3936

4037
chatEvents.on('linkCopied', handleLinkCopied);
@@ -101,59 +98,25 @@ const GroupChatHeader: React.FC = () => {
10198
</div>
10299

103100
<div className="flex items-center space-x-2">
104-
<Root open={dialogOpen} onOpenChange={setDialogOpen}>
105-
<Trigger asChild>
106-
<button className="p-2 text-gray-500 hover:bg-gray-100 rounded-full" disabled={isConnecting}>
107-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
108-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
109-
d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"
110-
/>
111-
</svg>
112-
</button>
113-
</Trigger>
114-
<Portal>
115-
<Overlay className={`fixed inset-0 bg-black/30 ${overlayShow}`} />
116-
<Content className={`fixed top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]
117-
w-[90vw] max-w-[450px] rounded-lg bg-white p-6 shadow-xl focus:outline-none ${contentShow}`}>
118-
<Title className="text-xl font-semibold mb-4">分享群聊</Title>
119-
<Description className="text-gray-500 mb-4">
120-
复制下面的链接,邀请好友加入群聊:
121-
</Description>
122-
<div className="flex mb-6">
123-
<input
124-
type="text"
125-
value={groupChat.shareLink || ''}
126-
readOnly
127-
className="flex-1 px-3 py-2 border border-gray-300 rounded-l-md focus:outline-none"
128-
/>
129-
<button
130-
onClick={handleCopyLink}
131-
disabled={isCopying}
132-
className={`px-4 py-2 bg-blue-500 text-white rounded-r-md hover:bg-blue-600 flex items-center justify-center min-w-[80px]
133-
${isCopying ? 'opacity-75' : ''}`}
134-
>
135-
{isCopying ? (
136-
<>
137-
<svg className="w-4 h-4 mr-1 animate-spin" fill="none" viewBox="0 0 24 24">
138-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
139-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
140-
</svg>
141-
复制中
142-
</>
143-
) : '复制'}
144-
</button>
145-
</div>
146-
<div className="flex justify-end">
147-
<button
148-
onClick={() => setDialogOpen(false)}
149-
className="px-4 py-2 bg-gray-100 text-gray-700 rounded-md hover:bg-gray-200"
150-
>
151-
关闭
152-
</button>
153-
</div>
154-
</Content>
155-
</Portal>
156-
</Root>
101+
<button
102+
className="p-2 text-gray-500 hover:bg-gray-100 rounded-full"
103+
disabled={isConnecting || isCopying}
104+
onClick={handleCopyLink}
105+
title="复制邀请链接"
106+
>
107+
{isCopying ? (
108+
<svg className="w-5 h-5 animate-spin" fill="none" viewBox="0 0 24 24">
109+
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
110+
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
111+
</svg>
112+
) : (
113+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
114+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
115+
d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"
116+
/>
117+
</svg>
118+
)}
119+
</button>
157120

158121
<AlertDialogRoot open={leaveDialogOpen} onOpenChange={setLeaveDialogOpen}>
159122
<AlertDialogTrigger asChild>

src/view/chat/components/sidebar/Sidebar.tsx

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import useChatStore, { chatEvents } from '@/store/useChatStore'
22
import { Chat, GroupChat } from '@/types/chat'
33
import { cleanRoomId } from '@/utils/roomUtils'
44
import { Content, Description, Overlay, Portal, Root, Title } from '@radix-ui/react-dialog'
5+
import { Provider as TooltipProvider, Root as TooltipRoot, Trigger as TooltipTrigger, Content as TooltipContent } from '@radix-ui/react-tooltip'
56
import React, { useEffect, useState } from 'react'
67
import toast from 'react-hot-toast'
78
import ChatListItem from './ChatListItem'
@@ -169,47 +170,78 @@ const Sidebar: React.FC = () => {
169170
<div className="h-full flex flex-col">
170171
<div className="p-4 border-b border-gray-200 flex items-center justify-between">
171172
<h1 className="text-xl font-semibold text-gray-800">聊天</h1>
172-
<div className="flex space-x-2">
173-
<button
174-
onClick={() => setJoinDialogOpen(true)}
175-
disabled={isConnecting}
176-
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
177-
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
178-
title="加入群聊"
179-
>
180-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
181-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
182-
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"
183-
/>
184-
</svg>
185-
</button>
186-
<button
187-
onClick={handleCreateGroupChat}
188-
disabled={isConnecting}
189-
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
190-
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
191-
title="创建群聊"
192-
>
193-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
194-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
195-
d="M12 4v16m8-8H4"
196-
/>
197-
</svg>
198-
</button>
199-
<button
200-
onClick={() => setNameDialogOpen(true)}
201-
disabled={isConnecting}
202-
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
203-
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
204-
title={userName ? "修改用户名" : "设置用户名"}
205-
>
206-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
207-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
208-
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
209-
/>
210-
</svg>
211-
</button>
212-
</div>
173+
<TooltipProvider>
174+
<div className="flex space-x-2">
175+
<TooltipRoot>
176+
<TooltipTrigger asChild>
177+
<button
178+
onClick={handleCreateGroupChat}
179+
disabled={isConnecting}
180+
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
181+
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
182+
>
183+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
184+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
185+
d="M12 4v16m8-8H4"
186+
/>
187+
</svg>
188+
</button>
189+
</TooltipTrigger>
190+
<TooltipContent
191+
className="bg-gray-800 text-white px-3 py-1.5 rounded text-sm animate-fadeIn z-50"
192+
sideOffset={5}
193+
>
194+
创建群聊
195+
</TooltipContent>
196+
</TooltipRoot>
197+
198+
<TooltipRoot>
199+
<TooltipTrigger asChild>
200+
<button
201+
onClick={() => setNameDialogOpen(true)}
202+
disabled={isConnecting}
203+
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
204+
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
205+
>
206+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
207+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
208+
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
209+
/>
210+
</svg>
211+
</button>
212+
</TooltipTrigger>
213+
<TooltipContent
214+
className="bg-gray-800 text-white px-3 py-1.5 rounded text-sm animate-fadeIn z-50"
215+
sideOffset={5}
216+
>
217+
{userName ? "修改用户名" : "设置用户名"}
218+
</TooltipContent>
219+
</TooltipRoot>
220+
221+
<TooltipRoot>
222+
<TooltipTrigger asChild>
223+
<button
224+
onClick={() => setJoinDialogOpen(true)}
225+
disabled={isConnecting}
226+
className={`p-2 text-gray-500 hover:bg-gray-100 rounded-full
227+
${isConnecting ? 'opacity-50 cursor-not-allowed' : ''}`}
228+
>
229+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
230+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
231+
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"
232+
/>
233+
</svg>
234+
</button>
235+
</TooltipTrigger>
236+
<TooltipContent
237+
className="bg-gray-800 text-white px-3 py-1.5 rounded text-sm animate-fadeIn z-50"
238+
sideOffset={5}
239+
>
240+
加入群聊
241+
</TooltipContent>
242+
</TooltipRoot>
243+
</div>
244+
</TooltipProvider>
213245
</div>
214246

215247
{/* 聊天列表 */}

0 commit comments

Comments
 (0)