From 2e1f63c5f2cdb03ae3250d9d408b7cc0588a8302 Mon Sep 17 00:00:00 2001 From: Mrmaxmeier Date: Tue, 15 Nov 2022 14:36:42 +0100 Subject: [PATCH] more cleanup --- src/PartyContext.tsx | 3 +-- src/PartyPage.tsx | 51 ++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/PartyContext.tsx b/src/PartyContext.tsx index d0b5431..030d3ad 100644 --- a/src/PartyContext.tsx +++ b/src/PartyContext.tsx @@ -41,8 +41,7 @@ export const PartyContextProvider: React.FC<{ children: React.ReactNode }> = (pr const [partyContext, setPartyContext] = useState(); const apiEndpoint = useMemo(() => { - // eslint-disable-next-line no-restricted-globals - const href = location.href; + const href = window.location.href; const p = parseURI(href); if (!p) return { partyName: "error", token: "" } return p; diff --git a/src/PartyPage.tsx b/src/PartyPage.tsx index eea4ce5..9638150 100644 --- a/src/PartyPage.tsx +++ b/src/PartyPage.tsx @@ -1,7 +1,7 @@ import React, { ChangeEvent, useContext, useRef, useState } from 'react'; import './PartyPage.css'; -import { APIEndPoint, PartyContext } from './PartyContext'; +import { APIEndPoint, PartyContext, PartyStatus } from './PartyContext'; // import MatrixBackground from './MatrixBackground'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faAngleDown, faCalendarDays, faLocationDot } from '@fortawesome/free-solid-svg-icons'; @@ -13,11 +13,33 @@ const myDear = { "d": "liebes", }; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getComingString(party: PartyStatus): string { + if (party.maybe_coming === 0) { + // exact number + if (party.definitely_coming === 0) { + return "Bisher hat noch niemand zugesagt." + } else if (party.definitely_coming === 1) { + return "Bisher hat ein Gast zugesagt." + } else { + return `Es haben schon ${party.definitely_coming} Gäste zugesagt.` + } + } else { + // inexact + if (party.definitely_coming === 0 && party.maybe_coming === 1) { + return "Bisher hat ein Gast vorläufig zugesagt." + } else if (party.definitely_coming === 0) { + return `Bisher haben ${party.maybe_coming} Gäste vorläufig zugesagt.` + } else { + return `Nach den bisherigen Zusagen kommen ${party.definitely_coming} bis ${party.definitely_coming + party.maybe_coming} Gäste.` + } + } +} + export const PartyPage: React.FC = () => { const partyContext = useContext(PartyContext); const dear = myDear[partyContext.self.grammatical_gender]; const name = partyContext.self.name; - const party = partyContext.party; const wannUndWoRef = useRef(null) const executeScroll = () => { wannUndWoRef.current!.scrollIntoView({ behavior: 'smooth' }) @@ -25,8 +47,7 @@ export const PartyPage: React.FC = () => { const [comingState, setComingState] = useState(partyContext.self.coming); // SAFETY: If this is undefined, the contextProvider already fails - // eslint-disable-next-line no-restricted-globals - const endpoint = parseURI(location.href) as APIEndPoint; + const endpoint = parseURI(window.location.href) as APIEndPoint; const handleSelect = async (e: ChangeEvent) => { const value = (e.target as HTMLInputElement).value; @@ -37,28 +58,6 @@ export const PartyPage: React.FC = () => { setComingState(status.coming); } - let coming: string; - if (party.maybe_coming === 0) { - // exact number - if (party.definitely_coming === 0) { - coming = "Bisher hat noch niemand zugesagt." - } else if (party.definitely_coming === 1) { - coming = "Bisher hat ein Gast zugesagt." - } else { - coming = `Es haben schon ${party.definitely_coming} Gäste zugesagt.` - } - } else { - // inexact - if (party.definitely_coming === 0 && party.maybe_coming === 1) { - coming = "Bisher hat ein Gast vorläufig zugesagt." - } else if (party.definitely_coming === 0) { - coming = `Bisher haben ${party.maybe_coming} Gäste vorläufig zugesagt.` - } else { - // eslint-disable-next-line - coming = `Nach den bisherigen Zusagen kommen ${party.definitely_coming} bis ${party.definitely_coming + party.maybe_coming} Gäste.` - } - } - return