From 223db12a33ce9c8d39ff27701960192df35832fc Mon Sep 17 00:00:00 2001 From: Rohinth S Date: Sun, 15 Nov 2026 09:23:26 +0530 Subject: [PATCH] Carry display names into public journeys and graph labels --- backend/src/services/community.service.ts | 3 ++- frontend/api/community.api.ts | 1 + frontend/app/results.tsx | 2 +- frontend/app/u/[username].tsx | 11 ++++++----- frontend/tests/journey-graph.test.mjs | 9 +++++++++ frontend/tests/publicDisplayName.test.mjs | 14 ++++++++++++++ frontend/utils/journeyGraph.ts | 4 ++-- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 frontend/tests/publicDisplayName.test.mjs diff --git a/backend/src/services/community.service.ts b/backend/src/services/community.service.ts index 6571b80..c2751cf 100644 --- a/backend/src/services/community.service.ts +++ b/backend/src/services/community.service.ts @@ -232,7 +232,7 @@ export async function getCommunityJourney( const userResult = await session.run( ` MATCH (u:User {username: $username}) - RETURN u.username AS username, u.avatarUrl AS avatarUrl, coalesce(u.reputationScore, 0) AS reputationScore + RETURN u.username AS username, u.displayName AS displayName, u.avatarUrl AS avatarUrl, coalesce(u.reputationScore, 0) AS reputationScore `, { username } ); @@ -312,6 +312,7 @@ export async function getCommunityJourney( reputationScore: Number(userRecord!.get("reputationScore")) }, username: userRecord!.get("username"), + displayName: userRecord!.get("displayName") ?? null, imageUrl: userRecord!.get("avatarUrl"), statistics: { goals: goals.length, diff --git a/frontend/api/community.api.ts b/frontend/api/community.api.ts index 77c0fb0..c794b67 100644 --- a/frontend/api/community.api.ts +++ b/frontend/api/community.api.ts @@ -13,6 +13,7 @@ export interface SearchCommunityUser { } export interface CommunityJourney extends UserJourneyResponse { + displayName?: string | null; imageUrl?: string | null; } diff --git a/frontend/app/results.tsx b/frontend/app/results.tsx index 1d9fbae..5e151f9 100644 --- a/frontend/app/results.tsx +++ b/frontend/app/results.tsx @@ -343,7 +343,7 @@ export default function ResultsPage() { { router.push({ pathname: `/u/${user.username}`, params: { - fromQuery: 'true', imageUrl: user.imageUrl ?? '', expandedDetails: JSON.stringify(user.expandedDetails || { goals: [], experiences: [], transitions: [] }) + fromQuery: 'true', displayName: user.displayName ?? '', imageUrl: user.imageUrl ?? '', expandedDetails: JSON.stringify(user.expandedDetails || { goals: [], experiences: [], transitions: [] }) } }); }}> diff --git a/frontend/app/u/[username].tsx b/frontend/app/u/[username].tsx index 62a6c05..026c140 100644 --- a/frontend/app/u/[username].tsx +++ b/frontend/app/u/[username].tsx @@ -15,8 +15,8 @@ import { WebView } from 'react-native-webview'; export default function PublicProfilePage() { const router = useRouter(); - const { username, fromCommunity, fromQuery, imageUrl, expandedDetails, experienceId } = useLocalSearchParams<{ - username: string; fromCommunity?: string; fromQuery?: string; imageUrl?: string; expandedDetails?: string; experienceId?: string; + const { username, fromCommunity, fromQuery, displayName, imageUrl, expandedDetails, experienceId } = useLocalSearchParams<{ + username: string; displayName?: string; fromCommunity?: string; fromQuery?: string; imageUrl?: string; expandedDetails?: string; experienceId?: string; }>(); const goBack = () => { if (fromCommunity === 'true') router.dismissTo('/(tabs)/community'); @@ -56,6 +56,7 @@ export default function PublicProfilePage() { setJourney({ username: username, + displayName: displayName?.trim() || null, imageUrl: imageUrl || null, statistics: { goals: parsedDetails.goals?.length || 0, @@ -76,7 +77,7 @@ export default function PublicProfilePage() { } else { console.warn("⚠️ No 'username' parameter is present."); } - }, [username, fromQuery, imageUrl, expandedDetails]); + }, [username, fromQuery, displayName, imageUrl, expandedDetails]); useEffect(() => { if (Platform.OS === 'web') { @@ -239,12 +240,12 @@ export default function PublicProfilePage() { ) : ( - {(journey.username || 'U')[0].toUpperCase()} + {(journey.displayName?.trim() || journey.username || 'U')[0].toUpperCase()} )} - @{journey.username} + {journey.displayName?.trim() || `@${journey.username}`} {journey.statistics?.goals || 0} Goals • {journey.statistics?.experiences || 0} Experiences diff --git a/frontend/tests/journey-graph.test.mjs b/frontend/tests/journey-graph.test.mjs index 00e0d36..fc148c6 100644 --- a/frontend/tests/journey-graph.test.mjs +++ b/frontend/tests/journey-graph.test.mjs @@ -224,3 +224,12 @@ for (const mode of ['public', 'personal']) { }); } } + +test('graph display name preserves center identity and legacy fallback', () => { + const journey={username:'test1',displayName:' Rohinth ',goals:[],experiences:[],transitions:[]}; + const center=JSON.parse(buildJourneyGraphElements(journey))[0].data; + assert.equal(center.id,'user'); assert.equal(center.label,'Rohinth'); + for(const name of [undefined,null,' ']) { + assert.equal(JSON.parse(buildJourneyGraphElements({...journey,displayName:name}))[0].data.label,'@test1'); + } +}); diff --git a/frontend/tests/publicDisplayName.test.mjs b/frontend/tests/publicDisplayName.test.mjs new file mode 100644 index 0000000..b2042e1 --- /dev/null +++ b/frontend/tests/publicDisplayName.test.mjs @@ -0,0 +1,14 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +const page=readFileSync(new URL('../app/u/[username].tsx',import.meta.url),'utf8'); +const results=readFileSync(new URL('../app/results.tsx',import.meta.url),'utf8'); +test('search journey navigation passes display name without replacing username path',()=>{ + assert.ok(results.includes('pathname: `/u/${user.username}`')); + assert.ok(results.includes("displayName: user.displayName ?? ''")); +}); +test('public journey uses optional display name but shares stable username URL',()=>{ + assert.ok(page.includes('displayName: displayName?.trim() || null')); + assert.ok(page.includes('journey.displayName?.trim() || `@${journey.username}`')); + assert.ok(page.includes('buildPublicJourneyUrl(journey.username)')); +}); diff --git a/frontend/utils/journeyGraph.ts b/frontend/utils/journeyGraph.ts index d77cb0a..147d379 100644 --- a/frontend/utils/journeyGraph.ts +++ b/frontend/utils/journeyGraph.ts @@ -3,13 +3,13 @@ import { L } from '../constants/colors'; /** Retains the node IDs used by both screens' detail sheets. */ export function buildJourneyGraphElements( - journey: UserJourneyResponse | null, + journey: (UserJourneyResponse & { displayName?: string | null }) | null, { filterMissingTransitions = false }: { filterMissingTransitions?: boolean } = {}, ): string { if (!journey) return "[]"; const elements: { data: Record }[] = []; // User Node - elements.push({ data: { id: 'user', label: '@' + journey.username, color: L.navy, shape: 'ellipse', textColor: '#fff', borderWidth: 0, borderColor: '#000' } }); + elements.push({ data: { id: 'user', label: journey.displayName?.trim() || '@' + journey.username, color: L.navy, shape: 'ellipse', textColor: '#fff', borderWidth: 0, borderColor: '#000' } }); // Goals journey.goals.forEach(g => {