Skip to content

Commit bb3e0bf

Browse files
committed
flatten remote config store
1 parent 7401a85 commit bb3e0bf

6 files changed

Lines changed: 33 additions & 29 deletions

File tree

src/App.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ function App() {
1313
const [showSideBar, setShowSideBar] = useState(false)
1414
const [showSettings, setShowSettings] = useState(false)
1515

16-
const {
17-
remoteConfig: { marketingBannerConfig },
18-
} = useRemoteConfigStore()
16+
const { marketingBannerConfig } = useRemoteConfigStore()
1917

2018
useEffect(() => {
2119
setupAnalytics()

src/features/carbonAds/components/CarbonAd.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import './CarbonAd.css'
22
import { addHttpsProtocol } from 'src/utils/UrlUtils'
33
import { useGetAd } from '../api/getAd'
4+
import { useRemoteConfigStore } from 'src/features/remoteConfig'
45
export const CarbonAd = () => {
5-
const { data: ad } = useGetAd()
6+
const { refresh_rate } = useRemoteConfigStore()
7+
const { data: ad } = useGetAd({
8+
config: {
9+
refetchInterval: refresh_rate,
10+
},
11+
})
612

713
if (!ad) {
814
return null
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
import create from 'zustand';
22
import { persist } from 'zustand/middleware'
3-
import { RemoteConfig } from "../types";
3+
import { RemoteConfig, Tag, MarketingBannerConfig } from "../types";
44

55
type ChangelogVersionStore = {
6-
remoteConfig: RemoteConfig;
6+
supportedTags: Tag[];
7+
refresh_rate: number | false;
8+
marketingBannerConfig?: MarketingBannerConfig;
79
setRemoteConfig: (remoteConfig: RemoteConfig) => void;
810
};
911

1012
export const useRemoteConfigStore = create(persist<ChangelogVersionStore>((set) => ({
11-
remoteConfig: {
12-
marketingBannerConfig: undefined,
13-
supportedTags: [
14-
{
15-
value: 'javascript',
16-
label: 'Javascript',
17-
githubValues: ['javascript'],
18-
confsValues: ['javascript'],
19-
devtoValues: ['javascript'],
20-
hashnodeValues: ['javascript'],
21-
mediumValues: ['javascript'],
22-
redditValues: ['javascript'],
23-
freecodecampValues: ['javascript']
24-
},
25-
],
26-
},
13+
marketingBannerConfig: undefined,
14+
refresh_rate: false,
15+
supportedTags: [
16+
{
17+
value: 'javascript',
18+
label: 'Javascript',
19+
githubValues: ['javascript'],
20+
confsValues: ['javascript'],
21+
devtoValues: ['javascript'],
22+
hashnodeValues: ['javascript'],
23+
mediumValues: ['javascript'],
24+
redditValues: ['javascript'],
25+
freecodecampValues: ['javascript']
26+
},
27+
],
2728
setRemoteConfig: (remoteConfig: RemoteConfig) =>
28-
set(() => ({
29-
remoteConfig: remoteConfig,
30-
}))
29+
set(() => {
30+
return { ...remoteConfig }
31+
}),
3132
}), {
3233
name: 'remote_config_storage',
3334
}));

src/features/remoteConfig/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export type MarketingBannerConfig = {
2727

2828
export type RemoteConfig = {
2929
supportedTags: Tag[]
30+
refresh_rate: number | false,
3031
marketingBannerConfig?: MarketingBannerConfig
3132
}

src/features/settings/components/SettingsModal.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ type OptionType = {
3838
}
3939

4040
export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalProps) => {
41-
const {
42-
remoteConfig: { supportedTags },
43-
} = useRemoteConfigStore()
41+
const { supportedTags } = useRemoteConfigStore()
4442

4543
const {
4644
cards,

src/utils/DataEnhancement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Tag, useRemoteConfigStore, TagValuesFieldType } from 'src/features/remoteConfig'
22

33
export const enhanceTags = (tags: string[]): Tag[] => {
4-
const savedTags = useRemoteConfigStore.getState().remoteConfig.supportedTags
4+
const savedTags = useRemoteConfigStore.getState().supportedTags
55

66
return tags
77
.map((tag) => savedTags.find((st) => st.value.toLowerCase() === tag.toLocaleString()))

0 commit comments

Comments
 (0)