From dcb905c1bffd68f4f53f9a98e64976ff6dd4ff58 Mon Sep 17 00:00:00 2001 From: bs32g1038 Date: Sun, 24 Mar 2024 20:23:10 +0800 Subject: [PATCH] fix: some bugs --- web/components/LoginModal/index.tsx | 7 ++-- web/components/Write/index.tsx | 7 ++-- .../home/components/TopTip/index.module.scss | 1 - .../home/components/TopTip/index.tsx | 20 +++++------ web/components/home/index.tsx | 34 ------------------- 5 files changed, 16 insertions(+), 53 deletions(-) diff --git a/web/components/LoginModal/index.tsx b/web/components/LoginModal/index.tsx index 8f0c8fe..34e0696 100644 --- a/web/components/LoginModal/index.tsx +++ b/web/components/LoginModal/index.tsx @@ -3,7 +3,7 @@ import Modal from '../Modal'; import { Form, Input, Button, message, Space, Image, Checkbox } from 'antd'; import { LockOutlined, MailOutlined, UserOutlined } from '@ant-design/icons'; import axios from 'axios'; -import { useRouter } from 'next/router'; +import { useRouter } from 'next/navigation'; import { useForm } from 'antd/lib/form/Form'; import Cookies from 'js-cookie'; import styles from './index.module.scss'; @@ -32,7 +32,7 @@ export default function LoginModal() { const { isShowLoginModal, setUser, showLoginModal } = useAppStore(); const [form] = useForm(); const [tab, setTab] = useState(LOGIN_TYPE.login); - // const router = useRouter(); + const router = useRouter(); const { trigger: login } = useSWRMutation('/api/v1/auth/login', sendRequest); const { trigger: register } = useSWRMutation('/api/v1/auth/signup', sendRequest); const onFinish = (values: any) => { @@ -43,7 +43,8 @@ export default function LoginModal() { message.success('登录成功!'); Cookies.set('token', token); setUser(res.data?.data); - // router.reload(); + router.refresh(); + showLoginModal(false); }); return; } diff --git a/web/components/Write/index.tsx b/web/components/Write/index.tsx index a05d026..26dcaf2 100644 --- a/web/components/Write/index.tsx +++ b/web/components/Write/index.tsx @@ -1,11 +1,10 @@ 'use client'; -import React, { use, useRef } from 'react'; +import React, { useRef } from 'react'; import styles from './index.module.scss'; import { Button, Form, Input, Select, Upload, message } from 'antd'; import { useForm } from 'antd/lib/form/Form'; import JEditor from '../JEditor'; -import TagGroup from '../TagGroup'; import { useRouter } from 'next/navigation'; import { useSWR, useSWRMutation } from '@/hooks'; import Layout from '../Layout'; @@ -17,7 +16,7 @@ const Write = () => { const router = useRouter(); const { user } = useAppStore(); const { data, isLoading } = useSWR({ url: '/api/v1/tags' }); - const { trigger: createPost } = useSWRMutation({ url: '/api/v1/posts' }); + const { trigger: createPost, isMutating } = useSWRMutation({ url: '/api/v1/posts' }); const ref = useRef(null); const handleUpload = (info) => { if (Array.isArray(info)) { @@ -77,7 +76,7 @@ const Write = () => {
-
diff --git a/web/components/home/components/TopTip/index.module.scss b/web/components/home/components/TopTip/index.module.scss index 8f448d1..ad4f211 100644 --- a/web/components/home/components/TopTip/index.module.scss +++ b/web/components/home/components/TopTip/index.module.scss @@ -5,7 +5,6 @@ img { width: 32px; height: 32px; - margin-right: 10px; } h2 { font-size: 14px; diff --git a/web/components/home/components/TopTip/index.tsx b/web/components/home/components/TopTip/index.tsx index e9efcdd..2607e48 100644 --- a/web/components/home/components/TopTip/index.tsx +++ b/web/components/home/components/TopTip/index.tsx @@ -21,17 +21,15 @@ export default function TopTip() {
- - {data?.data?.content?.map((item) => { - return ( - - - - - - ); - })} - + {data?.data?.content?.map((item) => { + return ( + + + + + + ); + })}
diff --git a/web/components/home/index.tsx b/web/components/home/index.tsx index 1358d9c..8736181 100644 --- a/web/components/home/index.tsx +++ b/web/components/home/index.tsx @@ -1,17 +1,6 @@ // 'use client'; -import { useState } from 'react'; -import Layout from '../../components/Layout'; -import { Empty, Pagination } from 'antd'; -import styles from './index.module.scss'; -import TopicItem from './components/TopicItem'; -import CategoryList from './components/CategoryList'; -import { isUndefined, omitBy } from 'lodash'; -import { useParams, useRouter } from 'next/navigation'; -import PinnedList from './components/PinnedList'; import axios from '@/libs/axios'; -import TopTip from './components/TopTip'; -import LoadAsyncMore from '../LoadAsyncMore'; import Articles from './components/Articles'; const Home = async (props: { searchParams: any }) => { @@ -24,26 +13,3 @@ const Home = async (props: { searchParams: any }) => { return ; }; export default Home; - -// export async function getServerSideProps(context) { -// const { query } = context; -// const { categoryId, sort, type, q, page = 1 } = query; -// console.log("categoryId", categoryId, 'sadsdssss', query) -// const reqParams = omitBy( -// { -// // categoryId, -// isHot: categoryId === 'hot', -// type, -// query: q, -// page: page - 1, -// }, -// isUndefined -// ); -// const url = '/api/v1/posts'; -// const res = await axios.get(url, { params: reqParams }).then((res) => res.data); -// return { -// props: { -// data: res, -// }, -// }; -// }