|
|
@@ -1,4 +1,4 @@
|
|
|
-import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
|
+import { PayloadAction, createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
|
export enum ResultType {
|
|
|
@@ -21,8 +21,8 @@ const initialState: ResultState = {
|
|
|
seconds: 0
|
|
|
}
|
|
|
|
|
|
-const resultTime = 2;
|
|
|
-const countdownTime = 20;
|
|
|
+const resultTime = 1;
|
|
|
+const countdownTime = 5;
|
|
|
|
|
|
const resultSlice = createSlice({
|
|
|
name: 'result',
|
|
|
@@ -32,49 +32,14 @@ const resultSlice = createSlice({
|
|
|
state.type = ResultType.ing;
|
|
|
},
|
|
|
checkSuccess(state) {
|
|
|
- debugger
|
|
|
- console.log('9527')
|
|
|
- // state.type = ResultType.success;
|
|
|
- // var count = resultTime;
|
|
|
- // var timer = setInterval(()=>{
|
|
|
- // count--;
|
|
|
- // if (count <= 0) {
|
|
|
- // clearInterval(timer);
|
|
|
- // state.type = ResultType.countdown;
|
|
|
- // var count2 = countdownTime;
|
|
|
- // var timer2 = setInterval(()=>{
|
|
|
- // count2--;
|
|
|
- // if (count2 <= 0) {
|
|
|
- // clearInterval(timer2);
|
|
|
- // state.type = ResultType.idle;
|
|
|
- // }
|
|
|
- // },1000)
|
|
|
- // }
|
|
|
- // },1000)
|
|
|
+ state.type = ResultType.success;
|
|
|
},
|
|
|
checkFail(state) {
|
|
|
state.type = ResultType.fail;
|
|
|
- var count = resultTime;
|
|
|
- var timer = setInterval(()=>{
|
|
|
- count--;
|
|
|
- if (count <= 0) {
|
|
|
- clearInterval(timer);
|
|
|
- state.type = ResultType.idle;
|
|
|
- }
|
|
|
- },1000)
|
|
|
},
|
|
|
- checkCountdown(state) {
|
|
|
- debugger
|
|
|
+ checkCountdown(state,action: PayloadAction<any>) {
|
|
|
+ state.title = action.payload;
|
|
|
state.type = ResultType.countdown;
|
|
|
- var count = 20;
|
|
|
- var timer = setInterval(()=>{
|
|
|
- count--;
|
|
|
- if (count <= 0) {
|
|
|
- clearInterval(timer);
|
|
|
- state.type = ResultType.idle;
|
|
|
- }
|
|
|
- },1000)
|
|
|
- // state.seconds = action.payload;
|
|
|
},
|
|
|
checkCountdownEnd(state) {
|
|
|
state.type = ResultType.idle;
|
|
|
@@ -92,16 +57,31 @@ export const { checkStart, checkSuccess, checkFail, checkCountdownEnd, checkCoun
|
|
|
export default resultSlice.reducer;
|
|
|
|
|
|
export const setResult = createAsyncThunk('result/action', async (payload: {isSuccess:boolean}, { dispatch }) => {
|
|
|
- debugger
|
|
|
if (payload.isSuccess) {
|
|
|
- console.log('aaaa')
|
|
|
dispatch(checkSuccess());
|
|
|
- console.log('successdddd')
|
|
|
setTimeout(() => {
|
|
|
- dispatch(checkCountdown());
|
|
|
- console.log('zzzzz')
|
|
|
- debugger
|
|
|
- }, 2000);
|
|
|
+ var count = countdownTime;
|
|
|
+ dispatch(checkCountdown(count));
|
|
|
+
|
|
|
+ var timer = setInterval(()=>{
|
|
|
+ count--;
|
|
|
+ dispatch(checkCountdown(count));
|
|
|
+ if (count<0){
|
|
|
+ clearInterval(timer);
|
|
|
+ dispatch(resetStatus())
|
|
|
+ }
|
|
|
+ },1000)
|
|
|
+ }, resultTime*1000);
|
|
|
+
|
|
|
+ // setTimeout(()=>{
|
|
|
+ // dispatch(resetStatus())
|
|
|
+ // },countdownTime*1000)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dispatch(checkFail());
|
|
|
+ setTimeout(()=>{
|
|
|
+ dispatch(resetStatus());
|
|
|
+ },resultTime*1000)
|
|
|
}
|
|
|
|
|
|
});
|