"use client";
import Link from "next/link";
import { LinkType } from "../_lib/data/linkType";
import { Link as _Link } from "../_lib/data/link";
import { useEffect, useMemo } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClock, faFire, faTimeline, faTimesCircle, faTimesRectangle, faVolumeTimes } from "@fortawesome/free-solid-svg-icons";
import { useAtom } from "jotai";
import { linkTypeAtom } from "../_lib/atom";
import Image from "next/image";
const LinkBlock = ({ val }: { val: _Link }) => {
return
{val.name}
{val.description}
}
export default function LinkListBox({ linkTypeList, linkList, showHot, showRecent }: { linkTypeList: LinkType[]; linkList: _Link[]; showHot: boolean; showRecent: boolean }) {
const hotList = useMemo(() => linkList.filter((val, index) => val.isHot && index < 12), [])
const recentList = useMemo(() => linkList.map(val => val).sort((a, b) => b.addTime - a.addTime).filter((_, idx) => idx < 12), [])
const [currentId] = useAtom(linkTypeAtom)
useEffect(() => {
console.log(currentId);
if (currentId) {
// 根据 targetId 查找对应的元素
const element = document.getElementById(currentId);
if (element) {
// 滚动到找到的元素位置
element.scrollIntoView({ behavior: 'smooth' });
}
}
}, [currentId])
return
{
showHot &&
热门网站
{
hotList.map(val => (
))
}
}
{
showRecent &&
最新收录
{
recentList.map(val => (
))
}
}
{
linkTypeList.map(item => (
{item.label}
{
linkList.filter(val => val.type === item._id).map(val => (
))
}
))
}
}