feat(desktop): set-nickname dialog + right-click trigger in friends list

This commit is contained in:
byGalax
2026-05-16 17:01:38 +02:00
parent a5eadef663
commit 898b7469bb
2 changed files with 123 additions and 3 deletions
+42 -3
View File
@@ -14,6 +14,7 @@ import { useNavigate } from 'react-router-dom';
import { Avatar } from '../components/Avatar';
import { EmptyState } from '../components/EmptyState';
import { NicknameDialog } from '../components/NicknameDialog';
import {
AddUserIcon,
AlertIcon,
@@ -41,6 +42,7 @@ export function FriendsPage() {
const [searchError, setSearchError] = useState<string | null>(null);
const [pendingId, setPendingId] = useState<string | null>(null);
const [actionError, setActionError] = useState<string | null>(null);
const [nicknameDialog, setNicknameDialog] = useState<{ userId: string; displayName: string } | null>(null);
const searchInputRef = useRef<HTMLInputElement | null>(null);
const focusSearch = useCallback(() => {
@@ -184,6 +186,12 @@ export function FriendsPage() {
<FriendList
items={accepted}
emptyKey="app:friends.empty_friends"
onRowContextMenu={(f) =>
setNicknameDialog({
userId: f.peer.userId,
displayName: f.peer.displayName ?? f.peer.username ?? 'Freund',
})
}
renderActions={(f) => (
<FriendActions
busy={pendingId === f.peer.userId || pendingId === 'msg-' + f.peer.userId}
@@ -233,6 +241,12 @@ export function FriendsPage() {
/>
)}
</div>
<NicknameDialog
open={nicknameDialog !== null}
userId={nicknameDialog?.userId ?? ''}
displayName={nicknameDialog?.displayName ?? ''}
onClose={() => setNicknameDialog(null)}
/>
</div>
);
}
@@ -275,10 +289,12 @@ function FriendList({
items,
emptyKey,
renderActions,
onRowContextMenu,
}: {
items: Friendship[];
emptyKey: string;
renderActions: (f: Friendship) => React.ReactNode;
onRowContextMenu?: (f: Friendship) => void;
}) {
const { t } = useTranslation(['app']);
if (items.length === 0) {
@@ -296,16 +312,39 @@ function FriendList({
<ul className="space-y-1.5">
{items.map((f) => (
<li key={f.peer.userId}>
<FriendRow profile={f.peer}>{renderActions(f)}</FriendRow>
<FriendRow
profile={f.peer}
{...(onRowContextMenu
? {
onContextMenu: (e: React.MouseEvent<HTMLDivElement>) => {
e.preventDefault();
onRowContextMenu(f);
},
}
: {})}
>
{renderActions(f)}
</FriendRow>
</li>
))}
</ul>
);
}
function FriendRow({ profile, children }: { profile: ProfileBrief; children: React.ReactNode }) {
function FriendRow({
profile,
children,
onContextMenu,
}: {
profile: ProfileBrief;
children: React.ReactNode;
onContextMenu?: (e: React.MouseEvent<HTMLDivElement>) => void;
}) {
return (
<div className="flex items-center gap-3 rounded-xl border border-line bg-surface-2 px-4 py-3">
<div
onContextMenu={onContextMenu}
className="flex items-center gap-3 rounded-xl border border-line bg-surface-2 px-4 py-3"
>
<Avatar
url={profile.avatarUrl}
displayName={profile.displayName ?? profile.username}