Skip to content

Commit

Permalink
export/import from @frogpond/app-config, add convenience hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
drewvolz committed Oct 15, 2023
1 parent f1ae317 commit 09d878f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
21 changes: 20 additions & 1 deletion modules/app-config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react'
import {getFeatureFlag} from '../../source/lib/storage'
import {AppConfigKey, AppConfigGroupKey, FeatureFlagType} from './types'
import {useQuery} from '@tanstack/react-query'

export type {FeatureFlagType} from './types'
export type {AppConfigKey, FeatureFlagType} from './types'

// datastore for the __DEV__ feature flags
export const AppConfig = async (): Promise<FeatureFlagType[]> => {
return [
{
Expand All @@ -13,3 +16,19 @@ export const AppConfig = async (): Promise<FeatureFlagType[]> => {
},
]
}

// helper method to query exported __DEV__ feature flags
const useFeature = (featureKey: AppConfigKey): boolean => {
let {data: featureValue = false} = useQuery({
queryKey: ['app', 'app:feature-flag', featureKey],
queryFn: () => getFeatureFlag(featureKey),
onSuccess: (newValue) => {
return newValue
},
})

return featureValue
}

// exported feature flags
export const useMockedStoprint = (): boolean => useFeature(AppConfigKey.MockStoprintData)
20 changes: 0 additions & 20 deletions source/lib/stoprint/debug.ts

This file was deleted.

1 change: 0 additions & 1 deletion source/lib/stoprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ export type {
HeldJobsResponse,
} from './types'
export {showGeneralError} from './errors'
export {useMockedStoprint} from './debug'
3 changes: 2 additions & 1 deletion source/views/stoprint/print-jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from 'react'
import {timezone} from '@frogpond/constants'
import {Platform, SectionList} from 'react-native'
import type {PrintJob} from '../../lib/stoprint'
import {STOPRINT_HELP_PAGE, useMockedStoprint} from '../../lib/stoprint'
import {STOPRINT_HELP_PAGE} from '../../lib/stoprint'
import {useMockedStoprint} from '@frogpond/app-config'
import {
Detail,
ListRow,
Expand Down
2 changes: 1 addition & 1 deletion source/views/stoprint/query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useQuery, UseQueryResult} from '@tanstack/react-query'
import {useUsername} from '../../lib/login'
import {useMockedStoprint} from '../../lib/stoprint'
import {useMockedStoprint} from '@frogpond/app-config'
import {
fetchAllPrinters,
fetchColorPrinters,
Expand Down

0 comments on commit 09d878f

Please sign in to comment.