-
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 all 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", | ||
|
@@ -104,6 +105,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, | ||
}); | ||
|
||
export 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,51 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { testDispatchFunctions } from '../../testUtilities/testUtilities'; | ||
import DarkModeToggle, { mapDispatchToProps } from './DarkModeToggle'; | ||
|
||
describe('DarkModeToggle', () => { | ||
const props = { | ||
isDarkMode: false, | ||
set: () => {}, | ||
}; | ||
|
||
it('is defined', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
|
||
it('it displays "Disable" when isDarkMode === true', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} isDarkMode />, | ||
); | ||
expect(wrapper.find('button').text()).toBe('Disable Dark Mode'); | ||
}); | ||
|
||
it('it displays "Enable" when isDarkMode !== true', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper.find('button').text()).toBe('Enable Dark Mode'); | ||
}); | ||
|
||
it('calls the set function', () => { | ||
let val = true; | ||
const onClick = v => val = v; // eslint-disable-line | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} isDarkMode set={onClick} />, | ||
); | ||
const click = () => wrapper.find('button').simulate('click'); | ||
click(); | ||
expect(val).toBe(false); | ||
wrapper.setProps({ isDarkMode: false }); | ||
wrapper.update(); | ||
click(); | ||
expect(val).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('mapDispatchToProps', () => { | ||
testDispatchFunctions(mapDispatchToProps, { bool: [true] }); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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'; | ||
import { checkFlag } from '../../flags'; | ||
|
||
const getUseDarkMode = () => checkFlag('flags.personalization'); | ||
|
||
const setMode = (value) => { | ||
if (!value || !getUseDarkMode()) { | ||
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,16 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import DarkMode from './DarkMode'; | ||
|
||
describe('DarkMode', () => { | ||
const props = { | ||
isDarkMode: true, | ||
}; | ||
|
||
it('is defined', () => { | ||
const wrapper = shallow( | ||
<DarkMode.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
}); |
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.
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.
👍