Skip to content

Commit

Permalink
More detail in tossup states.
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Aug 6, 2024
1 parent 26f26d9 commit 033fe0d
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions src/components/More.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const SelectionDetails: React.FC<{ result: StateSelectionResult }> = ({
}) => {
let message;
let marginMessage = null;
let otherMarginMessage = null;

switch (result.selection) {
case "home":
Expand Down Expand Up @@ -383,35 +384,79 @@ const SelectionDetails: React.FC<{ result: StateSelectionResult }> = ({
}

const election = ELECTION_2020[selectedState(result)];
const electionWinner = winner(election, CANDIDATES_2020);
const mp = marginPercent(election);
if (mp < 0.01) {
marginMessage = (
<>
In 2020,{" "}
<span className="font-black">{winner(election, CANDIDATES_2020)}</span>{" "}
won {selectedStateName(result)} by a razor-thin margin of{" "}
In 2020, <span className="font-black">{electionWinner}</span> won{" "}
{selectedStateName(result)} by a razor-thin margin of{" "}
{formatMargin(election)} votes.
</>
);
} else if (mp < 0.025) {
marginMessage = (
<>
In 2020,{" "}
<span className="font-black">{winner(election, CANDIDATES_2020)}</span>{" "}
won {selectedStateName(result)} by a slim margin of{" "}
{formatMargin(election)} votes.
In 2020, <span className="font-black">{electionWinner}</span> won{" "}
{selectedStateName(result)} by a slim margin of {formatMargin(election)}{" "}
votes.
</>
);
}

// Show the other state's margin if it's close too!
if (marginMessage && result.selection === "toss-up") {
const otherElection = ELECTION_2020[otherState(result)];
const otherElectionWinner = winner(otherElection, CANDIDATES_2020);
const otherIsSame = otherElectionWinner === electionWinner;
const otherMP = marginPercent(otherElection);
const otherMPSimilar =
(mp < 0.01 && otherMP < 0.01) ||
(mp >= 0.01 && mp < 0.025 && otherMP >= 0.01 && otherMP < 0.025);

if (otherMP < 0.01) {
otherMarginMessage = (
<>
{otherIsSame ? (
<>He also </>
) : (
<>
On the other hand,{" "}
<span className="font-black">{otherElectionWinner}</span>{" "}
</>
)}
won {otherStateName(result)} by a{" "}
{otherMPSimilar ? "similarly thin" : "razor-thin"} margin of{" "}
{formatMargin(otherElection)} votes.
</>
);
} else if (otherMP < 0.025) {
otherMarginMessage = (
<>
{otherIsSame ? (
<>He also </>
) : (
<>
On the other hand,{" "}
<span className="font-black">{otherElectionWinner}</span>{" "}
</>
)}
won {otherStateName(result)} by a{" "}
{otherMPSimilar ? "similarly slim" : "slim"} margin of{" "}
{formatMargin(otherElection)} votes.
</>
);
}
}

return (
<div className="font-satoshi font-medium py-4 text-[20px] leading-[30px]">
{message}
{marginMessage && (
<>
<br />
<br />
{marginMessage}
{marginMessage} {otherMarginMessage}
</>
)}
</div>
Expand Down

0 comments on commit 033fe0d

Please sign in to comment.