Skip to content

Commit ef9facd

Browse files
Content tags point player, team or game if applicable
1 parent 096adf4 commit ef9facd

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

src/app/components/ContentTag.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import { PropTypes } from 'prop-types';
3+
import Link from 'next/link';
4+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5+
import { faHockeyPuck, faPeopleGroup, faTag, faUser } from '@fortawesome/free-solid-svg-icons';
6+
7+
const ContentTag = ({ tag }) => {
8+
let url = `/news/topic/${tag.slug}`;
9+
let icon = faTag;
10+
11+
if (tag.externalSourceName === 'player') {
12+
url = `/player/${tag.extraData.playerId}`;
13+
icon = faUser;
14+
}
15+
16+
if (tag.externalSourceName === 'team') {
17+
url = `/team/${tag.extraData.abbreviation}`;
18+
icon = faPeopleGroup;
19+
}
20+
21+
if (tag.externalSourceName === 'game') {
22+
url = `/game/${tag.extraData.gameId}`;
23+
icon = faHockeyPuck;
24+
}
25+
26+
return (
27+
<Link href={url} key={tag._entityId} className="inline-block rounded p-1 border text-xs m-1">
28+
<FontAwesomeIcon icon={icon} fixedWidth className="mr-1" /> {tag.title}
29+
</Link>
30+
);
31+
};
32+
33+
ContentTag.propTypes = {
34+
tag: PropTypes.shape({
35+
_entityId: PropTypes.string.isRequired,
36+
extraData: PropTypes.object,
37+
externalSourceName: PropTypes.string,
38+
slug: PropTypes.string.isRequired,
39+
title: PropTypes.string.isRequired,
40+
}).isRequired,
41+
};
42+
43+
export default ContentTag;

src/app/contexts/StoryContext.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const fetchGameData = async (gameId) => {
4848
export const StoryProvider = ({ storyId, children }) => {
4949
const [story, setStory] = useState({});
5050
const [game, setGame] = useState({});
51+
const [players, setPlayers] = useState([]);
5152
const [sidebarStories, setSidebarStories] = useState([]);
5253
const [pageError, setPageError] = useState(null);
5354

@@ -70,6 +71,11 @@ export const StoryProvider = ({ storyId, children }) => {
7071
setGame(gameResponse);
7172
}
7273

74+
const playerTags = storyResponse.tags.filter((t) => t.externalSourceName === 'player');
75+
if (playerTags.length) {
76+
setPlayers(playerTags);
77+
}
78+
7379
setSidebarStories(topStories);
7480
setStory(storyResponse);
7581

@@ -85,7 +91,7 @@ export const StoryProvider = ({ storyId, children }) => {
8591
}, [storyId]); // only re-run if story/storyId changes
8692

8793
return (
88-
<StoryContext.Provider value={{ story, game, sidebarStories, pageError }}>
94+
<StoryContext.Provider value={{ story, game, players, sidebarStories, pageError }}>
8995
{children}
9096
</StoryContext.Provider>
9197
);

src/app/news/[slug]/page.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import React from 'react';
44
import { notFound } from 'next/navigation';
5-
import Link from 'next/link';
65
import { useStoryContext } from '@/app/contexts/StoryContext';
76
import GameBodySkeleton from '@/app/components/GameBodySkeleton';
87
import ContentPhoto from '@/app/components/ContentPhoto';
@@ -11,6 +10,7 @@ import ContentExternal from '@/app/components/ContentExternal';
1110
import ContentMarkdown from '@/app/components/ContentMarkdown';
1211
import ContentByline from '@/app/components/ContentByline';
1312
import PageError from '@/app/components/PageError';
13+
import ContentTag from '@/app/components/ContentTag';
1414

1515
const NewsArticle = () => {
1616
const { story, pageError } = useStoryContext();
@@ -80,9 +80,7 @@ const NewsArticle = () => {
8080
Tags:
8181
</span>
8282
{story.tags.filter((t) => !t.extraData?.hideOnSite).map((tag) => (
83-
<Link href={`/news/topic/${tag.slug}`} key={tag._entityId} className="inline-block rounded p-1 border text-xs m-1">
84-
{tag.title}
85-
</Link>
83+
<ContentTag tag={tag} key={tag._entityId} />
8684
))}
8785
</div>
8886
</div>

src/app/player/[id]/page.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import StoryCard from '@/app/components/StoryCard';
1717
import PlayerDropdown from '@/app/components/PlayerDropdown';
1818
import '@/app/components/StatsTable.scss';
1919
import ContentCustomEntity from '@/app/components/ContentCustomEntity';
20+
import { STAT_CONTEXT } from '@/app/utils/constants';
2021

2122
export default function PlayerPage() {
2223
const { id } = useParams();
@@ -101,7 +102,7 @@ export default function PlayerPage() {
101102

102103
const statHeaders = [
103104
{ key: 'gamesPlayed', label: 'GP', title: 'Games Played' },
104-
{ key: 'gamesStarted', label: 'GS', title: 'Games Started' },
105+
{ key: 'gamesStarted', label: 'GS', title: 'Games Started', unit: 'start' },
105106
{ key: 'decision', label: 'D', title: 'Decision' },
106107
{ key: 'wins', label: 'W', title: 'Wins' },
107108
{ key: 'losses', label: 'L', title: 'Losses' },
@@ -389,7 +390,7 @@ export default function PlayerPage() {
389390

390391
{last5Games && (
391392
<div className="my-5">
392-
<div className="text-3xl font-bold my-3">Last Five Games</div>
393+
<div className="text-3xl font-bold my-3">{STAT_CONTEXT['last_5_games']}</div>
393394
<div className="overflow-x-auto">
394395
<table className="text-sm w-full">
395396
<thead>
@@ -428,13 +429,13 @@ export default function PlayerPage() {
428429
</div>
429430
</td>
430431
{statHeaders.map(
431-
({ key, altKey, precision }) =>
432+
({ key, altKey, precision, unit }) =>
432433
(Object.keys(last5Games[0]).includes(key) || (altKey && Object.keys(last5Games[0]).includes(altKey))) && (
433434
<td key={key} className="p-2 border text-center text-xs">
434435
{g[key] !== undefined ? (
435-
<>{formatStat(g[key], precision)}</>
436+
<>{formatStat(g[key], precision, unit)}</>
436437
) : (
437-
<>{formatStat(g[altKey], precision)}</>
438+
<>{formatStat(g[altKey], precision, unit)}</>
438439
)}
439440
</td>
440441
)

src/app/utils/formatters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export const formatLocalizedTime = (timeString) => {
4646
};
4747

4848
export const formatStat = (value, precision, unit) => {
49+
if (unit === 'start') {
50+
return value ? 'Yes' : 'No';
51+
}
52+
4953
if (unit === 'time') {
5054
return formatSecondsToGameTime(value);
5155
}

0 commit comments

Comments
 (0)