Page MenuHomePhabricator

D8652.id29180.diff
No OneTemporary

D8652.id29180.diff

diff --git a/native/components/feature-flags-provider.react.js b/native/components/feature-flags-provider.react.js
--- a/native/components/feature-flags-provider.react.js
+++ b/native/components/feature-flags-provider.react.js
@@ -1,5 +1,6 @@
// @flow
+import AsyncStorage from '@react-native-async-storage/async-storage';
import * as React from 'react';
import { Platform } from 'react-native';
@@ -14,17 +15,19 @@
type FeatureFlagsContextType = {
+configuration: FeatureFlagsConfiguration,
- +loaded: boolean,
+ +loadedFromService: boolean,
};
const defaultContext = {
configuration: {},
- loaded: false,
+ loadedFromService: false,
};
const FeatureFlagsContext: React.Context<FeatureFlagsContextType> =
React.createContext<FeatureFlagsContextType>(defaultContext);
+const featureFlagsStorageKey = 'FeatureFlags';
+
type Props = {
+children: React.Node,
};
@@ -33,6 +36,31 @@
const isStaff = useIsCurrentUserStaff();
const [featuresConfig, setFeaturesConfig] = React.useState(defaultContext);
+
+ React.useEffect(() => {
+ (async () => {
+ if (featuresConfig.loadedFromService) {
+ return;
+ }
+
+ const persistedFeaturesConfig = await AsyncStorage.getItem(
+ featureFlagsStorageKey,
+ );
+ if (!persistedFeaturesConfig) {
+ return;
+ }
+
+ setFeaturesConfig(config =>
+ config.loadedFromService
+ ? config
+ : {
+ configuration: JSON.parse(persistedFeaturesConfig),
+ loadedFromService: false,
+ },
+ );
+ })();
+ }, [featuresConfig.loadedFromService]);
+
React.useEffect(() => {
(async () => {
try {
@@ -47,8 +75,12 @@
}
setFeaturesConfig({
configuration,
- loaded: true,
+ loadedFromService: true,
});
+ await AsyncStorage.setItem(
+ featureFlagsStorageKey,
+ JSON.stringify(configuration),
+ );
} catch (e) {
console.error('Feature flag retrieval failed:', e);
}

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 11, 2:10 AM (20 h, 4 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2858316
Default Alt Text
D8652.id29180.diff (2 KB)

Event Timeline