Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/doors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import Col from "react-bootstrap/Col";
import Spinner from "react-bootstrap/Spinner";
import { apiFetch } from "@/lib/api";
import DoorCard, { type Door, type DoorStatus } from "@/components/DoorCard";
import AuthGate from "@/components/AuthGate";

export default function DoorsPage() {
function DoorsPageInner() {
const { data: session } = useSession();
const token = session?.accessToken ?? "";

Expand Down Expand Up @@ -152,6 +153,7 @@ export default function DoorsPage() {
status={statuses[door.id]}
onUnlock={handleUnlock}
loading={unlocking[door.id] ?? false}
offline={statuses[door.id]?.guess === "offline"}
/>
</Col>
))}
Expand All @@ -167,6 +169,7 @@ export default function DoorsPage() {
status={statuses[door.id]}
onUnlock={handleUnlock}
loading={false}
offline={statuses[door.id]?.guess === "offline"}
/>
</Col>
))}
Expand All @@ -175,4 +178,12 @@ export default function DoorsPage() {
)}
</Container>
);
}

export default function DoorsPage() {
return (
<AuthGate>
<DoorsPageInner />
</AuthGate>
);
}
4 changes: 2 additions & 2 deletions components/AuthGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import { Container, Spinner } from "react-bootstrap";
import { useSession, signIn } from "next-auth/react";
import { AUTH_PROVIDER_ID, REFRESH_TOKEN_ERROR } from "@/lib/constants";
import { useEffect } from "react";
import { useEffect, type ReactNode } from "react";

export default function AuthGate({ children }) {
export default function AuthGate({ children }: {children: ReactNode}) {
const { data: session, status } = useSession({
required: true,
onUnauthenticated() {
Expand Down
4 changes: 3 additions & 1 deletion components/DoorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface DoorCardProps {
status: DoorStatus | undefined;
onUnlock: (doorId: string) => void;
loading?: boolean;
offline?: boolean;
}

const STATUS_COLOR: Record<string, string> = {
Expand All @@ -40,6 +41,7 @@ export default function DoorCard({
status,
onUnlock,
loading = false,
offline = false
}: DoorCardProps) {
const guess = status?.guess ?? "unknown";
const color = STATUS_COLOR[guess] ?? STATUS_COLOR.unknown;
Expand Down Expand Up @@ -79,7 +81,7 @@ export default function DoorCard({
variant="primary"
className="ms-3 flex-shrink-0"
onClick={() => onUnlock(door.id)}
disabled={loading}
disabled={loading || offline}
>
{loading ? (
<>
Expand Down