Skip to content

Commit

Permalink
feat: store select multiple routes in local storage
Browse files Browse the repository at this point in the history
Closes #91
  • Loading branch information
iamandrewluca committed Dec 2, 2019
1 parent 4655633 commit 56366e6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/route-select.dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function RouteSelectDialog(props: Props) {
const theme = useTheme<Theme>()
const classes = useStyles()
const fullScreen = useMediaQuery(theme.breakpoints.down('xs'))
const [selectMultiple, setSelectMultiple] = useState(false)
const [selectMultiple, setSelectMultiple] = useSelectMultiple()
const [l10n] = useTranslation()

function selectRoute(id: string) {
Expand Down Expand Up @@ -108,3 +108,21 @@ export function RouteSelectDialog(props: Props) {
</Dialog>
)
}

function useSelectMultiple(): [boolean, (value: boolean) => void] {
const [selectMultiple, setSelectMultiple] = useState<boolean>(() => {
try {
const fromStorage = localStorage.getItem('select-multiple')
return fromStorage ? JSON.parse(fromStorage) : false
} catch {
return false
}
})

function _setSelectMultiple(value: boolean) {
localStorage.setItem('select-multiple', value.toString())
return setSelectMultiple(value)
}

return [selectMultiple, _setSelectMultiple]
}

0 comments on commit 56366e6

Please sign in to comment.