diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1ed453a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{js,json,yml}] +charset = utf-8 +indent_style = space +indent_size = 2 diff --git a/.env.production b/.env.production deleted file mode 100644 index d742165..0000000 --- a/.env.production +++ /dev/null @@ -1 +0,0 @@ -VUE_APP_API_URL=https://api.csgow.tf \ No newline at end of file diff --git a/scss/custom.scss b/scss/custom.scss index 2c21edc..f0b28dd 100644 --- a/scss/custom.scss +++ b/scss/custom.scss @@ -27,9 +27,9 @@ $success: #609926; :root { // CSGO COLORS - --csgo-Orange: #FE9A28; - --csgo-Blue: #5BA7FE; - --csgo-Yellow: #F7F52F; - --csgo-Purple: #A01BEF; - --csgo-Green: #04B462; + --csgo-orange: #FE9A28; + --csgo-blue: #5BA7FE; + --csgo-yellow: #F7F52F; + --csgo-purple: #A01BEF; + --csgo-green: #04B462; } diff --git a/src/components/Nav.vue b/src/components/Nav.vue index 794f887..ff61fea 100644 --- a/src/components/Nav.vue +++ b/src/components/Nav.vue @@ -33,6 +33,9 @@ > Search! + @@ -44,18 +47,18 @@ import {reactive} from "vue"; import {useStore} from 'vuex' import {sanitize} from 'string-sanitizer' -import router from "../router"; -import {GoToLink} from '../utils' +import {GetUser, GoToLink, GoToPlayer} from '../utils' export default { name: 'Nav', setup() { const store = useStore() const data = reactive({ - searchInput: '' + searchInput: '', + error: '' }) - const parseSearch = () => { + const parseSearch = async () => { const input = data.searchInput const customUrlPattern = 'https://steamcommunity.com/id/' const profileUrlPattern = 'https://steamcommunity.com/profiles/' @@ -64,30 +67,42 @@ export default { store.state.id64 = '' store.state.vanityUrl = '' - if (id64Pattern.test(input)) { - store.state.id64 = input - } else if (input.match(customUrlPattern)) { - store.state.vanityUrl = sanitize(input.split('/')[4].split('?')[0]) - } else if (input.match(profileUrlPattern)) { - const tmp = input.split('/')[4].split('?')[0] - if (id64Pattern.test(tmp)) { - store.state.id64 = tmp + if (data.searchInput !== '') { + if (id64Pattern.test(input)) { + store.state.id64 = input + } else if (input.match(customUrlPattern)) { + store.state.vanityUrl = sanitize(input.split('/')[4].split('?')[0]) + } else if (input.match(profileUrlPattern)) { + const tmp = input.split('/')[4].split('?')[0] + if (id64Pattern.test(tmp)) { + store.state.id64 = tmp + } + } else { + store.state.vanityUrl = sanitize(input) } - } else { - store.state.vanityUrl = sanitize(input) - } - if (store.state.id64 !== '' || store.state.vanityUrl !== '') { - data.searchInput = '' + if (store.state.id64 !== '' || store.state.vanityUrl !== '') { + const [res, resData] = await GetUser(store.state.vanityUrl || store.state.id64) - if (store.state.id64) { - router.push(`/player/${store.state.id64}`) - } else if (store.state.vanityUrl) { - router.push(`/player/${store.state.vanityUrl}`) + if (res === 200) { + data.searchInput = '' + document.activeElement.blur() + + if (resData.vanity_url) { + GoToPlayer(resData.vanity_url) + } else if (resData.steamid64) { + GoToPlayer(resData.steamid64) + } + } else if (res === 404) { + data.searchInput = '' + data.error = `${resData} - Try again` + + setTimeout(() => { + data.error = '' + }, 5000) + } } } - - document.activeElement.blur() } return { @@ -111,10 +126,15 @@ nav { li { font-size: 1.5rem; font-weight: lighter; - margin: 22px 10px 0 10px; + margin: 22px 0 0 10px; cursor: pointer; transition: 100ms ease-in-out; + .text-up { + font-size: 40%; + vertical-align: top; + } + &:first-child { font-size: 2rem; font-weight: bold; @@ -122,41 +142,46 @@ nav { margin-left: 0; } - &:hover { + &:hover router-link { color: var(--bs-info); transition: 100ms ease-in-out; } } } - .text-up { - font-size: 40%; - vertical-align: top; - } + form { + position: relative; - svg { - width: 24px; - height: 24px; - fill: currentColor; - } - - label { - padding-top: 6px; - font-size: 1.4rem; - } - - input[type="search"] { - min-width: 300px; - max-width: 300px; - - &:focus { - box-shadow: 0 4px 2px -2px rgba(95, 120, 146, 0.59); - transition: .2s ease-in-out; - transform: scale(.975); + svg { + width: 24px; + height: 24px; + fill: currentColor; } - &::placeholder { - color: #aaa; + label { + padding-top: 6px; + font-size: 1.4rem; + } + + input[type="search"] { + min-width: 300px; + max-width: 300px; + + &:focus { + box-shadow: 0 4px 2px -2px rgba(95, 120, 146, 0.59); + transition: .2s ease-in-out; + transform: scale(.975); + } + + &::placeholder { + color: #aaa; + } + } + + .alert { + position: absolute; + right: 0; + top: 55px; } } } @@ -179,7 +204,6 @@ nav { } #mainNav { - ul { display: flex; flex-direction: column; @@ -225,4 +249,4 @@ nav { } } } - \ No newline at end of file + diff --git a/src/components/ScoreTeamPlayer.vue b/src/components/ScoreTeamPlayer.vue index b174d51..60c45aa 100644 --- a/src/components/ScoreTeamPlayer.vue +++ b/src/components/ScoreTeamPlayer.vue @@ -161,7 +161,11 @@ export default { \ No newline at end of file + diff --git a/src/router/index.js b/src/router/index.js index 49a7931..96d4703 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -16,12 +16,6 @@ const routes = [ component: lazyLoad('Player'), props: true }, - { - path: '/player/:id/matches', - name: 'MyMatches', - component: lazyLoad('MyMatches'), - props: true - }, { path: '/match/:match_id', name: 'Match', diff --git a/src/store/index.js b/src/store/index.js index 44ac28c..348d6bd 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,7 +3,7 @@ import { createStore } from 'vuex' export default createStore({ state: { id64: '', - vanityUrl: '' + vanityUrl: '', }, mutations: { }, diff --git a/src/utils/ApiRequests.js b/src/utils/ApiRequests.js new file mode 100644 index 0000000..f06fc6b --- /dev/null +++ b/src/utils/ApiRequests.js @@ -0,0 +1,19 @@ +import axios from "axios"; + +export const GetUser = async (id) => { + try { + const res = await axios.get(`${process.env.VUE_APP_API_URL}/player/${id}`) + + if (res.status === 200) { + return [200, res.data] + } + } catch (err) { + if (err.response) { + if (err.response.status === 404) { + return [404, 'Player not found'] + } + } else { + console.log(err.response) + } + } +} diff --git a/src/utils/Display.js b/src/utils/Display.js index 0e2a383..0e461fe 100644 --- a/src/utils/Display.js +++ b/src/utils/Display.js @@ -28,7 +28,9 @@ export const LoadImage = (mapName) => { let background = document.querySelector('.bg-img') img.onload = function() { + if (background) { background.src = img.src + } } img.onerror = function () { diff --git a/src/utils/GoTo.js b/src/utils/GoTo.js index e32ac8d..0fc982b 100644 --- a/src/utils/GoTo.js +++ b/src/utils/GoTo.js @@ -1,13 +1,13 @@ import router from "../router"; export const GoToMatch = (id) => { - router.push(`/match/${id}`) + router.push({name: 'Match', params: {match_id: id}}) } export const GoToPlayer = (id) => { - router.push(`/player/${id}`) + router.push({name: 'Player', params: {id: id}}) } export const GoToLink = (link) => { router.push(`${link}`) -} \ No newline at end of file +} diff --git a/src/utils/Utils.js b/src/utils/Utils.js new file mode 100644 index 0000000..36ebdc8 --- /dev/null +++ b/src/utils/Utils.js @@ -0,0 +1,52 @@ +import axios from "axios"; + +export const GetWinLoss = (matchResult, teamId) => { + if (matchResult === teamId) { + return 'win' + } else if (matchResult === 0) { + return 'draw' + } else { + return 'loss' + } +} + +export const TrackMe = async (id64, authcode, sharecode) => { + let statusError = '' + let status = 200 + + const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/ + const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/ + + if (!shareCodeRegex.test(sharecode)) { + statusError = 'Is not a valid sharecode' + status = 418 + return [status, statusError] + } + if (!authCodeRegex.test(authcode)) { + statusError = 'Is not a valid authcode' + status = 418 + return [status, statusError] + } + + try { + const res = await axios + .post(`${process.env.VUE_APP_API_URL}/player/trackme`, `id=${id64}&authcode=${authcode}&sharecode=${sharecode}`) + + if (res.status === 202) { + statusError = 'Hurray!! Your Matches will now be tracked!' + status = res.status + } + } catch (err) { + if (err.response.status === 401) { + statusError = 'Data does not match player' + status = err.response.status + } else if (err.response.status === 400) { + statusError = 'Userinput was wrong' + status = err.response.status + } else { + console.log(`${err.response.status}: ${err.response.statusText}`) + } + } + + return [status, statusError] +} diff --git a/src/utils/index.js b/src/utils/index.js index a8a9aad..fe54acf 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,13 +1,17 @@ import {FormatDate, FormatDuration, FormatFullDate, FormatFullDuration} from "./DateTime"; -import {GoToMatch, GoToPlayer, GoToLink} from "./GoTo"; +import {GoToLink, GoToMatch, GoToPlayer} from "./GoTo"; import {SaveLastVisitedToLocalStorage} from "./LocalStorage"; import {GetHLTV_1} from "./HLTV"; import {DisplayRank, LoadImage} from "./Display"; +import {GetUser} from "./ApiRequests"; +import {GetWinLoss, TrackMe} from "./Utils"; export { - FormatDate, FormatFullDuration, FormatFullDate, FormatDuration, - GoToMatch, GoToPlayer, GoToLink, - SaveLastVisitedToLocalStorage, - GetHLTV_1, - DisplayRank, LoadImage -} \ No newline at end of file + FormatDate, FormatFullDuration, FormatFullDate, FormatDuration, + GoToMatch, GoToPlayer, GoToLink, + SaveLastVisitedToLocalStorage, + GetHLTV_1, + DisplayRank, LoadImage, + GetUser, + GetWinLoss, TrackMe +} diff --git a/src/views/MyMatches.vue b/src/views/MyMatches.vue deleted file mode 100644 index 8a359e2..0000000 --- a/src/views/MyMatches.vue +++ /dev/null @@ -1,12 +0,0 @@ - - - \ No newline at end of file diff --git a/src/views/Player.vue b/src/views/Player.vue index 73b5ee2..ad97bf6 100644 --- a/src/views/Player.vue +++ b/src/views/Player.vue @@ -44,6 +44,17 @@ + + +