more cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mrmaxmeier 2022-11-15 14:36:42 +01:00
parent 9a227a1e47
commit 2e1f63c5f2
2 changed files with 26 additions and 28 deletions

View File

@ -41,8 +41,7 @@ export const PartyContextProvider: React.FC<{ children: React.ReactNode }> = (pr
const [partyContext, setPartyContext] = useState<PartyContextType>(); const [partyContext, setPartyContext] = useState<PartyContextType>();
const apiEndpoint = useMemo<APIEndPoint>(() => { const apiEndpoint = useMemo<APIEndPoint>(() => {
// eslint-disable-next-line no-restricted-globals const href = window.location.href;
const href = location.href;
const p = parseURI(href); const p = parseURI(href);
if (!p) return { partyName: "error", token: "" } if (!p) return { partyName: "error", token: "" }
return p; return p;

View File

@ -1,7 +1,7 @@
import React, { ChangeEvent, useContext, useRef, useState } from 'react'; import React, { ChangeEvent, useContext, useRef, useState } from 'react';
import './PartyPage.css'; import './PartyPage.css';
import { APIEndPoint, PartyContext } from './PartyContext'; import { APIEndPoint, PartyContext, PartyStatus } from './PartyContext';
// import MatrixBackground from './MatrixBackground'; // import MatrixBackground from './MatrixBackground';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faAngleDown, faCalendarDays, faLocationDot } from '@fortawesome/free-solid-svg-icons'; import { faAngleDown, faCalendarDays, faLocationDot } from '@fortawesome/free-solid-svg-icons';
@ -13,11 +13,33 @@ const myDear = {
"d": "liebes", "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 = () => { export const PartyPage: React.FC = () => {
const partyContext = useContext(PartyContext); const partyContext = useContext(PartyContext);
const dear = myDear[partyContext.self.grammatical_gender]; const dear = myDear[partyContext.self.grammatical_gender];
const name = partyContext.self.name; const name = partyContext.self.name;
const party = partyContext.party;
const wannUndWoRef = useRef<HTMLDivElement>(null) const wannUndWoRef = useRef<HTMLDivElement>(null)
const executeScroll = () => { const executeScroll = () => {
wannUndWoRef.current!.scrollIntoView({ behavior: 'smooth' }) wannUndWoRef.current!.scrollIntoView({ behavior: 'smooth' })
@ -25,8 +47,7 @@ export const PartyPage: React.FC = () => {
const [comingState, setComingState] = useState(partyContext.self.coming); const [comingState, setComingState] = useState(partyContext.self.coming);
// SAFETY: If this is undefined, the contextProvider already fails // SAFETY: If this is undefined, the contextProvider already fails
// eslint-disable-next-line no-restricted-globals const endpoint = parseURI(window.location.href) as APIEndPoint;
const endpoint = parseURI(location.href) as APIEndPoint;
const handleSelect = async (e: ChangeEvent) => { const handleSelect = async (e: ChangeEvent) => {
const value = (e.target as HTMLInputElement).value; const value = (e.target as HTMLInputElement).value;
@ -37,28 +58,6 @@ export const PartyPage: React.FC = () => {
setComingState(status.coming); 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 <div className="App"> return <div className="App">
<div className='container'> <div className='container'>
<div className='hero fullheight'> <div className='hero fullheight'>