Reconstruct code

This commit is contained in:
CPunisher 2020-05-09 14:47:08 +08:00
parent 0034589837
commit fdc1578306
5 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import React from 'react'
import React from "react";
import PropTypes from 'prop-types'
function calClassName(selected) {
@ -6,9 +6,9 @@ function calClassName(selected) {
return 'Qr-item';
}
const Style = ({ value, renderer, selected, onClick }) => (
const Style = ({ value, renderer, selected, onSelected }) => (
<div className={calClassName(selected)}
onClick={onClick}>
onMouseDown={onSelected}>
<div className="Qr-item-image">
<div className="Qr-item-image-inner">
{renderer}
@ -24,7 +24,7 @@ Style.propTypes = {
value: PropTypes.string.isRequired,
renderer: PropTypes.object.isRequired,
selected: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired
onSelected: PropTypes.func.isRequired
}
export default Style;

View File

@ -8,7 +8,7 @@ const StyleList = ({ styles, onSelected }) => (
<Style
key={style.value}
{...style}
onClick={() => onSelected(index)}
onSelected={() => onSelected(index)}
/>
)}
</div>

View File

@ -1,4 +1,5 @@
import {connect} from 'react-redux';
import * as React from "react";
const mapStateToProps = (state, ownProps) => ({
qrcode: state.qrcode,

View File

@ -36,13 +36,18 @@ const mapStateToProps = state => ({
return {
value: style.value,
selected: state.selectedIndex == index,
renderer: React.createElement(Renderer(style.renderer), {index: index, setParamInfo: setParamInfo})
renderer: React.createElement(Renderer(style.renderer), {
index: index,
setParamInfo: setParamInfo
})
}
})
})
const mapDispatchToProps = dispatch => ({
onSelected: index => dispatch(changeStyle(index))
onSelected: index => {
dispatch(changeStyle(index))
}
})
const StyleListViewer = () => {

View File

@ -9,7 +9,6 @@ const initialState = {
}
export default function appReducer(state = initialState, action) {
console.log(state)
switch (action.type) {
case actionTypes.GENERATE_QR_INFO: {
return Object.assign({}, state, {