Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
speechChunks,
type ReaderSpeechPreferences
} from './readerSpeech'
import { shouldShowAdminNavigation } from './navigation'

type WalletSubstrate = 'auto' | 'json-api' | 'secure-json-api' | 'react-native' | 'Cicada' | 'XDM' | 'window.CWI'

Expand Down Expand Up @@ -1197,7 +1198,7 @@ function Shell ({ children, status }: { children: React.ReactNode, status: Statu
<Link to='/about'><Info size={18} /> About</Link>
<Link to='/settings'><SlidersHorizontal size={18} /> Reader settings</Link>
<Link to='/author'><User size={18} /> Author</Link>
<Link to='/admin'><Settings size={18} /> Admin</Link>
{shouldShowAdminNavigation(status?.isAdmin) && <Link to='/admin'><Settings size={18} /> Admin</Link>}
</nav>
<button
className='nav-feedback'
Expand Down
17 changes: 17 additions & 0 deletions src/client/navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { shouldShowAdminNavigation } from './navigation'

describe('shouldShowAdminNavigation', () => {
it('hides admin navigation while status is unknown', () => {
expect(shouldShowAdminNavigation(undefined)).toBe(false)
expect(shouldShowAdminNavigation(null)).toBe(false)
})

it('hides admin navigation for non-admins', () => {
expect(shouldShowAdminNavigation(false)).toBe(false)
})

it('shows admin navigation for admins', () => {
expect(shouldShowAdminNavigation(true)).toBe(true)
})
})
3 changes: 3 additions & 0 deletions src/client/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function shouldShowAdminNavigation (isAdmin: boolean | null | undefined): boolean {
return isAdmin === true
}