-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
201 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faDoorOpen, faDoorClosed } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
const DoorStatus = () => { | ||
const [isOpen, setIsOpen] = useState(null); | ||
|
||
const fetchDoorStatus = async () => { | ||
try { | ||
const response = await fetch("https://doors.amoses.dev/door-status"); | ||
const data = await response.json(); | ||
const { door1, door2 } = data.status; | ||
|
||
// determine if the UPL is open | ||
if (door1 === "open" && door2 === "open") { | ||
setIsOpen(true); | ||
} else { | ||
setIsOpen(false); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching door status:", error); | ||
setIsOpen(false); // default to closed | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchDoorStatus(); | ||
const interval = setInterval(fetchDoorStatus, 500); // fetch every 10 seconds | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
return ( | ||
<a | ||
className={`md:text-md text-sm inline-flex items-center w-fit text-black font-sans font-semibold py-2 px-3 rounded-md focus:outline outline-offset outline-3 outline-sky-300`} | ||
> | ||
<div className="mr-2 flex-shrink-0"> | ||
<FontAwesomeIcon icon={isOpen ? faDoorOpen : faDoorClosed} /> | ||
</div> | ||
<p className="flex-nowrap"> | ||
The doors are{" "} | ||
<span | ||
className={ | ||
isOpen === null | ||
? "text-gray-500 font-bold" | ||
: isOpen | ||
? "text-green-600 font-bold" | ||
: "text-red-600 font-bold" | ||
} | ||
> | ||
{isOpen === null ? "loading..." : isOpen ? "open" : "closed"} | ||
</span> | ||
! | ||
</p> | ||
</a> | ||
); | ||
}; | ||
|
||
export default DoorStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,91 @@ | ||
--- | ||
import HeaderLink from "./HeaderLink.astro"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faDoorOpen, faDoorClosed } from "@fortawesome/free-solid-svg-icons"; | ||
import DoorStatus from "./DoorStatus.jsx"; | ||
const ROUTES: { | ||
path: string; | ||
name: string; | ||
path: string; | ||
name: string; | ||
}[] = [ | ||
{ | ||
path: "/", | ||
name: "Home", | ||
}, | ||
{ | ||
path: "/events", | ||
name: "Events", | ||
}, | ||
{ | ||
path: "/blog", | ||
name: "Blog", | ||
}, | ||
{ | ||
path: "/resources", | ||
name: "Resources", | ||
}, | ||
{ | ||
path: "/about", | ||
name: "About Us", | ||
}, | ||
{ | ||
path: "/hours", | ||
name: "Hours", | ||
}, | ||
{ | ||
path: "/", | ||
name: "Home", | ||
}, | ||
{ | ||
path: "/events", | ||
name: "Events", | ||
}, | ||
{ | ||
path: "/blog", | ||
name: "Blog", | ||
}, | ||
{ | ||
path: "/resources", | ||
name: "Resources", | ||
}, | ||
{ | ||
path: "/about", | ||
name: "About Us", | ||
}, | ||
{ | ||
path: "/hours", | ||
name: "Hours", | ||
}, | ||
]; | ||
--- | ||
|
||
<div class="navbar bg-gray-50"> | ||
<div class="navbar-start"> | ||
<div class="dropdown"> | ||
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="h-5 w-5" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
><path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M4 6h16M4 12h8m-8 6h16"></path></svg | ||
> | ||
</div> | ||
<ul | ||
tabindex="0" | ||
class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52" | ||
> | ||
{ | ||
ROUTES.map((e) => ( | ||
<li class="text-red-500 font-bold"> | ||
<HeaderLink href={e.path}>{e.name}</HeaderLink> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
<a | ||
class="btn btn-ghost text-red-500 lg:text-5xl text-xl font-semibold" | ||
href="/">UPL</a | ||
> | ||
</div> | ||
<div class="navbar-start"> | ||
<div class="dropdown"> | ||
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="h-5 w-5" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
><path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M4 6h16M4 12h8m-8 6h16"></path></svg | ||
> | ||
</div> | ||
<ul | ||
tabindex="0" | ||
class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52" | ||
> | ||
{ | ||
ROUTES.map((e) => ( | ||
<li class="text-red-500 font-bold"> | ||
<HeaderLink href={e.path}>{e.name}</HeaderLink> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
<a | ||
class="btn btn-ghost text-red-500 lg:text-5xl text-xl font-semibold" | ||
href="/">UPL</a | ||
> | ||
</div> | ||
|
||
<div class="navbar-center hidden lg:flex"> | ||
<ul class="menu menu-horizontal px-1 text-lg"> | ||
{ | ||
ROUTES.map((e) => ( | ||
<li class="text-red-500 font-bold"> | ||
<HeaderLink href={e.path}>{e.name}</HeaderLink> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
<div class="navbar-end"></div> | ||
<div class="navbar-center hidden lg:flex"> | ||
<ul class="menu menu-horizontal px-1 text-lg"> | ||
{ | ||
ROUTES.map((e) => ( | ||
<li class="text-red-500 font-bold"> | ||
<HeaderLink href={e.path}>{e.name}</HeaderLink> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
<!-- this is the door label --> | ||
<div class="navbar-end flex"> | ||
<div class="navbar-end flex-none"> | ||
<DoorStatus client:load /> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters