Skip to content

Commit

Permalink
refactor header component
Browse files Browse the repository at this point in the history
  • Loading branch information
silentDjay committed Nov 2, 2024
1 parent 48df829 commit e7c8588
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/GameplayMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const GameplayMap: React.FC<GameplayMapProps> = ({
const maxRadius = distanceFromTarget * 1000; // meters

const growthRate = 22000 / (map.getZoom() || 1); // Amount to increase the radius per interval (in meters)
const intervalRate = 5; // milliseconds
const intervalRate = 5;

const timeRequiredToFillCircle = (maxRadius / growthRate) * intervalRate;

Expand Down
11 changes: 3 additions & 8 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,20 @@ interface HeaderProps {
targetCountryData: Country;
gameCategory: GameCategory;
gameStatus: GameStatus;
distanceFromTarget?: number;
}

export const Header: React.FC<HeaderProps> = ({
clicks,
targetCountryData,
gameCategory,
gameStatus,
distanceFromTarget,
}) => {
const totalClickCount = clicks.length;
const clickCountOnLand = getNumberOfClicksOnLand(clicks);
const lastClickData = clicks[totalClickCount - 1];
const penultimateClickData = clicks[totalClickCount - 2];
const distanceFromTarget =
!!targetCountryData &&
!!lastClickData &&
getClickDistanceFromTarget(
targetCountryData.latlng,
lastClickData.coordinates
);
const previousClickDistance =
!!targetCountryData &&
!!penultimateClickData &&
Expand All @@ -50,7 +45,7 @@ export const Header: React.FC<HeaderProps> = ({
<span className="header-title">MAPSTERY</span>
{!!targetCountryData && (
<div className="header-gameplay-info">
{clicks?.length !== 0 && gameStatus === "INIT" && !!lastClickData ? (
{gameStatus === "INIT" && !!lastClickData ? (
<div style={{ display: "flex" }}>
<div>
<b>
Expand Down
5 changes: 2 additions & 3 deletions src/components/PlayGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export const PlayGame: React.FC = () => {
useState<google.maps.LatLng>();

useEffect(() => {
const totalClicks = clicks?.length;

const lastClickData = clicks[totalClicks - 1];
const lastClickData = clicks[clicks.length - 1];

if (!!lastClickData && !!targetCountryData) {
setLatestClickDistance(
Expand Down Expand Up @@ -275,6 +273,7 @@ export const PlayGame: React.FC = () => {
targetCountryData={targetCountryData}
gameCategory={gameCategory as GameCategory}
gameStatus={gameStatus}
distanceFromTarget={latestClickDistance}
/>
)}
<WelcomeModal
Expand Down

0 comments on commit e7c8588

Please sign in to comment.