mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Clean
This commit is contained in:
@@ -131,7 +131,7 @@ function CreateCompatibilityModalContent(props: {
|
||||
const data = {
|
||||
question: question,
|
||||
options: generateJson(),
|
||||
}
|
||||
} as any
|
||||
const newQuestion = await api('create-compatibility-question', data)
|
||||
debug('create-compatibility-question', newQuestion, data)
|
||||
const q = newQuestion?.question
|
||||
|
||||
@@ -105,6 +105,7 @@ function useAndSetupFirebaseUser() {
|
||||
}
|
||||
|
||||
export const FirebaseUserContext = createContext<FirebaseUser | null | undefined>(undefined)
|
||||
|
||||
export const AuthContext = createContext<AuthUser>(undefined)
|
||||
|
||||
// function getSupabaseAuthCall() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Row} from 'common/supabase/utils'
|
||||
import {sortBy} from 'lodash'
|
||||
import {useEffect, useState} from 'react'
|
||||
import {useFirebaseUser} from 'web/hooks/use-firebase-user'
|
||||
import {usePersistentInMemoryState} from 'web/hooks/use-persistent-in-memory-state'
|
||||
import {useUser} from 'web/hooks/use-user'
|
||||
import {api} from 'web/lib/api'
|
||||
import {useLocale} from 'web/lib/locale'
|
||||
import {
|
||||
@@ -97,14 +97,14 @@ export const useFRQuestionsWithAnswerCount = () => {
|
||||
|
||||
export const useCompatibilityQuestionsWithAnswerCount = (keyword?: string) => {
|
||||
const {locale} = useLocale()
|
||||
const user = useUser()
|
||||
const firebaseUser = useFirebaseUser()
|
||||
const [compatibilityQuestions, setCompatibilityQuestions] = usePersistentInMemoryState<
|
||||
QuestionWithCountType[]
|
||||
>([], `compatibility-questions-with-count`)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
|
||||
async function refreshCompatibilityQuestions() {
|
||||
if (!user) return
|
||||
if (!firebaseUser) return
|
||||
setIsLoading(true)
|
||||
return api('get-compatibility-questions', {locale, keyword}).then((res) => {
|
||||
setCompatibilityQuestions(res.questions)
|
||||
@@ -114,7 +114,7 @@ export const useCompatibilityQuestionsWithAnswerCount = (keyword?: string) => {
|
||||
|
||||
useEffect(() => {
|
||||
refreshCompatibilityQuestions()
|
||||
}, [user, locale, keyword])
|
||||
}, [firebaseUser, locale, keyword])
|
||||
|
||||
return {
|
||||
refreshCompatibilityQuestions,
|
||||
|
||||
@@ -11,14 +11,7 @@ export async function api<P extends APIPath>(path: P, params: APIParams<P> = {})
|
||||
|
||||
try {
|
||||
if (authed) {
|
||||
if (auth.currentUser === undefined) {
|
||||
// Auth hasn't resolved yet — this is a bug in the caller, not a recoverable state
|
||||
console.error(
|
||||
`api('${path}') called before auth resolved — check the calling hook/component`,
|
||||
)
|
||||
throw new APIError(401, 'Auth not resolved yet')
|
||||
}
|
||||
|
||||
await auth.authStateReady()
|
||||
if (auth.currentUser === null) {
|
||||
// User is definitely not logged in
|
||||
console.error(`api('${path}') called while unauthenticated`)
|
||||
|
||||
Reference in New Issue
Block a user