Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/follow-redirects-1.15.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Shebuka authored Mar 19, 2024
2 parents 500971c + 3f8f912 commit ffe665d
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Footer() {
<h3>{t('Item Data')}</h3>
<p>
{t(
'Fresh EFT data and player name searching courtesy of',
'Fresh EFT data courtesy of',
)}{' '}
<a href="https://tarkov-changes.com" target="_blank" rel="noopener noreferrer">
<span>Tarkov-Changes</span>
Expand Down
84 changes: 84 additions & 0 deletions src/data/maps.json
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,90 @@
"top": 2,
"bottom": -0.8,
"size": 90
},
{
"position": [-260, -364],
"text": "Administrative Office",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-254, -320],
"text": "Security Office",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-244, -378],
"text": "Security #1",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-215, -379],
"text": "Security #2",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-229, -343],
"text": "Conference Room",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-219, -302],
"text": "Cafeteria",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-189, -401],
"text": "Offices #1",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-149, -401],
"text": "Offices #2",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-130, -401],
"text": "Infirmary Lvl 2",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-130, -361],
"text": "Sterile Laboratory",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-169, -288],
"text": "Control Room",
"top": 1000,
"bottom": 3,
"size": 90
},
{
"position": [-250, -281],
"text": "Corridor To Building #2",
"top": 1000,
"bottom": 3,
"size": 90
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions src/pages/player/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ ul.favorite-item-list li {
.legendary {
color: #ffe084;
}

.banned {
color: #cd1e2f;
}
50 changes: 44 additions & 6 deletions src/pages/player/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
mdiBagPersonal,
mdiArmFlex,
mdiStarBox,
mdiTrophyAward
mdiTrophyAward,
mdiAccountSearch,
} from '@mdi/js';
import { TreeView, TreeItem } from '@mui/x-tree-view';

Expand Down Expand Up @@ -114,21 +115,33 @@ function Player() {
}
return;
} catch (error) {
if (error.message.includes('NetworkError')) {
setProfileError('Rate limited exceeded. Wait one minute to send another request.');
}
console.log('Error retrieving player profile', error);
}
}
try {
const response = await fetch('https://player.tarkov.dev/account/'+accountId);
if (response.status !== 200) {
if (response.status === 429) {
setProfileError(`Rate limited exceeded. Wait ${response.headers.get('Retry-After')} seconds to send another request`);
}
return;
}
const profileResponse = await response.json();
if (profileResponse.err) {
setProfileError(profileResponse.errmsg);
return;
}
if (response.status !== 200) {
return;
}
setPlayerData(profileResponse);
} catch (error) {
if (error.message.includes('NetworkError')) {
setProfileError('Rate limited exceeded. Wait one minute to send another request.');
}
console.log('Error retrieving player profile', error);
}
}
Expand Down Expand Up @@ -165,6 +178,16 @@ function Player() {
});
}, [playerData, playerLevel, t]);

const bannedMessage = useMemo(() => {
if (!playerData?.info?.bannedState) {
return false;
}
if (playerData.info.bannedUntil < 0) {
return t('Banned Permanently');
}
return t('Banned until {{banLiftDate}}', {banLiftDate: new Date(playerData.info.bannedUntil * 1000).toLocaleString()});
}, [playerData, t]);

const achievementColumns = useMemo(
() => [
{
Expand Down Expand Up @@ -645,28 +668,43 @@ function Player() {
])
}, [playerData, getItemDisplay, getLoadoutContents, t]);

const playerSearchDiv = (
<div>
<p>
<Link to="/players"><Icon path={mdiAccountSearch} size={1} className="icon-with-text"/>{t('Search different player')}</Link>
</p>
</div>
);

if (profileError) {
return (
<div className={'page-wrapper'} key="player-page-wrapper">
<h2>{profileError}</h2>
{playerSearchDiv}
</div>
);
}

