update(component): Add thumb and update collect.

mack-mac
mackt 7 months ago
parent 751193ea16
commit 0f21aa3586

@ -3,7 +3,7 @@
import Link from 'next/link'; import Link from 'next/link';
import { notFound } from 'next/navigation'; import { notFound } from 'next/navigation';
import { JournalCard, SongCardList, HotJournalList, Comment, Coolect } from '@/components'; import { JournalCard, SongCardList, HotJournalList, Comment, Collect } from '@/components';
import { apiGetJournalInfoById, apiGetSongsByJournalNo } from '@/services'; import { apiGetJournalInfoById, apiGetSongsByJournalNo } from '@/services';
const getData = async (journalId: string) => { const getData = async (journalId: string) => {
@ -51,10 +51,9 @@ export default async function JournalDetail({ params: { journalId } }: { params:
</div> </div>
</div> </div>
{/* 收藏 */} {/* 收藏 */}
<Coolect <Collect
haveCollect={journalInfo.haveCollect} active={journalInfo.haveCollect}
count={journalInfo.totalCommentReply} text={`${journalInfo.totalCommentReply}人收藏`}
text="人收藏"
id={journalInfo.id} id={journalInfo.id}
type="1" type="1"
/> />
@ -68,11 +67,7 @@ export default async function JournalDetail({ params: { journalId } }: { params:
{/* 卡片 */} {/* 卡片 */}
<SongCardList className="my-40px w-full" songList={songList} /> <SongCardList className="my-40px w-full" songList={songList} />
<Comment <Comment journalId={journalInfo.id} totalCommentReply={journalInfo.totalCommentReply} className="w-full" />
commentList={journalInfo.commentList}
totalCommentReply={journalInfo.totalCommentReplyInt}
className="w-full"
/>
</div> </div>
<div className="w-[346px]"> <div className="w-[346px]">

@ -1,3 +1,5 @@
// 期刊收藏
'use client'; 'use client';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@ -5,38 +7,31 @@ import { useEffect, useState } from 'react';
import { apiCollect } from '@/services'; import { apiCollect } from '@/services';
interface Props { interface Props {
haveCollect: boolean; active: boolean;
id: string; id: string;
type: string; type: string;
size?: number; size?: number;
count?: string;
text?: string; text?: string;
} }
export default function Collect({ haveCollect, id, type, size = 24, count = '0', text = '' }: Props) { export default function Collect({ active, id, type, size = 24, text = '' }: Props) {
const [state, setState] = useState<boolean>(false); // 收藏状态 const [state, setState] = useState<boolean>(false); // 收藏状态
useEffect(() => { useEffect(() => {
setState(haveCollect); setState(active);
}, [haveCollect]); }, [active]);
// 收藏/取消收藏 // 收藏/取消收藏
const handleCollect = async () => { const handleCollect = async () => {
setState(!state); setState(!state); // 更新收藏状态
const res = await apiCollect({ isAdd: !state, objectId: id, collectType: type }); const res = await apiCollect({ isAdd: !state, objectId: id, collectType: type });
if (res.code !== 200) { if (res.code !== 200) setState(!state); // 如果请求失败,回退状态
setState(!state);
}
}; };
return ( return (
<div className="flex flex-row items-center gap-[9px] cursor-pointer group" onClick={handleCollect}> <div className="flex flex-row items-center gap-[9px] cursor-pointer group" onClick={handleCollect}>
{/* 文案 */} {/* 文案 */}
{!!text && ( {!!text && <p className="text-[rgba(0,0,0,0.4)] text-[13px] leading-[18.2px] group-hover:text-theme">{text}</p>}
<p className="text-[rgba(0,0,0,0.4)] text-[13px] leading-[18.2px] group-hover:text-theme">
{`${count}${text}`}
</p>
)}
{/* 图标 */} {/* 图标 */}
<div <div

@ -0,0 +1,40 @@
'use client';
import { useEffect, useState } from 'react';
import { apiCollect } from '@/services';
interface Props {
active: boolean;
id: string;
type: string;
size?: number;
text?: string;
}
export default function Collect({ active, id, type, size = 24, text = '' }: Props) {
const [state, setState] = useState<boolean>(false); // 点赞状态
useEffect(() => {
setState(active);
}, [active]);
// 收藏/取消收藏
const handleCollect = async () => {
setState(!state); // 更新点赞状态
const res = await apiCollect({ isAdd: !state, objectId: id, collectType: type });
if (res.code !== 200) setState(!state); // 如果请求失败,回退状态
};
return (
<div className="flex flex-row items-center gap-[9px] cursor-pointer group" onClick={handleCollect}>
{/* 文案 */}
{!!text && <p className="text-[rgba(0,0,0,0.4)] text-[13px] leading-[18.2px] group-hover:text-theme">{text}</p>}
{/* 图标 */}
<div
className={`w-[${size}px] h-[${size}px] ${state ? 'bg-[url(/img/icon/thumb-active.svg)]' : 'bg-[url(/img/icon/thumb.svg)]'} group-hover:bg-[url(/img/icon/thumb-active.svg)]`}
/>
</div>
);
}
Loading…
Cancel
Save