From 1ccee25127ac3c1bcb8a0b219c5a85653918c10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Avil=C3=A9s?= Date: Thu, 16 Dec 2021 16:49:17 -0800 Subject: [PATCH] feat(frontend): add state (context) to NavBar --- client/src/components/NavBar/NavBar.tsx | 50 +++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/client/src/components/NavBar/NavBar.tsx b/client/src/components/NavBar/NavBar.tsx index 7e3b4d0..c463001 100644 --- a/client/src/components/NavBar/NavBar.tsx +++ b/client/src/components/NavBar/NavBar.tsx @@ -1,11 +1,55 @@ -import { ReactElement } from "react"; +import { ReactElement, useContext } from "react"; +import { GlobalContext } from "../../context/GlobalState"; import { HamburgerMenu } from "./HamburgerMenu/HamburgerMenu"; +import "./NavBar.css"; + +function validateAddress(address: string | undefined): string { + if (address) { + const words = address.split(" "); + // sometimes address will contain zip codes, which we remove with !+word + // we also remove duplicates by comparing elements to indexOf + const validAddress = words.filter( + (word, i, self) => !+word && self.indexOf(word) === i + ); + + return validAddress.join(" "); + } + + return "Address not available"; +} + +function getTodayString(): string { + const today = new Date(); + const weekdays = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ]; + + const todayString = today + .toLocaleString("en-US", { + year: "numeric", + month: "short", + day: "numeric", + }) + .replace(",", ""); + + return `${weekdays[today.getDay()]}, ${todayString}`; +} function NavBar(): ReactElement { + const { geocoding } = useContext(GlobalContext); + return ( );