From bb114d679632efcf470033187c1a10ec6aed3435 Mon Sep 17 00:00:00 2001 From: vivianzhang Date: Tue, 15 Oct 2024 15:39:36 -0700 Subject: [PATCH 1/2] add link to news --- components/basketball/news/NewsCard.tsx | 25 +++++++++++- components/basketball/news/NewsList.tsx | 53 ++++++++++++++++++------- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/components/basketball/news/NewsCard.tsx b/components/basketball/news/NewsCard.tsx index 3e9d0dd..fee9db9 100644 --- a/components/basketball/news/NewsCard.tsx +++ b/components/basketball/news/NewsCard.tsx @@ -1,6 +1,9 @@ "use client"; +import Custom404 from "@/components/404"; +import { asyncFetch } from "@/utils/fetch"; +import { COMPETITIONID_TO_GROUPNAME } from "@/utils/variables"; import { Card, CardBody, CardFooter, Image } from "@nextui-org/react"; -import { useState } from "react"; +import { useEffect, useState } from "react"; interface NewsCardProp { newsObject: BbNews; @@ -10,6 +13,24 @@ const NULL = "http://svcsa.org/uploads/null"; const NewsCard: React.FC = ({ newsObject }) => { const [imageLoadingError, setImageLoadingError] = useState(false); const indexOfTeamName = newsObject.content.indexOf("team") + 5; + const [season, setSeason] = useState(null); + useEffect(()=> { + async function fetchSeason() { + const seasonData = await asyncFetch(`/basketball/season/${newsObject.seasonid}`); + setSeason(seasonData); + } + fetchSeason(); + }, [newsObject.seasonid]) + if (!season) { + return ; + } + const competitionid = season.competitionid; + const groupName = COMPETITIONID_TO_GROUPNAME[competitionid]; + const CATEGORY_TO_URL: Record = { + "bb_result" : `/basketball/${groupName}/matches/${newsObject.matchid}`, + "bb_schedule" : `/basketball/${groupName}/matches`, + }; + const categoryUrl = CATEGORY_TO_URL[newsObject.category] ?? "#"; return ( @@ -34,7 +55,7 @@ const NewsCard: React.FC = ({ newsObject }) => {

{newsObject.title}

{newsObject.content}

- learn more + learn more
); diff --git a/components/basketball/news/NewsList.tsx b/components/basketball/news/NewsList.tsx index 951c7e7..ae50404 100644 --- a/components/basketball/news/NewsList.tsx +++ b/components/basketball/news/NewsList.tsx @@ -1,8 +1,11 @@ -"use clinet" -import { useState } from "react"; +"use clinet"; +import { useEffect, useState } from "react"; import NewsLogo from "./NewsLogo"; import Link from "next/link"; import { Pagination } from "@nextui-org/react"; +import { asyncFetch } from "@/utils/fetch"; +import Custom404 from "@/components/404"; +import { COMPETITIONID_TO_GROUPNAME } from "@/utils/variables"; interface NewsListProps { newsList: BbNews[]; @@ -22,20 +25,42 @@ const NewsList: React.FC = ({ newsList }) => { }; return (
- {currentNewsList.map((news, index) => ( -
-
- -
- -

{news.title}

- {news.content}{" "} - + {currentNewsList.map((news, index) => { + const [season, setSeason] = useState(null); + useEffect(() => { + async function fetchSeason() { + const seasonData = await asyncFetch( + `/basketball/season/${news.seasonid}` + ); + setSeason(seasonData); + } + fetchSeason(); + }, [news.seasonid]); + if (!season) { + return ; + } + const competitionid = season.competitionid; + const groupName = COMPETITIONID_TO_GROUPNAME[competitionid]; + const CATEGORY_TO_URL: Record = { + bb_result: `/basketball/${groupName}/matches/${news.matchid}`, + bb_schedule: `/basketball/${groupName}/matches`, + }; + const categoryUrl = CATEGORY_TO_URL[news.category] ?? "#"; + return ( +
+
+ +
+ +

{news.title}

+ {news.content}{" "} + +
+
-
-
- ))} + ); + })} Date: Tue, 15 Oct 2024 21:18:08 -0700 Subject: [PATCH 2/2] fix error --- components/basketball/news/NewsItem.tsx | 45 +++++++++++++++++++++++++ components/basketball/news/NewsList.tsx | 41 ++-------------------- 2 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 components/basketball/news/NewsItem.tsx diff --git a/components/basketball/news/NewsItem.tsx b/components/basketball/news/NewsItem.tsx new file mode 100644 index 0000000..f2e21a8 --- /dev/null +++ b/components/basketball/news/NewsItem.tsx @@ -0,0 +1,45 @@ +import Link from "next/link" +import NewsLogo from "./NewsLogo" +import { useEffect, useState } from "react"; +import { asyncFetch } from "@/utils/fetch"; +import Custom404 from "@/components/404"; +import { COMPETITIONID_TO_GROUPNAME } from "@/utils/variables"; + +interface NewsItemProps { + news: BbNews +} +const NewsItem: React.FC = ({news}) => { + const [season, setSeason] = useState(null); + useEffect(()=> { + async function fetchSeason() { + const seasonData = await asyncFetch(`/basketball/season/${news.seasonid}`); + setSeason(seasonData); + } + fetchSeason(); + }, [news.seasonid]) + if (!season) { + return ; + } + const competitionid = season.competitionid; + const groupName = COMPETITIONID_TO_GROUPNAME[competitionid]; + const CATEGORY_TO_URL: Record = { + "bb_result" : `/basketball/${groupName}/matches/${news.matchid}`, + "bb_schedule" : `/basketball/${groupName}/matches`, + }; + const categoryUrl = CATEGORY_TO_URL[news.category] ?? "#"; + return( +
+
+ +
+ +

{news.title}

+ {news.content}{" "} + +
+
+
+
+ ) +} +export default NewsItem; \ No newline at end of file diff --git a/components/basketball/news/NewsList.tsx b/components/basketball/news/NewsList.tsx index ae50404..803a6ca 100644 --- a/components/basketball/news/NewsList.tsx +++ b/components/basketball/news/NewsList.tsx @@ -1,11 +1,7 @@ "use clinet"; -import { useEffect, useState } from "react"; -import NewsLogo from "./NewsLogo"; -import Link from "next/link"; +import { useState } from "react"; import { Pagination } from "@nextui-org/react"; -import { asyncFetch } from "@/utils/fetch"; -import Custom404 from "@/components/404"; -import { COMPETITIONID_TO_GROUPNAME } from "@/utils/variables"; +import NewsItem from "./NewsItem"; interface NewsListProps { newsList: BbNews[]; @@ -26,39 +22,8 @@ const NewsList: React.FC = ({ newsList }) => { return (
{currentNewsList.map((news, index) => { - const [season, setSeason] = useState(null); - useEffect(() => { - async function fetchSeason() { - const seasonData = await asyncFetch( - `/basketball/season/${news.seasonid}` - ); - setSeason(seasonData); - } - fetchSeason(); - }, [news.seasonid]); - if (!season) { - return ; - } - const competitionid = season.competitionid; - const groupName = COMPETITIONID_TO_GROUPNAME[competitionid]; - const CATEGORY_TO_URL: Record = { - bb_result: `/basketball/${groupName}/matches/${news.matchid}`, - bb_schedule: `/basketball/${groupName}/matches`, - }; - const categoryUrl = CATEGORY_TO_URL[news.category] ?? "#"; return ( -
-
- -
- -

{news.title}

- {news.content}{" "} - -
-
-
-
+ ); })}