return [
<SEO
title={`${t('Player Profile')} - ${t('Escape from Tarkov')} - ${t('Tarkov.dev')}`}
description={t('player-page-description', 'View player profile.')}
key="seo-wrapper"
/>,
<div className={'page-wrapper'} key="player-page-wrapper">
{playerSearchDiv}
<div className="player-headline-wrapper" key="player-headline">
<h1 className="player-page-title">
<Icon path={mdiAccountDetails} size={1.5} className="icon-with-text"/>
{pageTitle}
</h1>
</div>
<div>
{profileError && (
<p>{profileError}</p>
)}
{playerData.info.registrationDate !== 0 && (
<p>{`${t('Started current wipe')}: ${new Date(playerData.info.registrationDate * 1000).toLocaleString()}`}</p>
)}
{playerData.info.bannedState && (
<p>{t('Banned')}</p>
{!!bannedMessage && (
<p className="banned">{bannedMessage}</p>
)}
{totalSecondsInGame > 0 && (
<p>{`${t('Total account time in game')}: ${(() => {
Expand Down
45 changes: 38 additions & 7 deletions src/pages/players/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useState, useCallback, useMemo } from 'react';
import { useState, useCallback, useMemo, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';

import { Icon } from '@mdi/react';
import { mdiAccountSearch } from '@mdi/js';

import useKeyPress from '../../hooks/useKeyPress.jsx';

import SEO from '../../components/SEO.jsx';
import { InputFilter } from '../../components/filter/index.js';

Expand All @@ -13,11 +15,14 @@ import './index.css';
function Players() {
const { t } = useTranslation();

const enterPress = useKeyPress('Enter');

const defaultQuery = new URLSearchParams(window.location.search).get(
'search',
);
const [nameFilter, setNameFilter] = useState(defaultQuery || '');
const [nameResults, setNameResults] = useState([]);
const [nameResultsError, setNameResultsError] = useState(false);

const [isButtonDisabled, setButtonDisabled] = useState(true);
const [searched, setSearched] = useState(false);
Expand All @@ -27,25 +32,40 @@ function Players() {
return;
}
try {
setNameResultsError(false);
setButtonDisabled(true);
const response = await fetch('https://player.tarkov.dev/name/'+nameFilter);
if (response.status !== 200) {
return;
let errorMessage = await response.text();
try {
const json = JSON.parse(errorMessage);
errorMessage = json.errmsg;
} catch {}
throw new Error(errorMessage);
}
setButtonDisabled(false);
setSearched(true);
setNameResults(await response.json());
} catch (error) {
setNameResults(['Error searching player profile: ' + error]);
let message = error.message;
if (message.includes('NetworkError')) {
message = 'Rate limited exceeded. Wait one minute to send another request.';
}
if (message.includes('Malformed')) {
message = 'Error searching player profile; try removing one character from the end until the search works.'
}
setSearched(false);
setNameResults([]);
setNameResultsError(message);
}
}, [nameFilter, setNameResults]);
setButtonDisabled(false);
}, [nameFilter, setNameResults, setNameResultsError]);

const searchResults = useMemo(() => {
if (!searched) {
return '';
}
if (nameResults.length < 1) {
return 'No players with this name';
return 'No players with this name. Note: banned players do not show up in name searches.';
}
let morePlayers = '';
if (nameResults.length >= 5) {
Expand All @@ -71,6 +91,12 @@ function Players() {
searchForName();
}

useEffect(() => {
if (enterPress) {
searchForName();
}
}, [enterPress, searchForName]);

return [
<SEO
title={`${t('Players')} - ${t('Escape from Tarkov')} - ${t('Tarkov.dev')}`}
Expand Down Expand Up @@ -105,7 +131,12 @@ function Players() {
/>
<button className="search-button" onClick={searchForName} disabled={isButtonDisabled}>{t('Search')}</button>
</div>
{searchResults}
{!!nameResultsError && (
<div>
<p>{`${t('Search error')}: ${nameResultsError}`}</p>
</div>
)}
{!nameResultsError && searchResults}
</div>,
];
}
Expand Down
Loading

0 comments on commit ffe665d

Please sign in to comment.