diff --git a/src/actions/accounts.js b/src/actions/accounts.js index 3f8f36d6..23dc8535 100644 --- a/src/actions/accounts.js +++ b/src/actions/accounts.js @@ -1,9 +1,27 @@ // @flow import db from 'helpers/db' +import sortBy from 'lodash/sortBy' +import type { Dispatch } from 'redux' import type { Account } from 'types/common' +function sortAccounts(accounts, orderAccounts) { + const accountsSorted = sortBy(accounts, a => { + if (orderAccounts === 'balance') { + return a.data.balance + } + + return a[orderAccounts] + }) + + if (orderAccounts === 'balance') { + accountsSorted.reverse() + } + + return accountsSorted +} + export type AddAccount = Account => { type: string, payload: Account } export const addAccount: AddAccount = payload => ({ type: 'DB:ADD_ACCOUNT', @@ -16,11 +34,24 @@ export const updateAccount: AddAccount = payload => ({ payload, }) -type FetchAccounts = () => { type: string } -export const fetchAccounts: FetchAccounts = () => { - const payload = db.get('accounts') - return { +export type FetchAccounts = () => (Dispatch<*>, Function) => void +export const fetchAccounts: FetchAccounts = () => (dispatch, getState) => { + const { settings: { orderAccounts } } = getState() + const accounts = db.get('accounts') + dispatch({ type: 'SET_ACCOUNTS', - payload, - } + payload: sortAccounts(accounts, orderAccounts), + }) +} + +export type UpdateOrderAccounts = string => (Dispatch<*>, Function) => void +export const updateOrderAccounts: UpdateOrderAccounts = (orderAccounts: string) => ( + dispatch, + getState, +) => { + const { accounts } = getState() + dispatch({ + type: 'DB:SET_ACCOUNTS', + payload: sortAccounts(accounts, orderAccounts), + }) } diff --git a/src/actions/settings.js b/src/actions/settings.js index 1b942e93..6c5b2652 100644 --- a/src/actions/settings.js +++ b/src/actions/settings.js @@ -2,6 +2,7 @@ import db from 'helpers/db' +import type { Dispatch } from 'redux' import type { Settings } from 'types/common' export type SaveSettings = Settings => { type: string, payload: Settings } @@ -10,7 +11,8 @@ export const saveSettings: SaveSettings = payload => ({ payload, }) -export const fetchSettings: Function = () => dispatch => { +type FetchSettings = () => (Dispatch<*>) => void +export const fetchSettings: FetchSettings = () => dispatch => { const settings = db.get('settings') if (Object.keys(settings).length === 0) { return diff --git a/src/components/DevToolbar.js b/src/components/DevToolbar.js index 88125481..6c44cfdc 100644 --- a/src/components/DevToolbar.js +++ b/src/components/DevToolbar.js @@ -195,30 +195,32 @@ class DevToolbar extends PureComponent { - {Object.keys(cpuUsage).map(k => ( - - - {k} - {last(cpuUsage[k]).value}% + {Object.keys(cpuUsage) + .sort() + .map(k => ( + + + {k} + {last(cpuUsage[k]).value}% + + + + + + - - - - - - - ))} + ))} diff --git a/src/components/SettingsPage/Display.js b/src/components/SettingsPage/Display.js index cd116bca..775ef879 100644 --- a/src/components/SettingsPage/Display.js +++ b/src/components/SettingsPage/Display.js @@ -14,7 +14,6 @@ type InputValue = SettingsDisplay type Props = { t: T, - i18n: Object, settings: SettingsDisplay, onSaveSettings: Function, } @@ -26,22 +25,43 @@ class TabProfile extends PureComponent { state = { inputValue: { language: this.props.settings.language, + orderAccounts: this.props.settings.orderAccounts, }, } - getLanguages() { + getDatas() { const { t } = this.props - return [ - { - key: 'en', - name: t('language.en'), - }, - { - key: 'fr', - name: t('language.fr'), - }, - ] + return { + languages: [ + { + key: 'en', + name: t('language.en'), + }, + { + key: 'fr', + name: t('language.fr'), + }, + ], + orderAccounts: [ + { + key: 'custom', + name: t('orderAccounts.custom'), + }, + { + key: 'name', + name: t('orderAccounts.name'), + }, + { + key: 'balance', + name: t('orderAccounts.balance'), + }, + { + key: 'type', + name: t('orderAccounts.type'), + }, + ], + } } handleChangeInput = (key: $Keys) => (value: $Values) => @@ -55,24 +75,22 @@ class TabProfile extends PureComponent { handleSubmit = (e: SyntheticEvent) => { e.preventDefault() - const { onSaveSettings, i18n } = this.props + const { onSaveSettings } = this.props const { inputValue } = this.state - const settings = { - language: inputValue.language, - } - - i18n.changeLanguage(settings.language) - - onSaveSettings(settings) + onSaveSettings({ + ...inputValue, + }) } render() { const { t } = this.props const { inputValue } = this.state - const languages = this.getLanguages() + const { languages, orderAccounts } = this.getDatas() + const currentLanguage = languages.find(l => l.key === inputValue.language) + const currentOrderAccounts = orderAccounts.find(l => l.key === inputValue.orderAccounts) return (
@@ -86,6 +104,15 @@ class TabProfile extends PureComponent { items={languages} /> + + +