Skip to content

Commit a5c77e2

Browse files
author
Jovert Lota Palonpon
committed
Added night mode toggle
1 parent dd7751e commit a5c77e2

File tree

7 files changed

+121
-13
lines changed

7 files changed

+121
-13
lines changed

resources/js/Backoffice.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Backoffice extends Component {
1212
loading: true,
1313
navigating: true,
1414
authenticated: false,
15+
nightMode: false,
1516
auth: {},
1617
user: {},
1718
username: '',
@@ -80,6 +81,26 @@ class Backoffice extends Component {
8081
} catch (error) {}
8182
};
8283

84+
/**
85+
* Handle nightmode toggle.
86+
* Store boolean value in persistent storage.
87+
*
88+
* @return {undefined}
89+
*/
90+
handleNightmodeToggled = () => {
91+
this.setState(prevState => {
92+
return {
93+
nightMode: !prevState.nightMode,
94+
};
95+
});
96+
97+
if (!this.state.nightMode) {
98+
window.localStorage.setItem('nightMode', true);
99+
} else {
100+
window.localStorage.removeItem('nightMode');
101+
}
102+
};
103+
83104
/**
84105
* Sign out the user, but retain the username.
85106
*
@@ -104,6 +125,19 @@ class Backoffice extends Component {
104125
await this.signout();
105126
};
106127

128+
/**
129+
* Set nightmode based on stored value in persistent storage.
130+
*
131+
* @return {undefined}
132+
*/
133+
setNightMode = () => {
134+
const nightMode = window.localStorage.getItem('nightMode');
135+
136+
this.setState({
137+
nightMode: nightMode ? true : false,
138+
});
139+
};
140+
107141
/**
108142
* Get the Authentication Data from the persistent storage.
109143
*
@@ -159,6 +193,8 @@ class Backoffice extends Component {
159193
await this.authenticate(JSON.stringify(auth));
160194
}
161195

196+
this.setNightMode();
197+
162198
this.setState({ loading: false, navigating: false });
163199
}
164200

@@ -180,6 +216,8 @@ class Backoffice extends Component {
180216
width,
181217
environment: 'backoffice',
182218
routes: ROUTES,
219+
handleNightmodeToggled: this
220+
.handleNightmodeToggled,
183221
refresh: this.refresh,
184222
authenticate: this.authenticate,
185223
handleLock: this.handleLock,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { SvgIcon } from '@material-ui/core';
3+
4+
const LightbulbOn = props => (
5+
<SvgIcon
6+
{...props}
7+
viewBox="0 0 24 24"
8+
>
9+
<path d="M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6C7.8 12.16 7 10.63 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z"></path>
10+
</SvgIcon>
11+
);
12+
13+
export default LightbulbOn;

resources/js/icons/1x1/LightbulbOn.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { SvgIcon } from '@material-ui/core';
3+
4+
const LightbulbOn = props => (
5+
<SvgIcon
6+
{...props}
7+
viewBox="0 0 24 24"
8+
>
9+
<path d="m9,21c0,0.55 0.45,1 1,1l4,0c0.55,0 1,-0.45 1,-1l0,-1l-6,0l0,1zm3,-19c-3.86,0 -7,3.14 -7,7c0,2.38 1.19,4.47 3,5.74l0,2.26c0,0.55 0.45,1 1,1l6,0c0.55,0 1,-0.45 1,-1l0,-2.26c1.81,-1.27 3,-3.36 3,-5.74c0,-3.86 -3.14,-7 -7,-7z" />
10+
</SvgIcon>
11+
);
12+
13+
export default LightbulbOn;

resources/js/icons/1x1/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as LightbulbOff } from './LightbulbOff';
2+
export { default as LightbulbOn } from './LightbulbOn';

resources/js/views/__backoffice/partials/Header.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import {
3737
Settings as SettingsIcon,
3838
} from '@material-ui/icons';
3939

40+
import {
41+
LightbulbOff as LightbulbOffIcon,
42+
LightbulbOn as LightbulbOnIcon,
43+
} from '../../../icons/1x1';
4044
import { Ph as PhIcon, Us as UsIcon } from '../../../icons/flags/4x3';
4145
import { Skeleton } from '../../../ui';
4246

@@ -232,7 +236,7 @@ const Header = props => {
232236
accountMenuOpen,
233237
} = parentProps;
234238

235-
const { user, navigating } = pageProps;
239+
const { user, navigating, nightMode, handleNightmodeToggled } = pageProps;
236240

237241
const skeletonProps = {
238242
color: colors.grey[400],
@@ -308,6 +312,17 @@ const Header = props => {
308312
/>
309313
</IconButton>
310314
</Grid>
315+
316+
<Grid item>
317+
<IconButton color="inherit">
318+
<Skeleton
319+
{...skeletonProps}
320+
circle
321+
height={30}
322+
width={30}
323+
/>
324+
</IconButton>
325+
</Grid>
311326
</Grid>
312327
</Toolbar>
313328
</AppBar>
@@ -462,6 +477,27 @@ const Header = props => {
462477
</Tooltip>
463478
</Grid>
464479

480+
<Grid item>
481+
<Tooltip
482+
title={
483+
nightMode
484+
? Lang.get('navigation.nightmode_off')
485+
: Lang.get('navigation.nightmode_on')
486+
}
487+
>
488+
<IconButton
489+
color="inherit"
490+
onClick={handleNightmodeToggled}
491+
>
492+
{nightMode ? (
493+
<LightbulbOnIcon />
494+
) : (
495+
<LightbulbOffIcon />
496+
)}
497+
</IconButton>
498+
</Tooltip>
499+
</Grid>
500+
465501
<Grid item>
466502
<Tooltip title={Lang.get('navigation.account')}>
467503
<div className={classes.navLinkMenuWrapper}>

resources/lang/en/navigation.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
'signin' => 'Sign in instead',
2424
'send_link' => 'Send Link',
2525

26-
'account' => 'Account',
27-
'profile' => 'Profile',
28-
'settings' => 'Settings',
29-
'lock' => 'Lock',
30-
'signout' => 'Sign out',
26+
'notifications' => 'Notifications',
3127

3228
'locale' => 'Locale',
3329
'english' => 'English',
3430
'filipino' => 'Filipino',
3531

36-
'notifications' => 'Notifications',
32+
'nightmode_on' => 'Toggle Night Mode On',
33+
'nightmode_off' => 'Toggle Night Mode Off',
34+
35+
'account' => 'Account',
36+
'profile' => 'Profile',
37+
'settings' => 'Settings',
38+
'lock' => 'Lock',
39+
'signout' => 'Sign out',
3740

3841
'help' => 'Help',
3942

resources/lang/fil/navigation.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
'signin' => 'Mag-sign in nalang',
2424
'send_link' => 'I-send ang Link',
2525

26-
'account' => 'Account',
27-
'profile' => 'Profile',
28-
'settings' => 'Mga Setting',
29-
'lock' => 'I-lock',
30-
'signout' => 'Mag-sign out',
26+
'notifications' => 'Mga Abiso',
3127

3228
'locale' => 'Lokal',
3329
'english' => 'Ingles',
3430
'filipino' => 'Filipino',
3531

36-
'notifications' => 'Mga Abiso',
32+
'nightmode_on' => 'I-On ang Night Mode',
33+
'nightmode_off' => 'I-Off ang Night Mode',
34+
35+
'account' => 'Account',
36+
'profile' => 'Profile',
37+
'settings' => 'Mga Setting',
38+
'lock' => 'I-lock',
39+
'signout' => 'Mag-sign out',
3740

3841
'help' => 'Tulong',
3942

0 commit comments

Comments
 (0)