From 60dda04cc1551e844aa3035e32834a497686d95c Mon Sep 17 00:00:00 2001 From: mackt <1033530438@qq.com> Date: Fri, 5 Apr 2024 17:11:51 +0800 Subject: [PATCH] chore: Update meta title and add navigation event to UserCard. --- src/app/about/page.tsx | 5 ++++ src/app/download/components/DownloadCard.tsx | 2 ++ src/app/download/page.tsx | 8 +++++-- src/app/layout.tsx | 8 +++++-- src/app/mylist/page.tsx | 7 +++--- src/app/vol/[journalId]/page.tsx | 6 +++++ .../vol/list/[category]/[[...page]]/page.tsx | 6 +++++ src/components/Header/UserCard.tsx | 23 ++++++++++++++++--- src/components/Header/index.tsx | 4 ++-- 9 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index 5b784d5..8d4ba94 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -5,6 +5,11 @@ import styles from './about.module.css'; import { ContributorCard } from '@/components'; import { apiThanks } from '@/services'; +import type { Metadata } from 'next'; + +export const metadata: Metadata = { + title: '关于我们', +}; export interface ContributorCardType { id: string; nickName: string; diff --git a/src/app/download/components/DownloadCard.tsx b/src/app/download/components/DownloadCard.tsx index 76ae088..4ee36d6 100644 --- a/src/app/download/components/DownloadCard.tsx +++ b/src/app/download/components/DownloadCard.tsx @@ -1,3 +1,5 @@ +'use client'; + import { useState } from 'react'; import Image from 'next/image'; diff --git a/src/app/download/page.tsx b/src/app/download/page.tsx index e398954..40cd34c 100644 --- a/src/app/download/page.tsx +++ b/src/app/download/page.tsx @@ -1,9 +1,13 @@ -'use client'; - import Image from 'next/image'; import DownloadCard from '@/app/download/components/DownloadCard'; +import type { Metadata } from 'next'; + +export const metadata: Metadata = { + title: '下载', +}; + const qrCodeList: Array = [ { platform: 'APP Store', diff --git a/src/app/layout.tsx b/src/app/layout.tsx index e884c6f..ed647b5 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,10 +1,14 @@ +import { Metadata, Viewport } from 'next'; + import { Header, Footer, PlayerBar } from '@/components'; -import type { Metadata, Viewport } from 'next'; import './globals.css'; export const metadata: Metadata = { - title: '雀乐', + title: { + template: '%s - 雀乐', + default: '雀乐', + }, description: '独立 不独于世', icons: { icon: '/favicon.ico', diff --git a/src/app/mylist/page.tsx b/src/app/mylist/page.tsx index b3996fa..6244f3c 100644 --- a/src/app/mylist/page.tsx +++ b/src/app/mylist/page.tsx @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'; +import Head from 'next/head'; import { useShallow } from 'zustand/react/shallow'; import styles from './index.module.css'; @@ -12,11 +13,10 @@ import { SongCardList } from '@/components'; import { apiGetSongCollect } from '@/services'; import useUserStore from '@/store/user'; -export default function Journal({ params }: { params: { category?: string; page?: number } }) { - const { userInfo, userLogout } = useUserStore( +export default function Journal() { + const { userInfo } = useUserStore( useShallow((state) => ({ userInfo: state.userInfo, - userLogout: state.userLogout, })), ); @@ -52,6 +52,7 @@ export default function Journal({ params }: { params: { category?: string; page? ]; useEffect(() => { + document.title = '我的收藏 - 雀乐'; getList(); }, [type, pageNum]); diff --git a/src/app/vol/[journalId]/page.tsx b/src/app/vol/[journalId]/page.tsx index 056c553..498a692 100644 --- a/src/app/vol/[journalId]/page.tsx +++ b/src/app/vol/[journalId]/page.tsx @@ -6,6 +6,12 @@ import { notFound } from 'next/navigation'; import { JournalCard, SongCardList, HotJournalList, Comment, Collect } from '@/components'; import { apiGetJournalInfoById, apiGetSongsByJournalNo } from '@/services'; +export async function generateMetadata({ params: { journalId } }: { params: { journalId: string } }) { + const res = await apiGetJournalInfoById({ id: journalId }); + const title = res.code === 200 ? res.data.title : '期刊详情'; + return { title }; +} + const getData = async (journalId: string) => { const [journalInfoRes, songListRes] = await Promise.all([ apiGetJournalInfoById({ id: journalId }), diff --git a/src/app/vol/list/[category]/[[...page]]/page.tsx b/src/app/vol/list/[category]/[[...page]]/page.tsx index c52a957..f4cb253 100644 --- a/src/app/vol/list/[category]/[[...page]]/page.tsx +++ b/src/app/vol/list/[category]/[[...page]]/page.tsx @@ -3,6 +3,12 @@ import { Category, JournalList, HotJournalList } from '@/components'; import { apiSearchCategory } from '@/services'; +import type { Metadata } from 'next'; + +export const metadata: Metadata = { + title: '期刊', +}; + const getCategoryList = async () => { const result = await apiSearchCategory(); return result.code === 200 ? result.data : []; diff --git a/src/components/Header/UserCard.tsx b/src/components/Header/UserCard.tsx index b65d7dd..a429389 100644 --- a/src/components/Header/UserCard.tsx +++ b/src/components/Header/UserCard.tsx @@ -1,12 +1,14 @@ import { useState, useEffect } from 'react'; import Image from 'next/image'; +import { useRouter } from 'next/navigation'; import { useShallow } from 'zustand/react/shallow'; import { Avatar } from '@/components'; import useUserStore from '@/store/user'; interface Props { + onClose: () => void; className?: string; } @@ -15,7 +17,8 @@ interface TDataList { value: number; } -export default function UserCard({ className }: Props) { +export default function UserCard({ onClose, className }: Props) { + const router = useRouter(); const { userInfo, userLogout } = useUserStore( useShallow((state) => ({ userInfo: state.userInfo, @@ -30,6 +33,17 @@ export default function UserCard({ className }: Props) { { label: '获赞', value: userInfo.thumbUpCount }, ]); + const handleGoMyList = () => { + router.push('/myList'); + onClose(); + }; + + const handleLogout = async () => { + await userLogout; + router.push('/'); + onClose(); + }; + useEffect(() => { setUserDataList([ { label: '关注', value: userInfo.followCount }, @@ -64,13 +78,16 @@ export default function UserCard({ className }: Props) { {/* 按钮 */}