Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions components/basketball/news/NewsCard.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +13,24 @@ const NULL = "http://svcsa.org/uploads/null";
const NewsCard: React.FC<NewsCardProp> = ({ newsObject }) => {
const [imageLoadingError, setImageLoadingError] = useState(false);
const indexOfTeamName = newsObject.content.indexOf("team") + 5;
const [season, setSeason] = useState<BbSeason | null>(null);
useEffect(()=> {
async function fetchSeason() {
const seasonData = await asyncFetch(`/basketball/season/${newsObject.seasonid}`);
setSeason(seasonData);
}
fetchSeason();
}, [newsObject.seasonid])
if (!season) {
return <Custom404 />;
}
const competitionid = season.competitionid;
const groupName = COMPETITIONID_TO_GROUPNAME[competitionid];
const CATEGORY_TO_URL: Record<string, string> = {
"bb_result" : `/basketball/${groupName}/matches/${newsObject.matchid}`,
"bb_schedule" : `/basketball/${groupName}/matches`,
};
const categoryUrl = CATEGORY_TO_URL[newsObject.category] ?? "#";
return (
<Card className="text-white">
<CardBody className="grid justify-items-center content-center">
Expand All @@ -34,7 +55,7 @@ const NewsCard: React.FC<NewsCardProp> = ({ newsObject }) => {
<CardFooter className="flex flex-col text-xs w-48 h-40">
<h3 className="text-center font-bold leading-6">{newsObject.title}</h3>
<p className="text-center font-medium text-slate-900">{newsObject.content}</p>
<a className="text-orange-700 underline cursor-pointer">learn more</a>
<a className="text-orange-700 underline cursor-pointer" href={categoryUrl}>learn more</a>
</CardFooter>
</Card>
);
Expand Down
45 changes: 45 additions & 0 deletions components/basketball/news/NewsItem.tsx
Original file line number Diff line number Diff line change
@@ -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<NewsItemProps> = ({news}) => {
const [season, setSeason] = useState<BbSeason | null>(null);
useEffect(()=> {
async function fetchSeason() {
const seasonData = await asyncFetch(`/basketball/season/${news.seasonid}`);
setSeason(seasonData);
}
fetchSeason();
}, [news.seasonid])
if (!season) {
return <Custom404 />;
}
const competitionid = season.competitionid;
const groupName = COMPETITIONID_TO_GROUPNAME[competitionid];
const CATEGORY_TO_URL: Record<string, string> = {
"bb_result" : `/basketball/${groupName}/matches/${news.matchid}`,
"bb_schedule" : `/basketball/${groupName}/matches`,
};
const categoryUrl = CATEGORY_TO_URL[news.category] ?? "#";
return(
<div >
<div className="grid grid-cols-10 gap-4 min-h-16">
<NewsLogo news={news} />
<div className="col-start-3 col-span-8 cursor-pointer py-3 hover:bg-slate-300">
<Link href={categoryUrl}>
<p className="font-bold">{news.title}</p>
{news.content}{" "}
</Link>
</div>
</div>
<hr className="border-gray-300" />
</div>
)
}
export default NewsItem;
24 changes: 7 additions & 17 deletions components/basketball/news/NewsList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use clinet"
"use clinet";
import { useState } from "react";
import NewsLogo from "./NewsLogo";
import Link from "next/link";
import { Pagination } from "@nextui-org/react";
import NewsItem from "./NewsItem";

interface NewsListProps {
newsList: BbNews[];
Expand All @@ -22,20 +21,11 @@ const NewsList: React.FC<NewsListProps> = ({ newsList }) => {
};
return (
<div>
{currentNewsList.map((news, index) => (
<div key={index}>
<div className="grid grid-cols-10 gap-4 min-h-16">
<NewsLogo news={news} />
<div className="col-start-3 col-span-8 cursor-pointer py-3 hover:bg-slate-300">
<Link href={news.category == "bb_schedule" ? "/basketball" : "#"}>
<p className="font-bold">{news.title}</p>
{news.content}{" "}
</Link>
</div>
</div>
<hr className="border-gray-300" />
</div>
))}
{currentNewsList.map((news, index) => {
return (
<NewsItem news={news} key={index}/>
);
})}
<Pagination
className="grid justify-items-center mt-2"
isCompact
Expand Down