diff --git a/app/renderer/components/main/importBrowserDataPanel.js b/app/renderer/components/main/importBrowserDataPanel.js index 3d023588113..e35458daa4a 100644 --- a/app/renderer/components/main/importBrowserDataPanel.js +++ b/app/renderer/components/main/importBrowserDataPanel.js @@ -4,9 +4,10 @@ const React = require('react') const {StyleSheet, css} = require('aphrodite/no-important') +const Immutable = require('immutable') // Components -const ImmutableComponent = require('../immutableComponent') +const ReduxComponent = require('../reduxComponent') const Dialog = require('../common/dialog') const Button = require('../common/button') const SwitchControl = require('../common/switchControl') @@ -20,106 +21,85 @@ const { } = require('../common/commonForm') // Actions -const windowActions = require('../../../../js/actions/windowActions') const appActions = require('../../../../js/actions/appActions') +const windowActions = require('../../../../js/actions/windowActions') // Styles const globalStyles = require('../styles/global') -class ImportBrowserDataPanel extends ImmutableComponent { - constructor () { - super() +class ImportBrowserDataPanel extends React.Component { + constructor (props) { + super(props) this.onToggleHistory = this.onToggleSetting.bind(this, 'history') this.onToggleFavorites = this.onToggleSetting.bind(this, 'favorites') this.onToggleCookies = this.onToggleSetting.bind(this, 'cookies') this.onImport = this.onImport.bind(this) this.onChange = this.onChange.bind(this) } + onToggleSetting (setting, e) { - windowActions.setImportBrowserDataSelected(this.props.importBrowserDataSelected.set(setting, e.target.value)) - } - get browserData () { - let index = this.props.importBrowserDataSelected.get('index') - if (index === undefined) { - index = '0' - } - return this.props.importBrowserDataDetail.get(index) - } - get supportHistory () { - let browserData = this.browserData - if (browserData === undefined) { - return false - } - return browserData.get('history') - } - get supportFavorites () { - let browserData = this.browserData - if (browserData === undefined) { - return false - } - return browserData.get('favorites') - } - get supportCookies () { - let browserData = this.browserData - if (browserData === undefined) { - return false - } - return browserData.get('cookies') + windowActions.setImportBrowserDataSelected({ + [setting]: e.target.value + }) } + onImport () { - let index = this.props.importBrowserDataSelected.get('index') - if (index === undefined) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', '0') - } - let browserData = this.browserData - if (browserData !== undefined) { - let type = browserData.get('type') - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('type', type) + let data = {} + data.index = this.props.selectedIndex.toString() + data.cookies = this.props.cookies + data.favorites = this.props.favorites + data.history = this.props.history + + if (this.props.type != null) { + data.type = this.props.type } - appActions.importBrowserData(this.props.importBrowserDataSelected) - this.props.onHide() + + appActions.importBrowserData(Immutable.fromJS(data)) + this.onHide() } + onChange (e) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', e.target.value) - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('history', false) - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('favorites', false) - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('cookies', false) - let importBrowserDataSelected = this.props.importBrowserDataSelected - if (this.supportHistory) { - importBrowserDataSelected = importBrowserDataSelected.set('history', true) - } - if (this.supportFavorites) { - importBrowserDataSelected = importBrowserDataSelected.set('favorites', true) - } - if (this.supportCookies) { - importBrowserDataSelected = importBrowserDataSelected.set('cookies', true) - } - windowActions.setImportBrowserDataSelected(importBrowserDataSelected) + windowActions.setImportBrowserDataSelected(~~e.target.value) + } + + onHide () { + windowActions.setImportBrowserDataDetail() } - get selectedBrowser () { - let index = this.props.importBrowserDataSelected.get('index') - if (index === undefined) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', '0') - if (this.supportHistory) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('history', true) - } - if (this.supportFavorites) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('favorites', true) - } - if (this.supportCookies) { - this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('cookies', true) - } + + componentWillMount () { + if (this.props.selectedIndex == null) { + windowActions.setImportBrowserDataSelected(0) } - return index !== undefined ? index : '0' } + + mergeProps (state, ownProps) { + const currentWindow = state.get('currentWindow') + const importBrowserDataSelected = currentWindow.get('importBrowserDataSelected', Immutable.Map()) + const importBrowserDataDetail = currentWindow.get('importBrowserDataDetail', Immutable.Map()) + const index = importBrowserDataSelected.get('index', '0') + const currentBrowser = importBrowserDataDetail.get(index, Immutable.Map()) + + const props = {} + // used in renderer + props.browserNames = importBrowserDataDetail.map((browser) => browser.get('name')) + props.browserIndexes = importBrowserDataDetail.map((browser) => browser.get('index')) + props.isSupportingHistory = currentBrowser.get('history', false) + props.isSupportingFavourites = currentBrowser.get('favorites', false) + props.isSupportingCookies = currentBrowser.get('cookies', false) + props.currentIndex = index + props.cookies = importBrowserDataSelected.get('cookies') + props.favorites = importBrowserDataSelected.get('favorites') + props.history = importBrowserDataSelected.get('history') + props.type = importBrowserDataSelected.get('type') + + // used in other functions + props.selectedIndex = importBrowserDataSelected.get('index') + + return props + } + render () { - var browsers = [] - if (this.props.importBrowserDataDetail !== undefined) { - this.props.importBrowserDataDetail.toJS().forEach((browser) => { - browsers.push() - }) - } - return + return e.stopPropagation()}>
- {browsers} + { + this.props.browserNames.map((name, i) => { + return + }) + }
-