forked from partypages/party-template
This commit is contained in:
parent
9a227a1e47
commit
2e1f63c5f2
@ -41,8 +41,7 @@ export const PartyContextProvider: React.FC<{ children: React.ReactNode }> = (pr
|
||||
const [partyContext, setPartyContext] = useState<PartyContextType>();
|
||||
|
||||
const apiEndpoint = useMemo<APIEndPoint>(() => {
|
||||
// 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;
|
||||
|
||||
@ -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<HTMLDivElement>(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 <div className="App">
|
||||
<div className='container'>
|
||||
<div className='hero fullheight'>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user