Decentralize definitions from schema file (James feedback)
This commit is contained in:
parent
953e65f707
commit
17f819e155
|
@ -1,7 +1,10 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useFirestoreDocumentData } from '@react-query-firebase/firestore'
|
||||
import { Contract, listenForContract } from 'web/lib/firebase/contracts'
|
||||
import { contracts } from 'web/lib/firebase/schema'
|
||||
import {
|
||||
Contract,
|
||||
contracts,
|
||||
listenForContract,
|
||||
} from 'web/lib/firebase/contracts'
|
||||
import { useStateCheckEquality } from './use-state-check-equality'
|
||||
import { doc, DocumentData } from 'firebase/firestore'
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ import {
|
|||
listenForPrivateUser,
|
||||
listenForUser,
|
||||
User,
|
||||
users,
|
||||
} from 'web/lib/firebase/users'
|
||||
import { users } from 'web/lib/firebase/schema'
|
||||
import { useStateCheckEquality } from './use-state-check-equality'
|
||||
import { identifyUser, setUserProperty } from 'web/lib/service/analytics'
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ import {
|
|||
} from 'firebase/firestore'
|
||||
import { sortBy, sum } from 'lodash'
|
||||
|
||||
import { getValues, listenForValue, listenForValues } from './utils'
|
||||
import { contracts } from './schema'
|
||||
import { coll, getValues, listenForValue, listenForValues } from './utils'
|
||||
import { BinaryContract, Contract } from 'common/contract'
|
||||
import { getDpmProbability } from 'common/calculate-dpm'
|
||||
import { createRNG, shuffle } from 'common/util/random'
|
||||
|
@ -27,6 +26,9 @@ import { MAX_FEED_CONTRACTS } from 'common/recommended-contracts'
|
|||
import { Bet } from 'common/bet'
|
||||
import { Comment } from 'common/comment'
|
||||
import { ENV_CONFIG } from 'common/envs/constants'
|
||||
|
||||
export const contracts = coll<Contract>('contracts')
|
||||
|
||||
export type { Contract }
|
||||
|
||||
export function contractPath(contract: Contract) {
|
||||
|
|
|
@ -9,10 +9,17 @@ import {
|
|||
import { sortBy } from 'lodash'
|
||||
import { Group } from 'common/group'
|
||||
import { getContractFromId } from './contracts'
|
||||
import { groups } from './schema'
|
||||
import { getValue, getValues, listenForValue, listenForValues } from './utils'
|
||||
import {
|
||||
coll,
|
||||
getValue,
|
||||
getValues,
|
||||
listenForValue,
|
||||
listenForValues,
|
||||
} from './utils'
|
||||
import { filterDefined } from 'common/util/array'
|
||||
|
||||
export const groups = coll<Group>('groups')
|
||||
|
||||
export function groupPath(
|
||||
groupSlug: string,
|
||||
subpath?: 'edit' | 'questions' | 'about' | 'chat'
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { getDoc, orderBy, query, setDoc, where } from 'firebase/firestore'
|
||||
import { doc } from 'firebase/firestore'
|
||||
import { Manalink } from '../../../common/manalink'
|
||||
import { manalinks } from './schema'
|
||||
import { customAlphabet } from 'nanoid'
|
||||
import { listenForValues } from './utils'
|
||||
import { coll, listenForValues } from './utils'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export const manalinks = coll<Manalink>('manalinks')
|
||||
|
||||
export async function createManalink(data: {
|
||||
fromId: string
|
||||
amount: number
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import { db } from './init'
|
||||
import { collection, CollectionReference } from 'firebase/firestore'
|
||||
|
||||
import { Contract } from 'common/contract'
|
||||
import { User, PrivateUser } from 'common/user'
|
||||
import { Txn } from 'common/txn'
|
||||
import { Group } from 'common/group'
|
||||
import { Manalink } from 'common/manalink'
|
||||
|
||||
const coll = <T>(path: string, ...rest: string[]) => {
|
||||
return collection(db, path, ...rest) as CollectionReference<T>
|
||||
}
|
||||
|
||||
export const groups = coll<Group>('groups')
|
||||
export const manalinks = coll<Manalink>('manalinks')
|
||||
export const privateUsers = coll<PrivateUser>('private-users')
|
||||
export const txns = coll<Txn>('txns')
|
||||
export const contracts = coll<Contract>('contracts')
|
||||
export const users = coll<User>('users')
|
|
@ -1,10 +1,11 @@
|
|||
import { ManalinkTxn, DonationTxn, TipTxn } from 'common/txn'
|
||||
import { ManalinkTxn, DonationTxn, TipTxn, Txn } from 'common/txn'
|
||||
import { orderBy, query, where } from 'firebase/firestore'
|
||||
import { txns } from './schema'
|
||||
import { getValues, listenForValues } from './utils'
|
||||
import { coll, getValues, listenForValues } from './utils'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { orderBy as _orderBy } from 'lodash'
|
||||
|
||||
export const txns = coll<Txn>('txns')
|
||||
|
||||
const getCharityQuery = (charityId: string) =>
|
||||
query(
|
||||
txns,
|
||||
|
|
|
@ -23,15 +23,23 @@ import {
|
|||
import { throttle, zip } from 'lodash'
|
||||
|
||||
import { app, db } from './init'
|
||||
import { privateUsers, users } from './schema'
|
||||
import { PortfolioMetrics, PrivateUser, User } from 'common/user'
|
||||
import { createUser } from './fn-call'
|
||||
import { getValue, getValues, listenForValue, listenForValues } from './utils'
|
||||
import {
|
||||
coll,
|
||||
getValue,
|
||||
getValues,
|
||||
listenForValue,
|
||||
listenForValues,
|
||||
} from './utils'
|
||||
import { feed } from 'common/feed'
|
||||
import { CATEGORY_LIST } from 'common/categories'
|
||||
import { safeLocalStorage } from '../util/local'
|
||||
import { filterDefined } from 'common/util/array'
|
||||
|
||||
export const users = coll<User>('users')
|
||||
export const privateUsers = coll<PrivateUser>('private-users')
|
||||
|
||||
export type { User }
|
||||
|
||||
export type Period = 'daily' | 'weekly' | 'monthly' | 'allTime'
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
import {
|
||||
collection,
|
||||
getDoc,
|
||||
getDocs,
|
||||
onSnapshot,
|
||||
Query,
|
||||
CollectionReference,
|
||||
DocumentReference,
|
||||
} from 'firebase/firestore'
|
||||
import { db } from './init'
|
||||
|
||||
export const coll = <T>(path: string, ...rest: string[]) => {
|
||||
return collection(db, path, ...rest) as CollectionReference<T>
|
||||
}
|
||||
|
||||
export const getValue = async <T>(doc: DocumentReference) => {
|
||||
const snap = await getDoc(doc)
|
||||
|
|
Loading…
Reference in New Issue
Block a user