Skip to content

Commit

Permalink
+: clear button functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lynklody authored and billchenchina committed Aug 13, 2020
1 parent 8e9823f commit 6d4a0ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Components/ButtonUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react'
import { Container, Grid, Button } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import { grey } from '@material-ui/core/colors'
import { useSelector } from 'react-redux'
import { useDispatch, useSelector } from 'react-redux'
import { startStringGen, startVectorGen } from '../Store/Actions'
import { ALTER_ALL } from '../Store/Actions/ActionTypes'

const useStyles = makeStyles({
button: {
Expand All @@ -17,13 +18,15 @@ const useStyles = makeStyles({

const ButtonUtil = () => {
const classes = useStyles()
const dispatch = useDispatch()
const dataType = useSelector(state => state.dataType)
const allState = useSelector(state => state)

const StartGenerator = () => {
console.log('---------------GEN START')
switch (dataType) {
case 'String':
startStringGen(allState)
startStringGen(allState, dispatch)
break
case 'Vector':
startVectorGen(allState)
Expand All @@ -48,7 +51,9 @@ const ButtonUtil = () => {
</Button>
</Grid>
<Grid item xs={3} sm={3}>
<Button className={classes.button}>
<Button className={classes.button}
onClick={() => dispatch({ type: ALTER_ALL })}
>
全部清除
</Button>
</Grid>
Expand Down
17 changes: 15 additions & 2 deletions src/Store/Reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// })

import { OPEN_DRAWER, CLOSE_DRAWER, UPDATE_CHARSET, UPDATE_DELIMITER, UPDATE_NUM_CHARS,
SET_DATATYPE, UPDATE_NUM_CASES, SET_OUTPUT, UPDATE_ALLOW_DUPLICATE } from '../Actions/ActionTypes'
SET_DATATYPE, UPDATE_NUM_CASES, SET_OUTPUT, UPDATE_ALLOW_DUPLICATE, ALTER_ALL } from '../Actions/ActionTypes'

const initState = {
open: false,
dataType: '',
dataType: 'String',
chars: 'abcdefghijklmnopqrstuvwxyz',
numChars: 0,
delimiter: '',
Expand Down Expand Up @@ -68,6 +68,19 @@ const reducer = (state=initState, action) => {
...state,
allowDuplicate: action.payload
}
case ALTER_ALL:
console.log('in ALTER_ALL')
return {
...state,
open: false,
dataType: '',
chars: 'abcdefghijklmnopqrstuvwxyz',
numChars: 0,
delimiter: '',
numCases: 0,
allowDuplicate: true,
output: ''
}
default:
return state
}
Expand Down

0 comments on commit 6d4a0ff

Please sign in to comment.