From cb6ca0317eb522c3f146685b9b9a4590fbb007b0 Mon Sep 17 00:00:00 2001 From: Chris Vickery Date: Wed, 14 Aug 2024 17:11:54 -0700 Subject: [PATCH] lets find out if this works lol --- package.json | 1 + public/dire.png | Bin 0 -> 1742 bytes public/radiant.png | Bin 0 -> 2534 bytes src/api/match.js | 12 ++ src/api/user.js | 12 ++ src/components/auth.js | 1 + src/components/drawer.js | 5 + src/components/pages/match-history/index.jsx | 56 +++++++++ src/components/pages/match-history/match.jsx | 119 +++++++++++++++++++ src/components/routes.jsx | 4 + yarn.lock | 5 + 11 files changed, 215 insertions(+) create mode 100644 public/dire.png create mode 100644 public/radiant.png create mode 100644 src/api/match.js create mode 100644 src/api/user.js create mode 100644 src/components/pages/match-history/index.jsx create mode 100644 src/components/pages/match-history/match.jsx diff --git a/package.json b/package.json index 718838f..7079be4 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "react-ga": "^2.7.0", "react-router-dom": "^5.1.2", "react-scripts": "3.2.0", + "short-time-ago": "^2.0.0", "thyming": "^0.1.1", "use-global-hook": "^0.1.12" }, diff --git a/public/dire.png b/public/dire.png new file mode 100644 index 0000000000000000000000000000000000000000..9ccbf4debacf3658f77a5a5ece40c0623a0767bf GIT binary patch literal 1742 zcmV;<1~K_kNk&G-1^@t8MM6+kP&il$0000G0000#002J#06|PpNL&E`00EFg+uE^5 z-yhqyZJTX6yGv_3Y0a@+skCj|w#^%V@B2K}OcfCmp#0mmNUtw);iP{Ez>8Eym6&jQ2x9SV+ZaGem!gr(x6&@y8uV|CL1zPHQLHkLls+?cMuv$&pbC9o6aTfHyR?Mpb93LCcr73#H z0u!1!vR{Dbk5;`|v{r)aw~`sUH9y&4r-`B{G2g&=k)C381gwWly1@HS*fC}(-M}rk zj9a*F->%&|x$fG&wbMkgNlHoJni%70s!{&?1y)cvAVdWK08knLodGI906+jf8483! zp#?%`iv$2+EdUs}wwJ5@bMecRt9HBzlV{KL;5@)TReC^qfc<*?qxZ-30q6ny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eivnX<0>Xvz(oBfLh*_U4#yhmZX zxA3X!uQD|s_U)3ld;PGjCY66=8x_yspbzz7IZMZq_x*|ovy3n^nz9Bi7!cLMh>^xw ki$a+r)FUp}<_~#M{AE3emuv(bHW<^ruW>OtF?b*V06=(h0ssI2 literal 0 HcmV?d00001 diff --git a/public/radiant.png b/public/radiant.png new file mode 100644 index 0000000000000000000000000000000000000000..e536ee1022f008d6ecfca8dd2bae0eb879d8cfbe GIT binary patch literal 2534 zcmV<|BMM6+kP&il$0000G0000#002J#06|PpNNWKA00DrbZMSJ> zUBt?X)&Zt5lTF&Yq#cq3({x znv4J^vDhIrKNv;FTDgg8*DGx_dQoQ|ft&->dz7PV67`R3@jFI}2R`bOKal2IjH+Iw z+p8uSDaWaZ{2}!jrr-)`UzuA&>T6~ikbb{0uNMaBZD;~HP8*3ro?!;YnM}I!My|dt z`q}i$?8w(HiC`2cDPWW(8Di8ZxFO?i!I#sn5W?wFNZ|A&q;Yx`GXJ~`cFCNcgiuab zf*+@S!Glx303(drC8dmVB{7UbBo0On2@J3q0J$HV02eUDWCmO(GKn?-Gc4x7XdsIq zL(t1$2uyC1+XA!Bdt&!aQ;<$94HWi~>I0?yg!({n_AixQP#%9r;w~0+E)$ps%{8~0 zZt6h)u$EyU={}%rz#XVMQbrVvBsqYzM@(6J*UZWJ+4<2-S4(M(2mDt709H^qAWR4V z0PrRNodGI906+jf83=p_CTb6C;RdFH^#tR zdralavi@L-yVOm_)p)r!hW@W==z!XM0n4yzi#}KtBywxF7O4D)~S1 z-|!!l-;|vscOw5|{D9_*peOS$>YwVrvwNz49shs)FP@L0Kjr_A{mS|U{zd%*{Gazf z+<)+&|NJ(7-Fr2D+O^E+|GDQxpm)XB;UK@$q4RE>>dkiqECjDh0M}mAMHbVN$md*@ zMsm-{(NXQ|qPlHypwSxrAqD#gsdL_!tgKO`1)cy8<2FY;CGSz|6@(A$k;S;w}{)j)5s1)+d>HpWBsYQ&g zvNS-`V>kU;%3~hAvXqzW0$az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Uinwq& zu5GGf#a|2?EFjX~D$a`ZFvZUQKY3W`ce69pHVE~0wFDV)8iW6{P5-RUhoe3U26>GU zw98+-zoe9m)9>K{Vi6Onq&;yyilFyLp6k$SVf9(#{{qZt{jgMh?Q%!t1?l}5fd6XH zkhBVWKj#&L=IvSwzUyu1|C>h?b+WbS@H7n;h>5e)?AmQbL}QWmuw05?Wrt{tdfl-!JBC wC`OT@()0tr>VD{}w-%gzNn(@tdR^23T@ki*iA|N{V(khK=MY#5cR@{H09H8zVgLXD literal 0 HcmV?d00001 diff --git a/src/api/match.js b/src/api/match.js new file mode 100644 index 0000000..e00b60e --- /dev/null +++ b/src/api/match.js @@ -0,0 +1,12 @@ +import Request from "config-request"; + +export async function getMatch(matchId) { + return new Promise((resolve, reject) => { + Request.get(`/matches/${matchId}`, {}, function (err, data) { + if (err) { + reject(err); + } + resolve(data ? data : null); + }); + }); +} diff --git a/src/api/user.js b/src/api/user.js new file mode 100644 index 0000000..b216fff --- /dev/null +++ b/src/api/user.js @@ -0,0 +1,12 @@ +import Request from "config-request"; + +export async function getUser(userId) { + return new Promise((resolve, reject) => { + Request.get(`/users/${userId}`, {}, function (err, data) { + if (err) { + reject(err); + } + resolve(data ? data : null); + }); + }); +} diff --git a/src/components/auth.js b/src/components/auth.js index 3fd519f..17b0bff 100644 --- a/src/components/auth.js +++ b/src/components/auth.js @@ -18,6 +18,7 @@ function decodeToken(store, data) { const token = Jwt.decode(data); Request.configure({ baseUrl: token.baseUrl, + // baseUrl: 'http://localhost:6969/', token: data, authorization: 'x-auth-token', options: { diff --git a/src/components/drawer.js b/src/components/drawer.js index 088894c..2dd1d0b 100644 --- a/src/components/drawer.js +++ b/src/components/drawer.js @@ -101,6 +101,11 @@ export default function AppDrawer(props) { text: "Top Players", path: "/top", }, + { + icon: EmojiEventsIcon, + text: "Match History", + path: "/matches", + }, { icon: GroupIcon, text: "Your Teams", diff --git a/src/components/pages/match-history/index.jsx b/src/components/pages/match-history/index.jsx new file mode 100644 index 0000000..c5134eb --- /dev/null +++ b/src/components/pages/match-history/index.jsx @@ -0,0 +1,56 @@ +import React, { useEffect, useState } from "react"; + +import Grid from "@material-ui/core/Grid"; +import List from "@material-ui/core/List"; +import ListItem from "@material-ui/core/ListItem"; +import ListItemText from "@material-ui/core/ListItemText"; +import Paper from "@material-ui/core/Paper"; +import Typography from "@material-ui/core/Typography"; + +import Match from './match'; + +import StandardPage from "../standard-page"; + +import { useUserState } from "../../auth"; + +import { getTopPlayers } from "../../../api/top"; +import { getMatch } from "../../../api/match"; +import { getUser } from "../../../api/user"; + +export default function MatchHistory() { + const [userProfile, setUserProfile] = useState(null); + const [{ user }] = useUserState(); + + useEffect(() => { + async function fetchData() { + const userData = getUser(user.steamid); + + setUserProfile(await userData); + } + fetchData(); + }, []); + + + console.log(user, userProfile); + + if (!userProfile) { + return ; + } + + // grab the 100 at the end of the array, they're the most recent + const recentMatches = userProfile.matches.length > 100 ? userProfile.matches.slice(userProfile.matches.length - 100) : userProfile.matches + + return ( + + + {`Match History`} + + + {recentMatches.reverse().map((matchId) => ( + + ) + )} + + + ); +} diff --git a/src/components/pages/match-history/match.jsx b/src/components/pages/match-history/match.jsx new file mode 100644 index 0000000..3acc8c0 --- /dev/null +++ b/src/components/pages/match-history/match.jsx @@ -0,0 +1,119 @@ +import React, { useEffect, useState } from "react"; + +import Grid from "@material-ui/core/Grid"; +import List from "@material-ui/core/List"; +import ListItem from "@material-ui/core/ListItem"; +import ListItemText from "@material-ui/core/ListItemText"; +import Paper from "@material-ui/core/Paper"; +import Typography from "@material-ui/core/Typography"; +import EmojiEventsIcon from "@material-ui/icons/EmojiEvents"; +import CloudDownloadIcon from "@material-ui/icons/CloudDownload"; + +import { timeAgo } from "short-time-ago"; + +import { useUserState } from "../../auth"; +import { getMatch } from "../../../api/match"; +import { CloudDownload } from "@material-ui/icons"; + +export default function Match({ matchId }) { + const [matchData, setMatchData] = useState(null); + const [{ user }] = useUserState(); + + useEffect(() => { + async function fetchData() { + const userData = getMatch(matchId); + + setMatchData(await userData); + } + fetchData(); + }, []); + + if (!matchData) { + return ( + + + + + + Loading data for match {matchId.substr(0, 8)}... + + + ); + } + + console.log(matchData); + + const startDate = matchData.startTime.substr(0, 8); + const startTime = matchData.startTime.substr(8); + console.log(startDate, startTime); + + const wasOnDire = matchData.teams.dire.indexOf(user.steamid) >= 0; + const teamName = wasOnDire ? "dire" : "radiant"; + const didWin = matchData.outcome === teamName; + + const myHeroPick = matchData.heroPicks[user.steamid]; + console.log(myHeroPick); + // https://cdn.akamai.steamstatic.com/apps/dota2/images/dota_react/heroes/abaddon.png + + const randomText = myHeroPick && (myHeroPick.rerandom ? "Rerandomed" : (myHeroPick.random ? "Randomed" : "")); + + const gameLength = []; + + if (matchData.gameLength > 3600) { + gameLength.push(`${Math.floor(matchData.gameLength / 3600)}hr`); + } + if (matchData.gameLength > 60) { + gameLength.push(`${Math.floor(matchData.gameLength / 60) % 60}m`); + } + if (matchData.gameLength) { + gameLength.push(`${matchData.gameLength % (60)}s`); + } + + console.log(gameLength); + + return ( + + + {startDate} + + + + {" "} + {teamName}/ + + + {!!gameLength.length && gameLength.join(' ')} + {!gameLength.length && '?'} + + + {myHeroPick && ( + <> + {myHeroPick.hero.substr(14)}/ + {randomText} + + )} + + + {Object.keys(matchData.heroPicks).length > 0 && ( + <> + {matchData.teams.radiant.map((steamid) => { + const pick = matchData.heroPicks[steamid]; + if (pick) { + return {pick.hero.substr(14)}/ + } + return null; + })} + {" vs "} + {matchData.teams.dire.map((steamid) => { + const pick = matchData.heroPicks[steamid]; + if (pick) { + return {pick.hero.substr(14)}/ + } + return null; + })} + + )} + + + ); +} diff --git a/src/components/routes.jsx b/src/components/routes.jsx index eccab53..03dbcf2 100644 --- a/src/components/routes.jsx +++ b/src/components/routes.jsx @@ -6,6 +6,7 @@ import Admin from "./pages/admin"; import Overview from "./pages/overview"; import ManageTeam from "./pages/manage-team"; import TopPlayers from "./pages/top-players"; +import MatchHistory from "./pages/match-history"; export default function Routes() { return ( @@ -19,6 +20,9 @@ export default function Routes() { + + + diff --git a/yarn.lock b/yarn.lock index f2c91f0..7776fe0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9452,6 +9452,11 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== +short-time-ago@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/short-time-ago/-/short-time-ago-2.0.0.tgz#3fde172e626999510c5ca6784aba568c964d50dc" + integrity sha512-klqvTBTPpU2xI/+qeTl3zMX6EVfcF7ddTfoaOg+aOpJY4IOhwwgxTQ2eu3sLDrSAQL0PwjFAoWqJUDUcJSEXXA== + signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"