diff --git a/src/App.js b/src/App.js
index 0ea7514..fc1b609 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,3 +1,4 @@
+import { useEffect } from 'react';
import { Routes, Route, Navigate, useNavigate } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { setAccessToken, setUserInfo, setSelectInfo } from "./business/userSlice.js"
@@ -11,21 +12,24 @@ function App() {
const navigate = useNavigate();
const [cookies, setCookie, removeCookie] = useCookies(['accessToken']);
- if (cookies.accessToken) {
- dispatch(setAccessToken(cookies.accessToken));
- yzs.get_user_info(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => {
- dispatch(setUserInfo(info));
- yzs.user_select(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => {
- dispatch(setSelectInfo(info));
+ useEffect(() => {
+ if (cookies.accessToken) {
+ dispatch(setAccessToken(cookies.accessToken));
+ yzs.get_user_info(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => {
+ dispatch(setUserInfo(info));
+ yzs.user_select(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => {
+ dispatch(setSelectInfo(info));
+ });
+ }).catch(error => {
+ console.log(error)
+ if (error.returnCode === "uc_0106") {
+ removeCookie("accessToken");
+ navigate("/login");
+ }
});
- }).catch(error => {
- console.log(error)
- if (error.returnCode === "uc_0106") {
- removeCookie("accessToken");
- navigate("/login");
- }
- });
- }
+ }
+ }, []);
+
return (
diff --git a/src/MainPage.js b/src/MainPage.js
index 13a318d..52cbcca 100644
--- a/src/MainPage.js
+++ b/src/MainPage.js
@@ -108,7 +108,7 @@ export default function () {
}).catch(error => {
console.log("get list failed", error);
});
- }, [accessToken, passportId]);
+ }, [passportId]);
const onClick = () => {
setOpen(!open);
diff --git a/src/PlayerBar.js b/src/PlayerBar.js
index fe826e0..c06a1fd 100644
--- a/src/PlayerBar.js
+++ b/src/PlayerBar.js
@@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "react";
import pauseIcon from "./assets/play.png";
import playIcon from "./assets/pause.png";
import downloadIcon from "./assets/download.png";
-import { setCurrentTime, togglePauseState, setCurrentWaveData } from "./business/recorderSlice.js"
+import { setCurrentTime, setPauseState, togglePauseState, setCurrentWaveData } from "./business/recorderSlice.js"
import { audioWaveData } from "./business/utilities"
import ProgressBar from "./components/ProgressBar";
@@ -32,6 +32,7 @@ export default function ({ width, currentTime }) {
}, [currentBlob]);
useEffect(() => {
+ if (currentBlob.length <= 0) return;
audioWaveData(currentBlob, (duration > 20 * 60) ? 200 : 100)
.then(data => dispatch(setCurrentWaveData(data)));
}, [duration]);
@@ -68,6 +69,10 @@ export default function ({ width, currentTime }) {
player.current.playbackRate = event.target.value;
};
+ const onEnded = (event) => {
+ dispatch(setPauseState(true));
+ };
+
return
-
+
{
state.pause = !state.pause;
},
+ setPauseState: (state, action) => {
+ state.pause = action.payload;
+ }
}
})
// Action creators are generated for each case reducer function
-export const { setCurrentIndex, setList, setCurrentLyric, setCurrentBlob, togglePauseState, setCurrentTime, setCurrentWaveData } = recorderSlice.actions
+export const { setCurrentIndex, setList, setCurrentLyric, setCurrentBlob, togglePauseState, setPauseState, setCurrentTime, setCurrentWaveData } = recorderSlice.actions
export default recorderSlice.reducer
\ No newline at end of file