import React, { Component } from 'react'; import { List, ListItem, ListItemText, ListSubheader, ListItemSecondaryAction, Paper, IconButton, withStyles, Button, Switch, Dialog, DialogTitle, DialogContent, RadioGroup, FormControlLabel, Radio, DialogActions } from '@material-ui/core'; import OpenInNewIcon from '@material-ui/icons/OpenInNew'; import {styles} from './PageLayout.styles'; import {setUserDefaultBool, getUserDefaultBool, getUserDefaultTheme, setUserDefaultTheme} from '../utilities/settings'; import {themes} from '../types/HyperspaceTheme'; interface ISettingsState { darkModeEnabled: boolean; pushNotificationsEnabled: boolean; deleteNotificationsOnRead: boolean; selectThemeName: string; themeDialogOpen: boolean; } class SettingsPage extends Component { constructor(props: any) { super(props); this.state = { darkModeEnabled: getUserDefaultBool('darkModeEnabled'), pushNotificationsEnabled: getUserDefaultBool('enablePushNotifications'), deleteNotificationsOnRead: getUserDefaultBool('clearNotificationsOnRead'), selectThemeName: getUserDefaultTheme().key, themeDialogOpen: false } this.toggleDarkMode = this.toggleDarkMode.bind(this); this.togglePushNotifications = this.togglePushNotifications.bind(this); this.toggleClearNotifsOnRead = this.toggleClearNotifsOnRead.bind(this); this.toggleThemeDialog = this.toggleThemeDialog.bind(this); this.changeThemeName = this.changeThemeName.bind(this); this.changeTheme = this.changeTheme.bind(this); } toggleDarkMode() { this.setState({ darkModeEnabled: !this.state.darkModeEnabled }); setUserDefaultBool('darkModeEnabled', !this.state.darkModeEnabled); window.location.reload(); } togglePushNotifications() { this.setState({ pushNotificationsEnabled: !this.state.pushNotificationsEnabled }); setUserDefaultBool('enablePushNotifications', !this.state.pushNotificationsEnabled); } toggleClearNotifsOnRead() { this.setState({ deleteNotificationsOnRead: !this.state.deleteNotificationsOnRead }); setUserDefaultBool('clearNotificationsOnRead', !this.state.deleteNotificationsOnRead); } toggleThemeDialog() { this.setState({ themeDialogOpen: !this.state.themeDialogOpen }); } changeTheme() { setUserDefaultTheme(this.state.selectThemeName); window.location.reload(); } changeThemeName(theme: string) { this.setState({ selectThemeName: theme}); } showThemeDialog() { return ( Choose a color scheme this.changeThemeName(value)} > {themes.map(theme => ( } label={theme.name} /> ))} ))} ); } render() { const { classes } = this.props; return (
Appearance
Notifications
Accounts
Advanced {this.showThemeDialog()}
); } } export default withStyles(styles)(SettingsPage);