gg
This commit is contained in:
@@ -57,11 +57,6 @@ function getLeagueLabel(match: MatchResponseDto): string {
|
||||
return String(match.leagueName || match.league?.name || "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Football season logic: Aug–Jun
|
||||
* If month >= August (8) → season starts this year: "YYYY-(YYYY+1)"
|
||||
* If month < August → season started last year: "(YYYY-1)-YYYY"
|
||||
*/
|
||||
function getSeasonFromTimestamp(timestampMs: number): string {
|
||||
const date = new Date(timestampMs);
|
||||
const year = date.getFullYear();
|
||||
@@ -73,28 +68,12 @@ function getSeasonFromTimestamp(timestampMs: number): string {
|
||||
return `${year - 1}-${year}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group matches by season string, returning a Map ordered by newest season first.
|
||||
*/
|
||||
function groupMatchesBySeason(matches: MatchResponseDto[]): Map<string, MatchResponseDto[]> {
|
||||
const groups = new Map<string, MatchResponseDto[]>();
|
||||
|
||||
for (const match of matches) {
|
||||
const ts = getMatchTimestamp(match);
|
||||
const season = ts ? getSeasonFromTimestamp(ts) : "Bilinmiyor";
|
||||
if (!groups.has(season)) {
|
||||
groups.set(season, []);
|
||||
}
|
||||
groups.get(season)!.push(match);
|
||||
}
|
||||
|
||||
// Sort by season key descending (newest first)
|
||||
const sorted = new Map(
|
||||
[...groups.entries()].sort((a, b) => b[0].localeCompare(a[0]))
|
||||
);
|
||||
|
||||
return sorted;
|
||||
}
|
||||
const SEASONS = (() => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const currentMonth = new Date().getMonth() + 1;
|
||||
const startYear = currentMonth >= 8 ? currentYear : currentYear - 1;
|
||||
return Array.from({ length: 5 }, (_, i) => `${startYear - i}-${startYear - i + 1}`);
|
||||
})();
|
||||
|
||||
// ─────────────────────────────────────────────────
|
||||
// Main Component
|
||||
@@ -107,13 +86,14 @@ export default function TeamDetailContent() {
|
||||
|
||||
const teamId = params.id as string;
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [activeSeason, setActiveSeason] = useState<string>(SEASONS[0]);
|
||||
|
||||
const { data: teamData, isLoading: teamLoading } = useTeamById(teamId);
|
||||
const {
|
||||
data: matchesResponse,
|
||||
isLoading: matchesLoading,
|
||||
isFetching: matchesFetching,
|
||||
} = useTeamMatches(teamId, { page: currentPage, limit: 20 });
|
||||
} = useTeamMatches(teamId, { page: currentPage, limit: 20, season: activeSeason });
|
||||
|
||||
const cardBg = useColorModeValue("white", "gray.800");
|
||||
const borderColor = useColorModeValue("gray.100", "gray.700");
|
||||
@@ -136,30 +116,16 @@ export default function TeamDetailContent() {
|
||||
[matches]
|
||||
);
|
||||
|
||||
// Group past matches by season
|
||||
const seasonGroups = useMemo(
|
||||
() => groupMatchesBySeason(pastMatches),
|
||||
[pastMatches]
|
||||
);
|
||||
const seasonKeys = useMemo(() => [...seasonGroups.keys()], [seasonGroups]);
|
||||
|
||||
// Active season selection
|
||||
const [activeSeason, setActiveSeason] = useState<string | null>(null);
|
||||
const displaySeason = activeSeason ?? seasonKeys[0] ?? null;
|
||||
const displayMatches = displaySeason ? seasonGroups.get(displaySeason) ?? [] : [];
|
||||
|
||||
// Pagination handlers
|
||||
const handleNextPage = useCallback(() => {
|
||||
if (currentPage < totalPages) {
|
||||
setCurrentPage((p) => p + 1);
|
||||
setActiveSeason(null); // Reset season on page change
|
||||
}
|
||||
}, [currentPage, totalPages]);
|
||||
|
||||
const handlePrevPage = useCallback(() => {
|
||||
if (currentPage > 1) {
|
||||
setCurrentPage((p) => p - 1);
|
||||
setActiveSeason(null);
|
||||
}
|
||||
}, [currentPage]);
|
||||
|
||||
@@ -296,11 +262,10 @@ export default function TeamDetailContent() {
|
||||
</Flex>
|
||||
|
||||
{/* Season Tabs */}
|
||||
{seasonKeys.length > 0 && (
|
||||
{SEASONS.length > 0 && (
|
||||
<HStack gap={2} mb={4} flexWrap="wrap">
|
||||
{seasonKeys.map((season) => {
|
||||
const isActive = season === displaySeason;
|
||||
const count = seasonGroups.get(season)?.length ?? 0;
|
||||
{SEASONS.map((season) => {
|
||||
const isActive = season === activeSeason;
|
||||
return (
|
||||
<Button
|
||||
key={season}
|
||||
@@ -312,14 +277,17 @@ export default function TeamDetailContent() {
|
||||
fontWeight={isActive ? "700" : "500"}
|
||||
fontSize="xs"
|
||||
px={4}
|
||||
onClick={() => setActiveSeason(season)}
|
||||
onClick={() => {
|
||||
setActiveSeason(season);
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
_hover={{
|
||||
transform: "translateY(-1px)",
|
||||
shadow: "sm",
|
||||
}}
|
||||
transition="all 0.2s"
|
||||
>
|
||||
🏆 {season} ({count})
|
||||
🏆 {season}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
@@ -330,17 +298,13 @@ export default function TeamDetailContent() {
|
||||
<Flex justify="center" py={8}>
|
||||
<Spinner size="md" color="primary.500" />
|
||||
</Flex>
|
||||
) : displayMatches.length === 0 && pastMatches.length === 0 ? (
|
||||
) : pastMatches.length === 0 ? (
|
||||
<Text color="fg.muted" textAlign="center" py={8}>
|
||||
Bu sayfada geçmiş maç bulunamadı
|
||||
</Text>
|
||||
) : displayMatches.length === 0 ? (
|
||||
<Text color="fg.muted" textAlign="center" py={8}>
|
||||
Bu sezonda maç bulunamadı
|
||||
Bu sezonda geçmiş maç bulunamadı
|
||||
</Text>
|
||||
) : (
|
||||
<VStack gap={2} align="stretch">
|
||||
{displayMatches.map((match: MatchResponseDto) => (
|
||||
{pastMatches.map((match: MatchResponseDto) => (
|
||||
<MatchRow
|
||||
key={match.id}
|
||||
match={match}
|
||||
@@ -390,7 +354,6 @@ export default function TeamDetailContent() {
|
||||
minW="36px"
|
||||
onClick={() => {
|
||||
setCurrentPage(pageNum);
|
||||
setActiveSeason(null);
|
||||
}}
|
||||
>
|
||||
{pageNum}
|
||||
|
||||
Reference in New Issue
Block a user