import axios from 'axios' import { useEffect, useState } from 'react' import Tabs from 'react-bootstrap/Tabs' import Tab from 'react-bootstrap/Tab' import ToggleButtonGroup from 'react-bootstrap/ButtonGroup' import ToggleButton from 'react-bootstrap/Button' import useSWR from 'swr' import Table from 'react-bootstrap/Table' import 'bootstrap/dist/css/bootstrap.min.css'; const fetcher = url => axios.get(url).then(res => res.data) var RABI_RIBI_GAME_ID = "o6g0o8d2" function VariableSelector(p) { const {values} = p const displayValues = Object.keys(values.values.values).map((key)=>[values.values.values[key],key]) const [selected,setSelected] = useState(Object.keys(values.values.values)[0]) const handleChange=(e)=>{ setSelected(e.target.id) var arr = {...p.selectionValues} arr[p.category.id][p.selectionID]=values.id+","+e.target.id p.setSelectionValues(arr) } return <> {displayValues.map((value,i)=>{value[0].label})}
} function getLeaderboard(categoryID,variables) { const { data,error } = useSWR("https://www.speedrun.com/api/v1/leaderboards/"+RABI_RIBI_GAME_ID+"/category/"+categoryID+variables,fetcher) return { data: data, isLoading: !error && !data, isError: error } } function Leaderboard(p) { const {data} = p return {data?.data.runs.map((run)=>{/*#*/} {/*Player*/} {/*Time without loads*/} {/*Time with loads*/} {/*Platform*/} {/*Version*/} {/*Date*/} {/*Video*/} )}
# Player Time without loads Time with loads Platform Version Date Video
{run.place}{run.run.players[0].id??run.run.players[0]?.name}{run.run.times.realtime_noloads_t??""}{run.run.times.realtime_t}{run.run.system.platform}{run.run.values.p85me3lg}{run.run.date}{run.run.videos?.links[0].uri}
} export default function Home(p) { var {CATEGORIES,VARIABLES}= p const [selectedTab,setSelectedTab] = useState("") const [selectionValues,setSelectionValues] = useState({}) const [appendStr,setAppendStr] = useState("") const {data} = getLeaderboard(selectedTab,appendStr) useEffect(()=>{ var arr = {...p.selectionValues} CATEGORIES.forEach((cat,i)=>{ if (i==0) { setSelectedTab(cat.id) } arr[cat.id]={} VARIABLES.filter((v)=>(v.category===cat.id||v.category===null)&&v["is-subcategory"]).forEach((v,i)=>{ arr[cat.id][i]=(v.id+","+Object.keys(v.values.values)[0]) }) }) setSelectionValues(arr) },[]) useEffect(()=>{ var appendStr = "" //console.log(selectionValues[selectedTab]) for (var val in selectionValues[selectedTab]) { //console.log(selectionValues[selectedTab][val]) var split = selectionValues[selectedTab][val].split(",") if (appendStr.length===0) { appendStr="?" } else { appendStr+="&" } appendStr+="var-"+split[0]+"="+split[1] } setAppendStr(appendStr) },[selectedTab,selectionValues]) return <>{setSelectedTab(e)}}> {CATEGORIES.map((cat)=> {/*cat.rules*/} {VARIABLES.filter((v)=>(v.category===cat.id||v.category===null)&&v["is-subcategory"]).map((v,i)=>)} )} {} } export async function getStaticProps() { var CATEGORIES = {} var RUN_DATA = {} var VARIABLES = {} await axios.get("https://www.speedrun.com/api/v1/games/"+RABI_RIBI_GAME_ID+"/categories").then((data)=>{ CATEGORIES = data.data.data }) await axios.get("https://www.speedrun.com/api/v1/games/"+RABI_RIBI_GAME_ID+"/variables").then((data)=>{ VARIABLES = data.data.data }) return { props: { RUN_DATA, CATEGORIES, VARIABLES }, // Next.js will attempt to re-generate the page: // - When a request comes in // - At most once every 10 seconds revalidate: 10, // In seconds } }