fix(web): stop the profile card re-anchoring to its own avatar (#39)

Avatar opened the profile popout whenever it received a user prop. Since user is how every avatar gets its gradient, colour and status dot, all 22 call sites became profile triggers by accident — including the picture inside the profile card itself, which re-anchored the card to that picture on every click and walked it across the screen (120px right, 36px down, until it pinned at the viewport clamp).

Avatar is now presentational. A new ProfileAvatar carries the open-the-profile behaviour at the five call sites that actually want it. The card's own picture escalates to the full profile modal instead of reopening the card.

The card also places itself off its measured size via the shared computeFloatingPosition engine, replacing six call sites that each hand-computed coordinates against a guessed 460px card height.

Closes #37
This commit is contained in:
cnrd
2026-08-25 15:51:04 +02:00
committed by GitHub
parent 747f1b9c5c
commit 8456b8f976
23 changed files with 563 additions and 118 deletions
+12 -6
View File
@@ -1,6 +1,7 @@
import { create } from 'zustand';
import { persist, createJSONStorage } from 'zustand/middleware';
import type { User } from '@backspace/shared';
import type { AnchorRect, Placement } from '../hooks/useFloatingPosition';
type ModalType =
| 'createSpace'
@@ -40,7 +41,11 @@ interface UIState {
imagePreviewUrl: string | null;
userProfilePopout: {
user: User | null;
position: { top: number; left: number } | null;
/** Rect of the element the card was opened from. The card places itself off
* this rect once it knows its own measured size — callers never compute
* coordinates, so no surface can drift by re-anchoring to itself. */
anchor: AnchorRect | null;
placement: Placement;
};
toasts: Toast[];
toggleSidebar: () => void;
@@ -51,7 +56,7 @@ interface UIState {
setShowDms: (show: boolean) => void;
openImagePreview: (url: string) => void;
closeImagePreview: () => void;
openUserProfile: (user: User, position: { top: number; left: number }) => void;
openUserProfile: (user: User, anchor: AnchorRect, placement?: Placement) => void;
closeUserProfile: () => void;
addToast: (message: string, type?: 'info' | 'warning' | 'success', duration?: number) => void;
removeToast: (id: string) => void;
@@ -93,7 +98,8 @@ export const useUIStore = create<UIState>()(
imagePreviewUrl: null,
userProfilePopout: {
user: null,
position: null,
anchor: null,
placement: 'right',
},
toasts: [],
@@ -120,7 +126,7 @@ export const useUIStore = create<UIState>()(
openImagePreview: (url) => set({ activeModal: 'imagePreview', imagePreviewUrl: url }),
closeImagePreview: () => set({ activeModal: null, imagePreviewUrl: null }),
openUserProfile: (user, position) => {
openUserProfile: (user, anchor, placement = 'right') => {
if (get().isMobile) {
// On mobile, push a full-screen user profile instead of a positioned popout
set((state) => ({
@@ -128,11 +134,11 @@ export const useUIStore = create<UIState>()(
}));
history.pushState({ mobileScreen: 'user-profile' }, '');
} else {
set({ userProfilePopout: { user, position } });
set({ userProfilePopout: { user, anchor, placement } });
}
},
closeUserProfile: () => set({
userProfilePopout: { user: null, position: null }
userProfilePopout: { user: null, anchor: null, placement: 'right' }
}),
addToast: (message, type = 'info', duration = 5000) => {