Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Added last 20 queue bans for profile #93

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/content/components/player-bans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @jsx h */
import { h } from 'dom-chef'
import { formatDistance, parseISO } from 'date-fns'

export default ({ banStart, banEnd, expired, reason }) => {
const isActive = !expired
const className = isActive ? 'text-success' : 'text-danger'

return (
<span
className={className}
style={{
cursor: 'help'
}}
title={banStart}
>
<span style={{ float: 'right' }}>[{reason}]</span>
{formatDistance(parseISO(banEnd), new Date(), { addSuffix: true })}
</span>
)
}
58 changes: 58 additions & 0 deletions src/content/features/add-player-profile-ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @jsx h */
import { h } from 'dom-chef'
import select from 'select-dom'

import {
hasFeatureAttribute,
setFeatureAttribute
} from '../helpers/dom-element'

import createPlayerBansElement from '../components/player-bans'
import { getPlayerProfileNickname } from '../helpers/player-profile'
import { getPlayer, getPlayerBans } from '../helpers/faceit-api'

const FEATURE_ATTRIBUTE = 'profile-bans'

export default async parentElement => {
const banElement = select('profile-overview-bans', parentElement)

if (banElement === null) {
return
}

if (hasFeatureAttribute(FEATURE_ATTRIBUTE, banElement)) {
return
}

setFeatureAttribute(FEATURE_ATTRIBUTE, banElement)

const headerElement = (
<h3 className="heading-border">
<span translate="BANS">Bans</span>
</h3>
)

const noBanElement = <div>No match bans yet</div>

const nickname = getPlayerProfileNickname()
const { guid } = await getPlayer(nickname)

const playerBans = await getPlayerBans(guid)

if (playerBans.length === 0) {
banElement.append(noBanElement)
}

playerBans.forEach(async ban => {
const playerBansElement = createPlayerBansElement(ban)

const banWrapper = <div className="mb-sm">{playerBansElement}</div>

banElement.append(banWrapper)
})

const headerElementMissing = select('h3.heading-border', parentElement)
if (headerElementMissing === null) {
banElement.insertBefore(headerElement, banElement.firstChild)
}
}
9 changes: 9 additions & 0 deletions src/content/helpers/faceit-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,12 @@ export const getPlayerHistory = async (userId, page = 0) => {

export const getMatchmakingQueue = queueId =>
fetchApiMemoized(`/queue/v1/queue/matchmaking/${queueId}`)

export const getPlayerBans = async userId => {
const limit = 20
const offset = 0

return fetchApiMemoized(
`/queue/v1/ban?userId=${userId}&organizerId=faceit&offset=${offset}&limit=${limit}`
)
}
3 changes: 3 additions & 0 deletions src/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import addPlayerProfileLevelProgress from './features/add-player-profile-level-p
import addPlayerProfileMatchesDemo from './features/add-player-profile-matches-demo'
import addPlayerProfileExtendedStats from './features/add-player-profile-extended-stats'
import addPlayerProfileBadge from './features/add-player-profile-badge'
import addPlayerProfileBan from './features/add-player-profile-ban'
import clickModalClose from './features/click-modal-close'
import getBannedUser from './helpers/get-banned-user'
import stopToxicity from './features/stop-toxicity'
Expand Down Expand Up @@ -91,6 +92,7 @@ function observeBody() {
} else if (modals.isPlayerProfile()) {
addPlayerProfileBadge(modalElement)
addPlayerProfileLinks(modalElement)
addPlayerProfileBan(modalElement)

if (modals.isPlayerProfileStats()) {
debouncedPlayerProfileStatsFeatures(modalElement)
Expand Down Expand Up @@ -139,6 +141,7 @@ function observeBody() {
} else if (pages.isPlayerProfile()) {
addPlayerProfileBadge(mainContentElement)
addPlayerProfileLinks(mainContentElement)
addPlayerProfileBan(mainContentElement)

if (pages.isPlayerProfileStats()) {
debouncedPlayerProfileStatsFeatures(mainContentElement)
Expand Down