From aaeeb54b730f65526ce13871fc86e2577efadd0f Mon Sep 17 00:00:00 2001 From: phntxx Date: Tue, 15 Dec 2020 14:11:15 +0100 Subject: [PATCH] Added function to access imprint with "#imprint" --- src/components/imprint.tsx | 14 +++++++++++++- src/components/modal.tsx | 18 +++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/components/imprint.tsx b/src/components/imprint.tsx index 9444096..232c56e 100644 --- a/src/components/imprint.tsx +++ b/src/components/imprint.tsx @@ -82,6 +82,13 @@ const useImprintData = () => { return { imprintData, fetchImprintData }; }; +const onClose = () => { + if (window.location.href.endsWith("#imprint")) { + let location = window.location.href.replace("#imprint", ""); + window.location.href = location; + } +}; + const Imprint = () => { const { imprintData: { name, address, phone, email, url, error }, @@ -99,7 +106,12 @@ const Imprint = () => { Imprint - + onClose()} + > Legal Disclosure {error && {error}} diff --git a/src/components/modal.tsx b/src/components/modal.tsx index 25d3c1e..b6cc0c4 100644 --- a/src/components/modal.tsx +++ b/src/components/modal.tsx @@ -34,27 +34,31 @@ interface IModalInterface { element: string; icon?: string; text?: string; + condition?: boolean; + onClose?: () => void; children: React.ReactNode; } const Modal = (props: IModalInterface) => { - const [modalHidden, setModalHidden] = useState(true); + const [modalHidden, setModalHidden] = useState(props.condition ?? true); + + const closeModal = () => { + if (props.onClose) props.onClose(); + setModalHidden(!modalHidden); + }; return ( <> {props.element === "icon" && ( - setModalHidden(!modalHidden)} - /> + closeModal()} /> )} {props.element === "text" && ( - setModalHidden(!modalHidden)}>{props.text} + closeModal()}>{props.text} )}