"use client"; import React, { useState } from "react"; import ChannelRow from "./TwitchTableRow"; interface TwitchChannelDataProp { channel_name: string; profile_pic: string; subscribers: number; sub_org: string; twitch_followers: number; total_sum: number; max_following?: number; } interface TwitchDataTableProp { channel_data: TwitchChannelDataProp[]; timestamp: string; } type SortKey = keyof TwitchChannelDataProp | "rank" | "max_following"; const TwitchDataTable = ({ channel_data, timestamp }: TwitchDataTableProp) => { const [sortKey, setSortKey] = useState("twitch_followers"); const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc"); const [indexName, setIndexName] = useState("RANK"); const handleSort = (key: SortKey) => { if (sortKey === key) { setSortOrder(sortOrder === "asc" ? "desc" : "asc"); } else { setSortKey(key); setSortOrder("desc"); } setIndexName(key === "sub_org" ? "INDEX" : "RANK"); }; const dataWithMax = channel_data.map((channel) => ({ ...channel, max_following: Math.max( channel.subscribers || 0, channel.twitch_followers || 0 ), })); const sortedData = [...dataWithMax].sort((a, b) => { let aValue: any, bValue: any; if (sortKey === "rank") { aValue = dataWithMax.indexOf(a) + 1; bValue = dataWithMax.indexOf(b) + 1; } else { aValue = a[sortKey]; bValue = b[sortKey]; } if (typeof aValue === "string") { return sortOrder === "asc" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue); } return sortOrder === "asc" ? aValue - bValue : bValue - aValue; }); return ( <>
Limited data shown on mobile view!

The Twitch Table

Updated Hourly. Retrieved at: {timestamp}

{/* Legend wrapper - stacked sections on all screen sizes */}
{/* Column explanations */}

Column Explanations

SUM(YT+TTV): Total combined followers across both platforms
MAX(YT,TTV): Highest follower count between platforms
{/* Horizontal divider */}
{/* Color key */}

MAX Column Color Key

YouTube subscriber count is higher
Twitch follower count is higher
{sortedData.map((channel, index) => ( ))}
{indexName} CHANNEL handleSort("sub_org")} > GROUP {sortKey === "sub_org" && ( {sortOrder === "asc" ? "▲" : "▼"} )} handleSort("subscribers")} > YOUTUBE SUBS {sortKey === "subscribers" && ( {sortOrder === "asc" ? "▲" : "▼"} )} handleSort("twitch_followers")} > TWITCH FOLLOWS {sortKey === "twitch_followers" && ( {sortOrder === "asc" ? "▲" : "▼"} )} handleSort("total_sum")} > SUM(YT+TTV) {sortKey === "total_sum" && ( {sortOrder === "asc" ? "▲" : "▼"} )} handleSort("max_following")} > MAX(YT, TTV) {sortKey === "max_following" && ( {sortOrder === "asc" ? "▲" : "▼"} )}
); }; export default TwitchDataTable; export type { TwitchDataTableProp, TwitchChannelDataProp };