import React, { Component } from 'react'; import { List, ListItem, ListItemText, ListSubheader, ListItemSecondaryAction, Paper, IconButton, withStyles, Button, Switch, Dialog, DialogTitle, DialogContent, RadioGroup, FormControlLabel, Radio, DialogActions, DialogContentText, Grid, Theme } 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 {canSendNotifications, browserSupportsNotificationRequests} from '../utilities/notifications'; import {themes, defaultTheme} from '../types/HyperspaceTheme'; import ThemePreview from '../components/ThemePreview'; import {setHyperspaceTheme, getHyperspaceTheme} from '../utilities/themes'; interface ISettingsState { darkModeEnabled: boolean; pushNotificationsEnabled: boolean; badgeDisplaysAllNotifs: boolean; selectThemeName: string; themeDialogOpen: boolean; resetHyperspaceDialog: boolean; resetSettingsDialog: boolean; previewTheme: Theme; } class SettingsPage extends Component { constructor(props: any) { super(props); this.state = { darkModeEnabled: getUserDefaultBool('darkModeEnabled'), pushNotificationsEnabled: canSendNotifications(), badgeDisplaysAllNotifs: getUserDefaultBool('displayAllOnNotificationBadge'), selectThemeName: getUserDefaultTheme().key, themeDialogOpen: false, resetHyperspaceDialog: false, resetSettingsDialog: false, previewTheme: setHyperspaceTheme(getUserDefaultTheme()) || setHyperspaceTheme(defaultTheme) } this.toggleDarkMode = this.toggleDarkMode.bind(this); this.togglePushNotifications = this.togglePushNotifications.bind(this); this.toggleBadgeCount = this.toggleBadgeCount.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); } toggleBadgeCount() { this.setState({ badgeDisplaysAllNotifs: !this.state.badgeDisplaysAllNotifs }); setUserDefaultBool('displayAllOnNotificationBadge', !this.state.badgeDisplaysAllNotifs); } toggleThemeDialog() { this.setState({ themeDialogOpen: !this.state.themeDialogOpen }); } toggleResetDialog() { this.setState({ resetHyperspaceDialog: !this.state.resetHyperspaceDialog }); } toggleResetSettingsDialog() { this.setState({ resetSettingsDialog: !this.state.resetSettingsDialog }); } changeTheme() { setUserDefaultTheme(this.state.selectThemeName); window.location.reload(); } changeThemeName(theme: string) { let previewTheme = setHyperspaceTheme(getHyperspaceTheme(theme)); this.setState({ selectThemeName: theme, previewTheme }); } reset() { localStorage.clear(); window.location.reload(); } refresh() { let settings = ['darkModeEnabled', 'enablePushNotifications', 'clearNotificationsOnRead', 'theme', 'displayAllOnNotificationBadge']; settings.forEach(setting => { localStorage.removeItem(setting); }) window.location.reload(); } showThemeDialog() { const {classes} = this.props; return ( Choose a theme this.changeThemeName(value)} > {themes.map(theme => ( } label={theme.name} /> ))} ))} ); } showResetSettingsDialog() { return ( this.toggleResetSettingsDialog()} > Are you sure you want to refresh settings? ); } showResetDialog() { return ( this.toggleResetDialog()} > Reset Hyperspace? Are you sure you want to reset Hyperspace? You'll need to sign in again and grant Hyperspace access to use it again. ); } render() { const { classes } = this.props; return (
Appearance
Notifications { browserSupportsNotificationRequests()? : null }
Accounts
Advanced {this.showThemeDialog()} {this.showResetDialog()} {this.showResetSettingsDialog()}
); } } export default withStyles(styles)(SettingsPage);