Skip to content

Commit

Permalink
fix: settings menu now should use store
Browse files Browse the repository at this point in the history
  • Loading branch information
lightlii committed Aug 23, 2023
1 parent 6e0a7a6 commit d195f55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
22 changes: 9 additions & 13 deletions src/renderer/components/SettingsView/ExperimentsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ import React from 'react'
import { defineMessages } from 'react-intl'
import { Map as MapIcon } from '@material-ui/icons'
import { SettingsList } from './SettingsList'
import { useExperimentsFlagsStore } from '../../hooks/store'

const m = defineMessages({
backgroundMaps: 'Background Maps',
backgroundMaps: 'Background Maps'
})

/**
* @typedef ExperiementsMenuProps
* @prop {boolean} backgroundMaps
* @prop {(e: React.Dispatch<boolean>) => number} setBackgroundMaps
*/
export const ExperiementsMenu = () => {
const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsStore(
store => [store.backgroundMaps, store.setBackgroundMapsFlag]
)

/** @param {ExperiementsMenuProps} props */
export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => {
const toggleBackgroundMaps = () => {
setBackgroundMaps(prevState => {
return !prevState
})
setBackgroundMaps(!backgroundMaps)
}

/** @type {import('./SettingsList').option[]} */
Expand All @@ -29,8 +25,8 @@ export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => {
label: m.backgroundMaps,
checked: backgroundMaps,
onClick: toggleBackgroundMaps,
type: 'toggle',
},
type: 'toggle'
}
]

return <SettingsList options={options} />
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/SettingsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { defineMessages } from 'react-intl'
import { AboutMapeoMenu } from './AboutMapeo'
import styled from 'styled-components'
import { ExperiementsMenu } from './ExperimentsMenu'
import createPersistedState from '../../hooks/createPersistedState'
import { BackgroundMaps } from './BackgroundMaps'
import { useExperimentsFlagsStore } from '../../hooks/store'

const m = defineMessages({
aboutMapeo: 'About Mapeo',
Expand All @@ -18,10 +18,10 @@ const m = defineMessages({
backgroundMaps: 'Background maps'
})

const useExperimentsFlagsState = createPersistedState('experimentsFlags')

export const SettingsView = () => {
const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsState(false)
const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsStore(
store => [store.backgroundMaps, store.backgroundMaps]
)
const tabs = /** @type {import('./SettingsMenu').tabs} */ [
{
tabId: 'AboutMapeo',
Expand Down

0 comments on commit d195f55

Please sign in to comment.