refactor(web): UserProfileModal — toast on server errors, drop ConnectInstanceModal triggers
Same pattern as FriendsPage cleanup (T19): the friend-add catch no longer branches on the deleted InstanceNotConnectedError / InstanceDisconnectedError; the ConnectInstanceModal trigger is removed since the server handles all routing/peering. Errors surface via toast using mapServerErrorToMessage. This restores the web package to a compileable state.
This commit is contained in:
@@ -7,8 +7,8 @@ import { Username } from '../ui/Username';
|
|||||||
import { useUIStore } from '../../stores/uiStore';
|
import { useUIStore } from '../../stores/uiStore';
|
||||||
import { useSpaceStore, getApiForOrigin, resolveUserOrigin } from '../../stores/spaceStore';
|
import { useSpaceStore, getApiForOrigin, resolveUserOrigin } from '../../stores/spaceStore';
|
||||||
import { api } from '../../api/client';
|
import { api } from '../../api/client';
|
||||||
import { useSocialStore, type TaggedFriend, type TaggedFriendRequest, InstanceNotConnectedError, InstanceDisconnectedError } from '../../stores/socialStore';
|
import { useSocialStore, type TaggedFriend, type TaggedFriendRequest } from '../../stores/socialStore';
|
||||||
import { ConnectInstanceModal } from './ConnectInstanceModal';
|
import { mapServerErrorToMessage } from '../../utils/friendErrors';
|
||||||
import { useAuthStore } from '../../stores/authStore';
|
import { useAuthStore } from '../../stores/authStore';
|
||||||
import { getAvatarGradient, getSpaceGradient, adjustColor, mutedGradient } from '../../utils/gradients';
|
import { getAvatarGradient, getSpaceGradient, adjustColor, mutedGradient } from '../../utils/gradients';
|
||||||
import { parseFederatedUsername, isSelf, canonicalUserMatch } from '../../utils/identity';
|
import { parseFederatedUsername, isSelf, canonicalUserMatch } from '../../utils/identity';
|
||||||
@@ -71,10 +71,6 @@ export function UserProfileModal() {
|
|||||||
const [mutualSpaces, setMutualSpaces] = useState<MutualSpace[]>([]);
|
const [mutualSpaces, setMutualSpaces] = useState<MutualSpace[]>([]);
|
||||||
const [loadingMutuals, setLoadingMutuals] = useState(false);
|
const [loadingMutuals, setLoadingMutuals] = useState(false);
|
||||||
const [friendActionLoading, setFriendActionLoading] = useState(false);
|
const [friendActionLoading, setFriendActionLoading] = useState(false);
|
||||||
const [connectModal, setConnectModal] = useState<{
|
|
||||||
domain: string;
|
|
||||||
isReconnect: boolean;
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
const isOpen = activeModal === 'userProfile';
|
const isOpen = activeModal === 'userProfile';
|
||||||
const userId = modalData?.userId as string | undefined;
|
const userId = modalData?.userId as string | undefined;
|
||||||
@@ -190,29 +186,15 @@ export function UserProfileModal() {
|
|||||||
try {
|
try {
|
||||||
await sendFriendRequest(user.username);
|
await sendFriendRequest(user.username);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof InstanceNotConnectedError) {
|
const errorBody = (err as { body?: unknown })?.body;
|
||||||
setConnectModal({ domain: err.domain, isReconnect: false });
|
let code: string | undefined;
|
||||||
} else if (err instanceof InstanceDisconnectedError) {
|
let message: string | undefined;
|
||||||
setConnectModal({ domain: err.domain, isReconnect: true });
|
if (errorBody && typeof errorBody === 'object') {
|
||||||
|
code = (errorBody as { error?: string }).error;
|
||||||
|
message = (errorBody as { message?: string }).message;
|
||||||
}
|
}
|
||||||
// Other errors: socialStore already sets its own error state
|
const fallback = message ?? (err instanceof Error ? err.message : undefined);
|
||||||
} finally {
|
addToast(mapServerErrorToMessage(code, fallback, user.username), 'warning');
|
||||||
setFriendActionLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConnected = async (result: 'new' | 'reconnect') => {
|
|
||||||
const domain = connectModal?.domain; // capture before clearing
|
|
||||||
setConnectModal(null);
|
|
||||||
// Retry the friend request now that we're connected
|
|
||||||
setFriendActionLoading(true);
|
|
||||||
try {
|
|
||||||
await sendFriendRequest(user.username);
|
|
||||||
const verb = result === 'reconnect' ? 'Reconnected to' : 'Connected to';
|
|
||||||
addToast(`${verb} ${domain} — friend request sent to ${user.displayName ?? parseFederatedUsername(user.username).baseName}`, 'success');
|
|
||||||
} catch (err) {
|
|
||||||
// Connection succeeded but friend request failed — still valuable
|
|
||||||
addToast((err as Error).message, 'warning');
|
|
||||||
} finally {
|
} finally {
|
||||||
setFriendActionLoading(false);
|
setFriendActionLoading(false);
|
||||||
}
|
}
|
||||||
@@ -559,15 +541,6 @@ export function UserProfileModal() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{connectModal && user && (
|
|
||||||
<ConnectInstanceModal
|
|
||||||
domain={connectModal.domain}
|
|
||||||
targetDisplayName={user.displayName ?? parseFederatedUsername(user.username).baseName}
|
|
||||||
isReconnect={connectModal.isReconnect}
|
|
||||||
onConnected={handleConnected}
|
|
||||||
onCancel={() => setConnectModal(null)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user