diff --git a/src/utils/ApiRequests.js b/src/utils/ApiRequests.js index 69cd55e..2d90775 100644 --- a/src/utils/ApiRequests.js +++ b/src/utils/ApiRequests.js @@ -15,14 +15,14 @@ export const GetUser = async (id) => { } } -export const TrackMe = async (id64, authcode, sharecode) => { +export const TrackMe = async (id64, authcode, sharecode = '') => { let statusError = '' let status = 202 const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/ const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/ - if (sharecode && !shareCodeRegex.test(sharecode)) { + if (sharecode !== '' && !shareCodeRegex.test(sharecode)) { statusError = 'Is not a valid sharecode' status = 418 return [status, statusError] @@ -67,9 +67,35 @@ export const getPlayerValue = async (match_id) => { } } -export const loadMoreMatches = async (player_id, date) => { +export const getMatchDetails = async (match_id) => { try { - const res = await axios.get(`${API_URL}/player/${player_id}/after/${date}`) + const res = await axios.get(`${API_URL}/match/${match_id}`) + + if (res.status === 200) { + return res.data + } + } catch (err) { + // TODO: 400, 404 + console.log(err.response.status, err.response.statusText) + } +} + +export const loadMoreMatches = async (player_id, date) => { + try { + const res = await axios.get(`${API_URL}/player/${player_id}/next/${date}`) + + if (res.status === 200) { + return res.data + } + } catch (err) { + // TODO: 400, 404 + console.log(err.response.status, err.response.statusText) + } +} + +export const getPlayerMeta = async (player_id, limit = 4) => { + try { + const res = await axios.get(`${API_URL}/player/${player_id}/meta/${limit}`) if (res.status === 200) { return res.data diff --git a/src/utils/index.js b/src/utils/index.js index b4d7185..842d0ae 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -3,7 +3,7 @@ import {GoToLink, GoToMatch, GoToPlayer} from "./GoTo"; import {SaveLastVisitedToLocalStorage} from "./LocalStorage"; import {GetHLTV_1} from "./HLTV"; import {DisplayRank, LoadImage} from "./Display"; -import {GetUser, TrackMe, getPlayerValue, loadMoreMatches} from "./ApiRequests"; +import {GetUser, TrackMe, getPlayerValue, loadMoreMatches, getPlayerMeta, getMatchDetails} from "./ApiRequests"; import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav} from "./Utils"; export { @@ -12,6 +12,6 @@ export { SaveLastVisitedToLocalStorage, GetHLTV_1, DisplayRank, LoadImage, - GetUser, TrackMe, getPlayerValue, loadMoreMatches, + GetUser, TrackMe, getPlayerValue, loadMoreMatches, getPlayerMeta, getMatchDetails, setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav } diff --git a/src/views/Match.vue b/src/views/Match.vue index 551d629..bf1e548 100644 --- a/src/views/Match.vue +++ b/src/views/Match.vue @@ -122,7 +122,8 @@ import { FormatFullDate, GetAvgRank, GoToLink, - LoadImage + LoadImage, + getMatchDetails } from "../utils"; import {useStore} from "vuex"; import {useRoute} from 'vue-router' @@ -146,36 +147,31 @@ export default { }) // Functions - const GetMatch = () => { - if (matchIdPattern.test(props.match_id)) - axios - .get(`${process.env.VUE_APP_API_URL}/match/${props.match_id}`) - .then((response) => { - if (response.data.map) - document.title = `${FixMapName(response.data.map)} | csgoWTF` - else - document.title = `Match-Details | csgoWTF` + const GetMatch = async () => { + let res = {} + if (matchIdPattern.test(props.match_id)) { + res = await getMatchDetails(props.match_id) - store.commit({ - type: 'changeMatchDetails', - data: response.data - }) + if (res.map) + document.title = `${FixMapName(res.map)} | csgoWTF` + else + document.title = `Match-Details | csgoWTF` - data.matchDetails = store.state.matchDetails - data.stats = data.matchDetails.stats - data.score = data.matchDetails.score + store.commit({ + type: 'changeMatchDetails', + data: res + }) - LoadImage(data.matchDetails.map ? data.matchDetails.map : 'random') + data.matchDetails = store.state.matchDetails + data.stats = data.matchDetails.stats + data.score = data.matchDetails.score - data.avgRank = GetAvgRank(data.stats) + LoadImage(data.matchDetails.map ? data.matchDetails.map : 'random') - console.log(data.matchDetails) - }) - .catch((e) => { - console.log(e) - // TODO: needs 404 - }) - else { + data.avgRank = GetAvgRank(data.stats) + + console.log(data.matchDetails) + } else { console.log('Match not found') // TODO: needs 404 } diff --git a/src/views/Player.vue b/src/views/Player.vue index 5395d01..b7aec4a 100644 --- a/src/views/Player.vue +++ b/src/views/Player.vue @@ -222,10 +222,9 @@
  • Mate 2
  • Mate 3
  • Mate 4
  • -
  • Mate 5
  • -
    +
    Most played with
    @@ -235,10 +234,9 @@
  • Player 2
  • Player 3
  • Player 4
  • -
  • Player 5
  • -
    +
    Preferred Weapons
    @@ -248,7 +246,18 @@
  • Weapon 2
  • Weapon 3
  • Weapon 4
  • -
  • Weapon 5
  • + +
    +
    +
    +
    Best Map
    +
    +
    +
      +
    • Map 1
    • +
    • Map 2
    • +
    • Map 3
    • +
    • Map 4
    @@ -595,7 +604,10 @@ export default { border-radius: 5px; } - .best-mate { + .best-mate, + .preferred-weapons, + .most-played-with, + .best-map { .heading { display: flex; align-items: center;