-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user profile bans feature (#152)
- Loading branch information
1 parent
f9e5023
commit febcca6
Showing
6 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** @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 gridElement = select('#content-grid-element-6', parentElement); | ||
const parentOfGrid = gridElement.parentElement; | ||
|
||
if(select('#user-ban-info', parentOfGrid)){ | ||
return; | ||
} | ||
|
||
const grids = select.all('div.content-secondary', parentOfGrid); | ||
|
||
// copying the grid node with every react classname | ||
// in order not to break everything | ||
const banElement = grids[0].cloneNode(false); | ||
|
||
banElement.setAttribute('id', 'user-ban-info'); | ||
grids[0].append(banElement); | ||
|
||
if (banElement === null || banElement === undefined) { | ||
return | ||
} | ||
|
||
if (hasFeatureAttribute(FEATURE_ATTRIBUTE, banElement)) { | ||
return | ||
} | ||
|
||
setFeatureAttribute(FEATURE_ATTRIBUTE, banElement) | ||
|
||
const headerElement = ( | ||
<h3 className="heading-border"> | ||
<span translate="BANS">Bans</span> | ||
</h3> | ||
) | ||
|
||
const headerElementMissing = select('#content-grid-element-6', banElement) | ||
|
||
if (headerElementMissing === null || headerElementMissing === undefined) { | ||
banElement.append(headerElement) | ||
} | ||
|
||
const noBanElement = <div>No match bans yet</div> | ||
|
||
const nickname = getPlayerProfileNickname() | ||
const player = await getPlayer(nickname) | ||
|
||
const playerBans = await getPlayerBans(player.id) | ||
|
||
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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters