Skip to content

Commit 127cfca

Browse files
committed
wip: inject colors into styles with DomainProvider
1 parent 3cf402e commit 127cfca

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

components/territory-domains.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,43 @@ import styles from './item.module.css'
1515
const DomainContext = createContext({
1616
domain: {
1717
domainName: null,
18-
subName: null
18+
subName: null,
19+
branding: null // wip-brandings
1920
}
2021
})
2122

2223
export const DomainProvider = ({ domain: ssrDomain, children }) => {
2324
const [domain, setDomain] = useState(ssrDomain || null)
2425

26+
// wip-brandings: this is a sketch/hack to set the branding colors
27+
const setBrandingColors = (branding) => {
28+
document.documentElement.style.setProperty('--bs-transition', 'all 0.3s ease')
29+
if (branding.primaryColor) {
30+
document.documentElement.style.setProperty('--theme-primary', branding.primaryColor)
31+
}
32+
if (branding.secondaryColor) {
33+
document.documentElement.style.setProperty('--theme-secondary', branding.secondaryColor)
34+
}
35+
36+
return () => {
37+
document.documentElement.style.removeProperty('--bs-transition')
38+
}
39+
}
40+
2541
// maintain the custom domain state across re-renders
2642
useEffect(() => {
2743
if (ssrDomain && !domain) {
2844
setDomain(ssrDomain)
2945
}
30-
}, [ssrDomain])
3146

32-
// TODO: Placeholder for Auth Sync
47+
// wip-brandings: set the branding colors
48+
if (ssrDomain?.branding) {
49+
setBrandingColors(ssrDomain.branding)
50+
}
51+
}, [ssrDomain])
3352

3453
return (
3554
<DomainContext.Provider value={{ domain }}>
36-
{/* TODO: Placeholder for Branding */}
3755
{children}
3856
</DomainContext.Provider>
3957
)

fragments/subs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,14 @@ export const TOP_SUBS = gql`
154154
}
155155
}
156156
`
157+
158+
export const SUB_BRANDING = gql`
159+
fragment SubBrandingFields on SubBranding {
160+
title
161+
description
162+
logoId
163+
faviconId
164+
primaryColor
165+
secondaryColor
166+
}
167+
`

0 commit comments

Comments
 (0)