A calm place to write long-form, and publish it to the open social web. skypress.blog/
0

Configure Feed

Select the types of activity you want to include in your feed.

Add accountMenuItems helper for the masthead menu

+43 -1
+20 -1
src/lib/auth/profile.test.ts
··· 1 1 import { describe, expect, it, vi } from 'vitest'; 2 2 import type { Agent } from '@atproto/api'; 3 - import { fetchViewerProfile, displayNameFor, authorPath } from './profile'; 3 + import { fetchViewerProfile, displayNameFor, authorPath, accountMenuItems } from './profile'; 4 4 5 5 /** Minimal Agent stub: only getProfile is exercised. */ 6 6 function agentReturning( data: Record< string, unknown > ): Agent { ··· 69 69 expect( authorPath( null ) ).toBeNull(); 70 70 } ); 71 71 } ); 72 + 73 + describe( 'accountMenuItems', () => { 74 + const base = { did: 'did:plc:abc', displayName: 'Jane Rivera', avatar: null }; 75 + 76 + it( 'returns Dashboard, Write and Profile in order for a profile with a handle', () => { 77 + expect( accountMenuItems( { ...base, handle: 'jane.bsky.social' } ) ).toEqual( [ 78 + { label: 'Dashboard', href: '/dashboard' }, 79 + { label: 'Write', href: '/editor' }, 80 + { label: 'Profile', href: '/@jane.bsky.social' }, 81 + ] ); 82 + } ); 83 + 84 + it( 'omits the Profile item when no handle is known', () => { 85 + expect( accountMenuItems( { ...base, handle: null } ) ).toEqual( [ 86 + { label: 'Dashboard', href: '/dashboard' }, 87 + { label: 'Write', href: '/editor' }, 88 + ] ); 89 + } ); 90 + } );
+23
src/lib/auth/profile.ts
··· 40 40 export function authorPath( handle: string | null ): string | null { 41 41 return handle ? `/@${ handle }` : null; 42 42 } 43 + 44 + /** One entry in the signed-in account dropdown. */ 45 + export interface MenuItem { 46 + label: string; 47 + href: string; 48 + } 49 + 50 + /** 51 + * Dropdown items for a signed-in viewer: Dashboard, Write, then Profile. The 52 + * Profile entry links to the public author page and is omitted when no handle 53 + * is known (so we never render a broken link). 54 + */ 55 + export function accountMenuItems( profile: ViewerProfile ): MenuItem[] { 56 + const items: MenuItem[] = [ 57 + { label: 'Dashboard', href: '/dashboard' }, 58 + { label: 'Write', href: '/editor' }, 59 + ]; 60 + const profileHref = authorPath( profile.handle ); 61 + if ( profileHref ) { 62 + items.push( { label: 'Profile', href: profileHref } ); 63 + } 64 + return items; 65 + }