-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Teams page roster information (#84)
* Fixed column sizes on smaller devices * Added teams rosters player elo's and extra info * Added option to opt out * Removed useless setting of className to undefined
- Loading branch information
Showing
10 changed files
with
144 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** @jsx h */ | ||
import { h } from 'dom-chef' | ||
import select from 'select-dom' | ||
import { | ||
hasFeatureAttribute, | ||
setFeatureAttribute | ||
} from '../helpers/dom-element' | ||
import { getPlayer, getTeam } from '../helpers/faceit-api' | ||
import { | ||
getTeamMemberPlayerElements, | ||
getTeamMemberNicknameElement, | ||
getTeamId | ||
} from '../helpers/team-page' | ||
import createFlagElement from '../components/flag' | ||
import { getPlayerBadges } from '../helpers/player-badges' | ||
import createFeaturedPlayerBadgeElement from '../components/player-badge' | ||
import createEloElement from '../components/elo' | ||
import createSkillLevelElement from '../components/skill-level' | ||
|
||
const FEATURE_ATTRIBUTE = 'team-player-stats' | ||
|
||
export default async parentElement => { | ||
const teamId = getTeamId() | ||
|
||
const team = await getTeam(teamId) | ||
|
||
if (!team) { | ||
return | ||
} | ||
|
||
const memberElements = getTeamMemberPlayerElements(parentElement) | ||
|
||
const badges = await getPlayerBadges(team.members.map(({ guid }) => guid)) | ||
|
||
memberElements.forEach(async memberElement => { | ||
if (hasFeatureAttribute(FEATURE_ATTRIBUTE, memberElement)) { | ||
return | ||
} | ||
|
||
setFeatureAttribute(FEATURE_ATTRIBUTE, memberElement) | ||
|
||
const nicknameElement = getTeamMemberNicknameElement(memberElement) | ||
const nickname = nicknameElement.textContent | ||
|
||
const player = await getPlayer(nickname) | ||
|
||
if (!player) { | ||
return | ||
} | ||
|
||
const { country, guid, csgoName, games, csgoSkillLevel } = player | ||
|
||
const memberDetailsElement = select('.users-list__details', memberElement) | ||
|
||
if (badges[guid]) { | ||
const featuredPlayerBadgeElement = createFeaturedPlayerBadgeElement( | ||
badges[guid] | ||
) | ||
|
||
memberDetailsElement.insertAdjacentElement( | ||
'afterbegin', | ||
<div style={{ 'margin-bottom': 2 }}>{featuredPlayerBadgeElement}</div> | ||
) | ||
} | ||
|
||
if (csgoName) { | ||
memberDetailsElement.appendChild( | ||
<span className="text-muted" style={{ display: 'block' }}> | ||
{csgoName} | ||
</span> | ||
) | ||
} | ||
|
||
if (games && games.csgo) { | ||
const elo = games.csgo.faceitElo || '–' | ||
|
||
memberElement.children[0].appendChild( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexShrink: 0 | ||
}} | ||
> | ||
{createEloElement({ | ||
elo, | ||
className: 'text-muted text-md', | ||
alignRight: true, | ||
style: { 'margin-right': 4 } | ||
})} | ||
{createSkillLevelElement({ level: csgoSkillLevel || 0 })} | ||
</div> | ||
) | ||
} | ||
|
||
const flagElement = createFlagElement({ country }) | ||
nicknameElement.prepend(flagElement) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import select from 'select-dom' | ||
import { getCurrentPath } from './location' | ||
|
||
export const getTeamId = path => { | ||
const match = /teams\/([0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+(?:-[0-9a-z]+)?)/.exec( | ||
path || getCurrentPath() | ||
) | ||
|
||
return match && match[1] | ||
} | ||
|
||
export const getTeamMemberPlayerElements = parent => | ||
select.all('ul.users-list > li', parent) | ||
|
||
export const getTeamMemberNicknameElement = parent => | ||
select('strong[ng-bind="member.nickname"]', parent) |
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