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
28 changes: 28 additions & 0 deletions ui/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ vi.mock('./shared/routing/routing', () => ({
getAppUrl: vi.fn(),
}))

vi.mock('./causestarter/shell/CauseShell', () => ({
CauseShell: ({ children }: { children: React.ReactNode }) => (
<div data-testid="cause-shell">{children}</div>
),
}))

vi.mock('./shared/components/AppShell', () => ({
AppShell: ({ branding, navigation, children }: { branding: { name: string }; navigation: { primaryNavigation: Array<{label: string; path: string}>; secondaryNavigation: Array<{label: string; path: string}>; footerText: string }; children: React.ReactNode }) => (
<div data-testid="app-shell">
Expand Down Expand Up @@ -134,6 +140,28 @@ describe('App route composition', () => {

expect(screen.getByText('Common Sense Majority')).toBeInTheDocument()
})

it('sets the document title from domain branding', async () => {
mockGetActiveDomain.mockReturnValue(fakeDomain('CauseStarter', [], 'footer'))

const { default: App } = await import('./App')
render(React.createElement(App))

expect(document.title).toBe('CauseStarter')
})

it('sets the document title when using CauseShell', async () => {
mockGetActiveDomain.mockReturnValue({
...fakeDomain('CauseStarter', [], 'footer'),
useCauseShell: true,
})

const { default: App } = await import('./App')
render(React.createElement(App))

expect(screen.getByTestId('cause-shell')).toBeInTheDocument()
expect(document.title).toBe('CauseStarter')
})
})

describe('primary navigation per domain', () => {
Expand Down
5 changes: 5 additions & 0 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { CauseShell } from './causestarter/shell/CauseShell'

function DomainChrome({ children }: { children: ReactNode }) {
const domain = getActiveDomain()

useEffect(() => {
document.title = domain.branding.name
}, [domain.branding.name])

if (domain.useCauseShell) {
return <CauseShell>{children}</CauseShell>
}
Expand Down
6 changes: 1 addition & 5 deletions ui/src/shared/components/AppShell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'
import { useState } from 'react'
import type { MouseEvent, ReactNode } from 'react'
import {
AppBar,
Expand Down Expand Up @@ -208,10 +208,6 @@ export function AppShell({ children, branding, navigation }: AppShellProps) {
tagline: 'Find common ground and fund what matters.',
}

useEffect(() => {
document.title = brand.name
}, [brand.name])

const nav = navigation ?? {
primaryNavigation: [
{ label: 'Start Here', path: '/docs' },
Expand Down
25 changes: 24 additions & 1 deletion ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig(({ mode }) => {
build: {
outDir: `dist/${domain}`,
},
plugins: [react(), runtimeConfigPlugin(domain, env), endUserDocsPlugin({ domain })],
plugins: [react(), htmlTitlePlugin(domain), runtimeConfigPlugin(domain, env), endUserDocsPlugin({ domain })],
worker: {
format: 'es',
},
Expand Down Expand Up @@ -102,6 +102,29 @@ function sdkSourceAliases(): Record<string, string> {
)
}

// Must match branding.name in ui/src/domains/*/manifest.tsx (Vite cannot import those TSX files here).
const DOMAIN_TITLES: Record<string, string> = {
commonality: 'Commonality',
lazyGiving: 'LazyGiving',
alignment: 'Aligning',
tally: 'Tally',
'content-funding': 'Content Funding',
civility: 'Civility',
'common-sense-majority': 'Common Sense Majority',
conceptspace: 'Conceptspace',
causestarter: 'CauseStarter',
}

function htmlTitlePlugin(buildDomain: string): Plugin {
const title = DOMAIN_TITLES[buildDomain] ?? 'Commonality'
return {
name: 'commonality-html-title',
transformIndexHtml(html) {
return html.replace(/<title>[^<]*<\/title>/, `<title>${title}</title>`)
},
}
}

function runtimeConfigPlugin(buildDomain: string, env: Record<string, string>): Plugin {
return {
name: 'commonality-runtime-config',
Expand Down
Loading