manifold/web/lib/firebase/globalConfig.ts
FRC ff6278b147
Featured items to homepage (#1024)
* Featured items to homepage

* Fix nits
2022-10-12 15:04:39 +01:00

34 lines
827 B
TypeScript

import {
CollectionReference,
doc,
collection,
getDoc,
updateDoc,
} from 'firebase/firestore'
import { db } from 'web/lib/firebase/init'
import { GlobalConfig } from 'common/globalConfig'
import { listenForValue } from './utils'
const globalConfigCollection = collection(
db,
'globalConfig'
) as CollectionReference<GlobalConfig>
const globalConfigDoc = doc(globalConfigCollection, 'globalConfig')
export const getGlobalConfig = async () => {
return (await getDoc(globalConfigDoc)).data()
}
export function updateGlobalConfig(
globalConfig: GlobalConfig,
updates: Partial<GlobalConfig>
) {
return updateDoc(globalConfigDoc, updates)
}
export function listenForGlobalConfig(
setGlobalConfig: (globalConfig: GlobalConfig | null) => void
) {
return listenForValue(globalConfigDoc, setGlobalConfig)
}