-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dark mode #459
dark mode #459
Changes from 2 commits
baf831a
b94fb27
b62cfb5
da2242f
d8d0f67
c1d509c
aa63d5f
aa90484
291d8a0
57dd486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"body-parser": "^1.18.2", | ||
"bunyan": "^1.8.12", | ||
"css-box-shadow": "^1.0.0-3", | ||
"darkreader": "^4.7.15", | ||
"date-fns": "^1.29.0", | ||
"draft-js": "^0.10.4", | ||
"draft-js-plugins-editor": "^2.1.1", | ||
|
@@ -105,6 +106,7 @@ | |
"node-mocks-http": "^1.7.6", | ||
"node-sass": "^4.7.2", | ||
"object-assign": "4.1.1", | ||
"object.entries": "^1.1.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
"pa11y-ci": "^1.3.1", | ||
"postcss-flexbugs-fixes": "4.1.0", | ||
"postcss-loader": "3.0.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { Component } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test(s) |
||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { setDarkModePreference } from '../../actions/preferences'; | ||
import { EMPTY_FUNCTION } from '../../Constants/PropTypes'; | ||
|
||
class DarkModeToggle extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.onClickUnset = this.onClickUnset.bind(this); | ||
this.onClickSet = this.onClickSet.bind(this); | ||
} | ||
|
||
onClickUnset() { | ||
this.props.set(false); | ||
} | ||
|
||
onClickSet() { | ||
this.props.set(true); | ||
} | ||
|
||
render() { | ||
const { isDarkMode, set, ...rest } = this.props; | ||
return ( | ||
isDarkMode ? | ||
<button className="unstyled-button" onClick={this.onClickUnset} {...rest}>Disable Dark Mode</button> | ||
: | ||
<button className="unstyled-button" onClick={this.onClickSet} {...rest}>Enable Dark Mode</button> | ||
); | ||
} | ||
} | ||
|
||
DarkModeToggle.propTypes = { | ||
isDarkMode: PropTypes.bool, | ||
set: PropTypes.func, | ||
}; | ||
|
||
DarkModeToggle.defaultProps = { | ||
isDarkMode: false, | ||
set: EMPTY_FUNCTION, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isDarkMode: state.darkModePreference, | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
set: bool => dispatch(setDarkModePreference(bool)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DarkModeToggle); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { Component } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test(s) |
||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
enable as enableDarkMode, | ||
disable as disableDarkMode, | ||
} from 'darkreader'; | ||
|
||
const setMode = (value) => { | ||
if (!value) { | ||
disableDarkMode(); | ||
} else { | ||
enableDarkMode({ | ||
brightness: 100, | ||
contrast: 90, | ||
sepia: 10, | ||
}); | ||
} | ||
}; | ||
|
||
class DarkMode extends Component { | ||
|
||
componentWillMount() { | ||
const { isDarkMode } = this.props; | ||
setMode(isDarkMode); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { isDarkMode } = nextProps; | ||
setMode(isDarkMode); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div /> | ||
); | ||
} | ||
} | ||
|
||
DarkMode.propTypes = { | ||
isDarkMode: PropTypes.bool, | ||
}; | ||
|
||
DarkMode.defaultProps = { | ||
isDarkMode: false, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isDarkMode: state.darkModePreference, | ||
}); | ||
|
||
export default connect(mapStateToProps)(DarkMode); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './DarkMode'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import preferences, { darkModePreference } from './preferences'; | ||
|
||
export default { preferences, darkModePreference }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import sortPreferences from './sortPreferences'; | ||
import preferences from './preferences'; | ||
import { POSITION_SEARCH_SORTS_TYPE } from '../../Constants/Sort'; | ||
|
||
describe('reducers', () => { | ||
it('can set reducer SET_SORT_PREFERENCE', () => { | ||
expect(sortPreferences({}, { type: 'SET_SORT_PREFERENCE', key: POSITION_SEARCH_SORTS_TYPE, value: 'title' })) | ||
expect(preferences({}, { type: 'SET_SORT_PREFERENCE', key: POSITION_SEARCH_SORTS_TYPE, value: 'title' })) | ||
.toBeDefined(); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import IndexSagas from './index-sagas'; | |
const persistConfig = { | ||
key: 'root', | ||
storage, | ||
whitelist: ['sortPreferences'], // only persist sortPreferences reducer | ||
whitelist: ['preferences', 'darkModePreference'], // only persist sortPreferences reducer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update comment |
||
}; | ||
|
||
// Setup the middleware to watch between the Reducers and the Actions | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