From 26e60cd197870067567e08c8462a96ef1852be94 Mon Sep 17 00:00:00 2001 From: mackt <1033530438@qq.com> Date: Tue, 9 Apr 2024 14:00:02 +0800 Subject: [PATCH] fix(ESLint): Process error for build. --- src/app/mylist/page.tsx | 2 +- src/components/AudioPlayer/Player.tsx | 2 +- src/components/AudioPlayer/PlayerBar.tsx | 36 +++++++++++++---------- src/components/Comment/Comment.tsx | 5 ++-- src/components/Comment/CommentInput.tsx | 2 +- src/components/Comment/CommentItem.tsx | 4 +-- src/components/Header/UserCard.tsx | 3 +- src/components/Journal/HotJournalCard.tsx | 2 +- src/components/Song/SongCardList.tsx | 3 +- src/hooks/useUserInfo.js | 17 ----------- src/hooks/useVerify.js | 17 ----------- src/services/client/user.ts | 4 +-- src/services/index.ts | 1 - src/services/server/music.ts | 15 ---------- src/store/user.ts | 14 +++++++-- src/utils/index.ts | 2 -- src/utils/request/client/index.ts | 2 +- src/utils/request/server/request.ts | 1 - src/utils/request/server/utils.ts | 19 ++++++++++-- 19 files changed, 61 insertions(+), 90 deletions(-) delete mode 100644 src/hooks/useUserInfo.js delete mode 100644 src/hooks/useVerify.js delete mode 100644 src/services/server/music.ts diff --git a/src/app/mylist/page.tsx b/src/app/mylist/page.tsx index 62cdbc8..3124219 100644 --- a/src/app/mylist/page.tsx +++ b/src/app/mylist/page.tsx @@ -36,7 +36,7 @@ export default function Journal() { // journal: apiGetSongCollect, // }; const result = await apiGetSongCollect({ userId: userInfo?.id, pageNum, pageSize }); - console.log(result); + // console.log(result); if (result.code === 200) setList(result.data.rows); }; diff --git a/src/components/AudioPlayer/Player.tsx b/src/components/AudioPlayer/Player.tsx index 0950f84..f17a820 100644 --- a/src/components/AudioPlayer/Player.tsx +++ b/src/components/AudioPlayer/Player.tsx @@ -24,7 +24,7 @@ export default function AudioPlayer({ className }: { className?: string }) { }), ); - const audio: SongInfo = playQueue.find((item) => item.id === audioId) || playQueue[0]; + const audio: SongInfo = playQueue.find((item) => item?.id === audioId) || playQueue[0]; const audioRef = useRef(new Audio(audio?.src || '')); const isReady = useRef(false); // 是否加载过组件 diff --git a/src/components/AudioPlayer/PlayerBar.tsx b/src/components/AudioPlayer/PlayerBar.tsx index 1fe5e9f..79700d1 100644 --- a/src/components/AudioPlayer/PlayerBar.tsx +++ b/src/components/AudioPlayer/PlayerBar.tsx @@ -1,5 +1,6 @@ 'use client'; -import { useEffect, useState } from 'react'; +// import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; import dynamic from 'next/dynamic'; @@ -8,19 +9,19 @@ import Player from './Player'; // import { debounce } from 'lodash'; const PlayerBar = ({ className }: { className?: string }) => { - let oldScrollY: number = 0; - function handleScroll() { - if (window.scrollY > oldScrollY) { - // 向下滚动 - // if (oldScrollY < 0) return; - setPositionBottom(-130); - } else { - // 向上滚动 - // if (oldScrollY > 0) return; - setPositionBottom(0); - } - oldScrollY = window.scrollY; - } + // let oldScrollY: number = 0; + // function handleScroll() { + // if (window.scrollY > oldScrollY) { + // // 向下滚动 + // // if (oldScrollY < 0) return; + // setPositionBottom(-130); + // } else { + // // 向上滚动 + // // if (oldScrollY > 0) return; + // setPositionBottom(0); + // } + // oldScrollY = window.scrollY; + // } useEffect(() => { // window.addEventListener('scroll', handleScroll); @@ -29,14 +30,17 @@ const PlayerBar = ({ className }: { className?: string }) => { // }; }); - const [positionBottom, setPositionBottom] = useState(0); + // const [positionBottom, setPositionBottom] = useState(0); return ( //
-
+
diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx index 2743b83..ec36e40 100644 --- a/src/components/Comment/Comment.tsx +++ b/src/components/Comment/Comment.tsx @@ -2,13 +2,12 @@ import { useState, useEffect, useRef, useCallback } from 'react'; -import throttle from 'lodash/throttle'; +// import throttle from 'lodash/throttle'; -import scrollToBottom from '@/utils/scroolToBottom'; +// import { scrollToBottom } from '@/utils/helpers'; import { CommentForm, CommentHeader, CommentList } from '@/components'; import { apiGetComment, apiCommentSave } from '@/services'; -import { size } from 'lodash'; interface Props { journalId: string; diff --git a/src/components/Comment/CommentInput.tsx b/src/components/Comment/CommentInput.tsx index 5b95762..7ad6497 100644 --- a/src/components/Comment/CommentInput.tsx +++ b/src/components/Comment/CommentInput.tsx @@ -3,7 +3,7 @@ /** 评论输入框 */ import { useState, useRef, useMemo, useEffect } from 'react'; -import { Avatar, Button, Input } from '@/components'; +import { Avatar, Button } from '@/components'; interface Props { nickName: string; diff --git a/src/components/Comment/CommentItem.tsx b/src/components/Comment/CommentItem.tsx index 799b46e..3aa727b 100644 --- a/src/components/Comment/CommentItem.tsx +++ b/src/components/Comment/CommentItem.tsx @@ -24,13 +24,13 @@ export default function CommentItem({ className, }: Comment & { className?: string }) { const inputRef = useRef(null); - const [showAll, setShowAll] = useState(false); + // const [showAll, setShowAll] = useState(false); const [showInput, setShowInput] = useState(false); const [subCommentList, setSubCommentList] = useState(topChildrenComment ? [topChildrenComment] : []); // 展示全部评论 const handleShowAll = async () => { - setShowAll(true); + // setShowAll(true); const res = await apiGetSubComment({ parentId: _id, size: commentCount, page: 1 }); if (res.code === 200) setSubCommentList(res.data.rows); return res.code === 200; diff --git a/src/components/Header/UserCard.tsx b/src/components/Header/UserCard.tsx index 61327e4..c7d7ffc 100644 --- a/src/components/Header/UserCard.tsx +++ b/src/components/Header/UserCard.tsx @@ -4,10 +4,9 @@ import Image from 'next/image'; import { useRouter } from 'next/navigation'; import { useShallow } from 'zustand/react/shallow'; -import { Avatar } from '@/components'; - import logout from '@/utils/logout'; +import { Avatar } from '@/components'; import useUserStore from '@/store/user'; interface Props { diff --git a/src/components/Journal/HotJournalCard.tsx b/src/components/Journal/HotJournalCard.tsx index c23107a..ee90450 100644 --- a/src/components/Journal/HotJournalCard.tsx +++ b/src/components/Journal/HotJournalCard.tsx @@ -1,6 +1,6 @@ import Image from 'next/image'; -export default function JournalItem({ title, image, totalCommentReply, journalNo }: JournalInfo) { +export default function JournalItem({ title, image, totalCommentReply }: JournalInfo) { return (
{title}{' '} diff --git a/src/components/Song/SongCardList.tsx b/src/components/Song/SongCardList.tsx index 7c03d42..998c427 100644 --- a/src/components/Song/SongCardList.tsx +++ b/src/components/Song/SongCardList.tsx @@ -15,11 +15,10 @@ interface Props { } export default function JournalItem({ listId, songList, className }: Props) { - const { setPlayList, setAudioId, playListId, audioId } = useAudioStore( + const { setPlayList, setAudioId, playListId } = useAudioStore( useShallow((state) => ({ setplayList: state.setPlayList, setAudioId: state.setAudioId, - audioId: state.audioId, playList: state.playList, setPlayList: state.setPlayList, playListId: state.playListId, diff --git a/src/hooks/useUserInfo.js b/src/hooks/useUserInfo.js deleted file mode 100644 index 76cbf6c..0000000 --- a/src/hooks/useUserInfo.js +++ /dev/null @@ -1,17 +0,0 @@ -import { useGetUserInfoQuery } from '@/store/services'; -import useVerify from './useVerify'; -import { useAppDispatch } from './useRedux'; -import { userLogin } from '@/store'; - -export default function useUserInfo() { - const dispatch = useAppDispatch(); - const isVerify = useVerify(); - - const { data, isLoading, error, isError } = useGetUserInfoQuery(undefined, { - skip: !isVerify, - }); - - if (isError) dispatch(userLogin('')); - - return { userInfo: data?.data, isVerify, isLoading, error, isError }; -} diff --git a/src/hooks/useVerify.js b/src/hooks/useVerify.js deleted file mode 100644 index 3522897..0000000 --- a/src/hooks/useVerify.js +++ /dev/null @@ -1,17 +0,0 @@ -import { useSelector } from 'react-redux'; -import jwt from 'jsonwebtoken'; - -export default function useVerify() { - const { token } = useSelector((state) => state.user); - let status; - - if (!token) return false; - - jwt.verify(token, process.env.NEXT_PUBLIC_ACCESS_TOKEN_SECRET, (err, decoded) => { - if (err) status = false; - if (decoded) status = true; - }); - - if (status) return true; - else return false; -} diff --git a/src/services/client/user.ts b/src/services/client/user.ts index bfce5f3..2b2a98e 100644 --- a/src/services/client/user.ts +++ b/src/services/client/user.ts @@ -1,7 +1,7 @@ -import { setCookie } from 'nookies'; +// import { setCookie } from 'nookies'; import clientHttp from '@/utils/request/client'; -import { request, verifyResponse } from '@/utils'; +// import { request, verifyResponse } from '@/utils'; /** * @description 发送短信验证码 diff --git a/src/services/index.ts b/src/services/index.ts index cb60857..a16e4ec 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -2,7 +2,6 @@ * @description server request */ export * from './server/user'; -export * from './server/music'; export * from './server/journal'; /** diff --git a/src/services/server/music.ts b/src/services/server/music.ts deleted file mode 100644 index 2e1392d..0000000 --- a/src/services/server/music.ts +++ /dev/null @@ -1,15 +0,0 @@ -import serverHttp from '@/utils/request/client'; - -// /** -// * @description 根据期刊号查询期刊信息 -// * @id 期刊号 -// */ -// export const apiGetSongsByJournalNo = async (params: { -// mobile: string; -// deviceId: string; -// countryCode?: string; -// imageCheckCode?: string; -// }) => { -// const result: FetchResponse = await serverHttp.post('/music/song/getByJournalNo', params); -// return result; -// }; diff --git a/src/store/user.ts b/src/store/user.ts index f892db1..0b3fe0f 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -53,7 +53,12 @@ const useUserStore = create()( thumbUpCount: 0, }; - const setUserInfo = (value: UserInfo) => set(produce((state) => (state.userInfo = value))); + const setUserInfo = (value: UserInfo) => + set( + produce((state) => { + state.userInfo = value; + }), + ); const getUserInfo = async () => { const result = await apiGetMyUserInfo(); @@ -64,7 +69,12 @@ const useUserStore = create()( return { userInfo: initialUserInfo, showLogin: false, - setShowLogin: (value) => set(produce((state) => (state.showLogin = value))), + setShowLogin: (value) => + set( + produce((state) => { + state.showLogin = value; + }), + ), setUserInfo, userLogin: async (params) => { const result = await apiUserLogin(params); diff --git a/src/utils/index.ts b/src/utils/index.ts index 63f4e52..f2a6b49 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,2 @@ -export { default as request } from './request'; -export { default as verifyResponse } from './verifyResponse'; export * from './helpers'; export * from './wrapper'; diff --git a/src/utils/request/client/index.ts b/src/utils/request/client/index.ts index 4465443..36470c3 100644 --- a/src/utils/request/client/index.ts +++ b/src/utils/request/client/index.ts @@ -1,7 +1,7 @@ import { getAuthorization, handleResponse, createFormBody } from '@/utils/request/client/utils'; import { IResponse } from '@/utils/request/type'; -export const get = async (url: string, data: any = null, revalidate = 20): Promise> => { +export const get = async (url: string, revalidate = 20): Promise> => { const token = await getAuthorization(); const response = await fetch(url, { headers: { diff --git a/src/utils/request/server/request.ts b/src/utils/request/server/request.ts index f18d0ff..e6eae37 100644 --- a/src/utils/request/server/request.ts +++ b/src/utils/request/server/request.ts @@ -4,7 +4,6 @@ import { cookies } from 'next/headers'; import { NextResponse } from 'next/server'; import { formatBody } from '@/utils/request/server/utils'; -import { IAuthType } from '@/utils/request/type'; const host = process.env.NEXT_PUBLIC_HOST; export const get = async (request: Request) => { diff --git a/src/utils/request/server/utils.ts b/src/utils/request/server/utils.ts index f36a5d9..ac2ea19 100644 --- a/src/utils/request/server/utils.ts +++ b/src/utils/request/server/utils.ts @@ -44,14 +44,27 @@ export const formatBody = async (body: any, contentType: string) => { }; const streamToFormUrlEncoded = async (stream: ReadableStream | null) => { + if (stream === null) { + throw new Error('Stream cannot be null'); + } + const chunks = []; const decoder = new TextDecoder('utf-8'); + const reader = stream.getReader(); // 逐块读取流数据 - for await (const chunk of stream) { - chunks.push(decoder.decode(chunk, { stream: true })); - } + while (true) { + const { done, value } = await reader.read(); + + if (done) { + break; + } + + if (value) { + chunks.push(decoder.decode(value, { stream: true })); + } + } // 合并块并转换为 URL 编码的形式 const formData = chunks.join(''); const urlEncodedFormData = new URLSearchParams(formData);