This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '768-electron-menu-i18n' of https://github.com/LiskHQ/li…
…sk-nano into 768-electron-menu-i18n
- Loading branch information
Showing
13 changed files
with
179 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Dropdown } from 'react-toolbox'; | ||
import { translate } from 'react-i18next'; | ||
import React from 'react'; | ||
|
||
import i18n from '../../i18n'; | ||
import languages from '../../constants/languages'; | ||
|
||
const languagesSource = Object.keys(languages).map(key => ({ | ||
value: key, | ||
label: languages[key].name, | ||
flag: languages[key].flag, | ||
})); | ||
|
||
const handleChange = (value) => { | ||
i18n.changeLanguage(value); | ||
}; | ||
|
||
const customItem = item => ( | ||
<div> | ||
<img src={item.flag}/> {item.label} | ||
</div> | ||
); | ||
|
||
const LanguageDropdown = ({ t }) => ( | ||
<Dropdown | ||
auto={false} | ||
className='language' | ||
label={t('Language')} | ||
source={languagesSource} | ||
value={i18n.language} | ||
template={customItem} | ||
onChange={handleChange} | ||
/> | ||
); | ||
|
||
export default translate()(LanguageDropdown); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import LanguageDropdown from './index'; | ||
import i18n from '../../i18n'; | ||
|
||
// import * as accountApi from '../../utils/api/account'; | ||
|
||
|
||
describe('LanguageDropdown', () => { | ||
let wrapper; | ||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
}; | ||
wrapper = mount(<LanguageDropdown {...props} />, { | ||
context: { i18n }, | ||
childContextTypes: { | ||
i18n: PropTypes.object.isRequired, | ||
}, | ||
}); | ||
}); | ||
|
||
it('renders a Dropdown component', () => { | ||
expect(wrapper.find('Dropdown')).to.have.length(1); | ||
}); | ||
|
||
it('calls i18n.changeLanguage on chaning the value in the dropdown', () => { | ||
const i18nSpy = sinon.spy(i18n, 'changeLanguage'); | ||
|
||
wrapper.find('Dropdown').simulate('click'); | ||
wrapper.find('Dropdown ul li').at(0).simulate('click'); | ||
expect(i18nSpy).to.have.been.calledWith('en'); | ||
|
||
i18nSpy.restore(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,10 @@ | ||
import { Dropdown } from 'react-toolbox'; | ||
import { translate } from 'react-i18next'; | ||
import React from 'react'; | ||
import LanguageDropdown from '../languageDropdown'; | ||
|
||
import i18n from '../../i18n'; | ||
import languages from '../../constants/languages'; | ||
|
||
const languagesSource = Object.keys(languages).map(key => ({ | ||
value: key, | ||
label: languages[key].name, | ||
flag: languages[key].flag, | ||
})); | ||
|
||
const handleChange = (value) => { | ||
i18n.changeLanguage(value); | ||
}; | ||
|
||
const customItem = item => ( | ||
<div> | ||
<img src={item.flag}/> {item.label} | ||
</div> | ||
); | ||
|
||
const Settings = ({ t }) => ( | ||
const Settings = () => ( | ||
<form> | ||
<Dropdown | ||
auto={false} | ||
className='language' | ||
label={t('Language')} | ||
source={languagesSource} | ||
value={i18n.language} | ||
template={customItem} | ||
onChange={handleChange} | ||
/> | ||
<LanguageDropdown /> | ||
</form> | ||
); | ||
|
||
export default translate()(Settings); | ||
export default Settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import history from '../history'; | ||
import routesReg from './routes'; | ||
import { errorToastDisplayed } from '../actions/toaster'; | ||
import store from '../store'; | ||
|
||
export default { | ||
init: () => { | ||
const { ipc } = window; | ||
|
||
if (ipc) { | ||
ipc.on('openUrl', (action, url) => { | ||
const normalizedUrl = url.toLowerCase().replace('lisk://', '/'); | ||
const route = routesReg.find(item => item.regex.test(normalizedUrl)); | ||
if (route !== undefined) { | ||
history.push(normalizedUrl); | ||
} else { | ||
store.dispatch(errorToastDisplayed({ label: 'The URL was invalid' })); | ||
} | ||
}); | ||
} | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import externalLinks from './externalLinks'; | ||
|
||
describe('externalLinks', () => { | ||
const ipc = { | ||
on: spy(), | ||
}; | ||
|
||
describe('init', () => { | ||
it('should be a function', () => { | ||
expect(typeof externalLinks.init).to.be.equal('function'); | ||
}); | ||
|
||
it('calling init when ipc is not on window should do nothing', () => { | ||
externalLinks.init(); | ||
expect(ipc.on).to.not.have.been.calledWith(); | ||
}); | ||
|
||
it('calling init when ipc is available on window should bind listeners', () => { | ||
window.ipc = ipc; | ||
externalLinks.init(); | ||
expect(ipc.on).to.have.been.calledWith(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export default [ | ||
{ | ||
regex: /\/main\/transactions(?:\/[^/]*)?$/, | ||
path: '/main/transactions/', | ||
params: 'dialog', | ||
name: 'transactions', | ||
}, { | ||
regex: /\/main\/voting(?:\/[^/]*)?$/, | ||
path: '/main/voting/', | ||
params: 'dialog', | ||
name: 'voting', | ||
}, { | ||
regex: /\/main\/forging(?:\/[^/]*)?$/, | ||
path: '/main/forging/', | ||
params: 'dialog', | ||
name: 'forging', | ||
}, { | ||
regex: /register(\/)?$/, | ||
path: '/', | ||
params: 'dialog', | ||
name: 'login', | ||
}, { | ||
regex: /^\/$/, | ||
path: '/', | ||
params: 'dialog', | ||
name: 'login', | ||
}, | ||
]; |