fix: correct networking imports and API response format
- Fix useSession → useAuth import (matches actual export) - Fix GraphEdge properties: source/target instead of fromUserId/toUserId - Add missing trustLevel, effectiveTrustLevel to edge response - Add myConnections to NetworkGraph type - Prefix unused myConnections param with underscore 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b95eb6dc01
commit
fab58aead0
|
|
@ -154,7 +154,7 @@ const styles = {
|
||||||
export function NetworkGraphMinimap({
|
export function NetworkGraphMinimap({
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
myConnections,
|
myConnections: _myConnections,
|
||||||
currentUserId,
|
currentUserId,
|
||||||
onConnect,
|
onConnect,
|
||||||
onDisconnect,
|
onDisconnect,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import React, { useState, useCallback, useMemo } from 'react';
|
||||||
import { useEditor, useValue } from 'tldraw';
|
import { useEditor, useValue } from 'tldraw';
|
||||||
import { NetworkGraphMinimap } from './NetworkGraphMinimap';
|
import { NetworkGraphMinimap } from './NetworkGraphMinimap';
|
||||||
import { useNetworkGraph } from './useNetworkGraph';
|
import { useNetworkGraph } from './useNetworkGraph';
|
||||||
import { useSession } from '../../context/AuthContext';
|
import { useAuth } from '../../context/AuthContext';
|
||||||
import type { GraphEdge, TrustLevel } from '../../lib/networking';
|
import type { GraphEdge, TrustLevel } from '../../lib/networking';
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
@ -26,7 +26,7 @@ interface NetworkGraphPanelProps {
|
||||||
|
|
||||||
export function NetworkGraphPanel({ onExpand }: NetworkGraphPanelProps) {
|
export function NetworkGraphPanel({ onExpand }: NetworkGraphPanelProps) {
|
||||||
const editor = useEditor();
|
const editor = useEditor();
|
||||||
const { session } = useSession();
|
const { session } = useAuth();
|
||||||
const [isCollapsed, setIsCollapsed] = useState(false);
|
const [isCollapsed, setIsCollapsed] = useState(false);
|
||||||
const [selectedEdge, setSelectedEdge] = useState<GraphEdge | null>(null);
|
const [selectedEdge, setSelectedEdge] = useState<GraphEdge | null>(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useEffect, useCallback, useMemo } from 'react';
|
import { useState, useEffect, useCallback, useMemo } from 'react';
|
||||||
import { useSession } from '../../context/AuthContext';
|
import { useAuth } from '../../context/AuthContext';
|
||||||
import {
|
import {
|
||||||
getMyNetworkGraph,
|
getMyNetworkGraph,
|
||||||
getRoomNetworkGraph,
|
getRoomNetworkGraph,
|
||||||
|
|
@ -80,7 +80,7 @@ export function useNetworkGraph(options: UseNetworkGraphOptions = {}): UseNetwor
|
||||||
useCache = true,
|
useCache = true,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const { session } = useSession();
|
const { session } = useAuth();
|
||||||
const [state, setState] = useState<NetworkGraphState>({
|
const [state, setState] = useState<NetworkGraphState>({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ async function fetchJson<T>(url: string, options?: RequestInit): Promise<T> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({ message: response.statusText }));
|
const errorData = await response.json().catch(() => ({ message: response.statusText })) as { message?: string };
|
||||||
throw new Error(error.message || `HTTP ${response.status}`);
|
throw new Error(errorData.message || `HTTP ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
|
|
@ -278,6 +278,8 @@ export function buildGraphEdge(
|
||||||
id: connection.id,
|
id: connection.id,
|
||||||
source: connection.fromUserId,
|
source: connection.fromUserId,
|
||||||
target: connection.toUserId,
|
target: connection.toUserId,
|
||||||
|
trustLevel: connection.trustLevel,
|
||||||
|
effectiveTrustLevel: connection.effectiveTrustLevel,
|
||||||
isMutual: connection.isMutual,
|
isMutual: connection.isMutual,
|
||||||
metadata: isOnEdge ? connection.metadata : undefined,
|
metadata: isOnEdge ? connection.metadata : undefined,
|
||||||
isVisible: true,
|
isVisible: true,
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ export interface GraphEdge {
|
||||||
export interface NetworkGraph {
|
export interface NetworkGraph {
|
||||||
nodes: GraphNode[];
|
nodes: GraphNode[];
|
||||||
edges: GraphEdge[];
|
edges: GraphEdge[];
|
||||||
|
myConnections: string[]; // User IDs the current user is connected to
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ export async function updateMyProfile(request: IRequest, env: Environment): Prom
|
||||||
`).bind(userId, body.displayName || null, body.bio || null, body.avatarColor || null).run();
|
`).bind(userId, body.displayName || null, body.bio || null, body.avatarColor || null).run();
|
||||||
|
|
||||||
// Return updated profile
|
// Return updated profile
|
||||||
return getUserProfile({ ...request, params: { userId } } as IRequest, env);
|
return getUserProfile({ ...request, params: { userId } } as unknown as IRequest, env);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Update profile error:', error);
|
console.error('Update profile error:', error);
|
||||||
return errorResponse('Failed to update profile', 500);
|
return errorResponse('Failed to update profile', 500);
|
||||||
|
|
@ -712,10 +712,12 @@ export async function getNetworkGraph(request: IRequest, env: Environment): Prom
|
||||||
|
|
||||||
const graphEdges: GraphEdge[] = (edges.results || []).map((e: any) => ({
|
const graphEdges: GraphEdge[] = (edges.results || []).map((e: any) => ({
|
||||||
id: e.id,
|
id: e.id,
|
||||||
fromUserId: e.fromUserId,
|
source: e.fromUserId,
|
||||||
toUserId: e.toUserId,
|
target: e.toUserId,
|
||||||
createdAt: e.createdAt,
|
trustLevel: e.trustLevel || 'connected',
|
||||||
|
effectiveTrustLevel: e.isMutual ? (e.trustLevel || 'connected') : null,
|
||||||
isMutual: !!e.isMutual,
|
isMutual: !!e.isMutual,
|
||||||
|
isVisible: true,
|
||||||
metadata: (e.fromUserId === userId || e.toUserId === userId) && (e.label || e.notes || e.color || e.strength) ? {
|
metadata: (e.fromUserId === userId || e.toUserId === userId) && (e.label || e.notes || e.color || e.strength) ? {
|
||||||
label: e.label,
|
label: e.label,
|
||||||
notes: e.notes,
|
notes: e.notes,
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
|
||||||
|
|
||||||
// User search and profiles
|
// User search and profiles
|
||||||
.get("/api/networking/users/search", searchUsers)
|
.get("/api/networking/users/search", searchUsers)
|
||||||
.get("/api/networking/users/me", (req, env) => getUserProfile({ ...req, params: { userId: req.headers.get('X-User-Id') || '' } } as IRequest, env))
|
.get("/api/networking/users/me", (req, env) => getUserProfile({ ...req, params: { userId: req.headers.get('X-User-Id') || '' } } as unknown as IRequest, env))
|
||||||
.put("/api/networking/users/me", updateMyProfile)
|
.put("/api/networking/users/me", updateMyProfile)
|
||||||
.get("/api/networking/users/:userId", getUserProfile)
|
.get("/api/networking/users/:userId", getUserProfile)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue