diff --git a/package.json b/package.json index 4594027..8f9850f 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "@types/node": "^14.0.1", "@types/react": "^16.9.35", "@types/react-dom": "^16.9.8", + "@types/streamsaver": "^2.0.1", "@typescript-eslint/eslint-plugin": "^2.33.0", "@typescript-eslint/parser": "^2.33.0", - "@types/streamsaver": "^2.0.1", "axios": "^0.21.1", "babel-eslint": "10.0.3", "babel-jest": "^24.9.0", @@ -93,6 +93,7 @@ "sass-loader": "7.2.0", "semver": "6.3.0", "streamsaver": "^2.0.6", + "artplayer": "^4.3.4", "style-loader": "1.0.0", "terser-webpack-plugin": "1.4.1", "timeago-react": "^3.0.0", diff --git a/src/component/Viewer/Code.js b/src/component/Viewer/Code.js index 7d15a7f..7ec9494 100644 --- a/src/component/Viewer/Code.js +++ b/src/component/Viewer/Code.js @@ -4,7 +4,6 @@ import { makeStyles } from "@material-ui/core/styles"; import { useLocation, useParams, useRouteMatch } from "react-router"; import API from "../../middleware/Api"; import { useDispatch } from "react-redux"; -import { changeSubTitle } from "../../redux/viewUpdate/action"; import pathHelper from "../../utils/page"; import SaveButton from "../Dial/Save"; import { codePreviewSuffix } from "../../config"; @@ -16,6 +15,8 @@ import Switch from "@material-ui/core/Switch"; import MenuItem from "@material-ui/core/MenuItem"; import Divider from "@material-ui/core/Divider"; import { toggleSnackbar } from "../../redux/explorer"; +import UseFileSubTitle from "../../hooks/fileSubtitle"; + const MonacoEditor = React.lazy(() => import(/* webpackChunkName: "codeEditor" */ "react-monaco-editor") ); @@ -65,12 +66,9 @@ export default function CodeViewer() { const query = useQuery(); const { id } = useParams(); const theme = useTheme(); + UseFileSubTitle(query, math, location); const dispatch = useDispatch(); - const SetSubTitle = useCallback( - (title) => dispatch(changeSubTitle(title)), - [dispatch] - ); const ToggleSnackbar = useCallback( (vertical, horizontal, msg, color) => dispatch(toggleSnackbar(vertical, horizontal, msg, color)), @@ -78,18 +76,10 @@ export default function CodeViewer() { ); useEffect(() => { - if (!pathHelper.isSharePage(location.pathname)) { - const path = query.get("p").split("/"); - const extension = query.get("p").split("."); - setSuffix(codePreviewSuffix[extension.pop()]); - SetSubTitle(path[path.length - 1]); - } else { - const extension = query.get("name").split("."); - setSuffix(codePreviewSuffix[extension.pop()]); - SetSubTitle(query.get("name")); - } + const extension = query.get("p").split("."); + setSuffix(codePreviewSuffix[extension.pop()]); // eslint-disable-next-line - }, [math.params[0], location]); + }, []); useEffect(() => { let requestURL = "/file/content/" + query.get("id"); @@ -142,11 +132,18 @@ export default function CodeViewer() {
- setWordWrap(e.target.checked ? "on" : "off")} - /> - } label="自动换行" /> + + setWordWrap( + e.target.checked ? "on" : "off" + ) + } + /> + } + label="自动换行" + />