import { cx } from "@twind/core";
import React, { ReactNode } from "react";
import { NavLink } from "react-router-dom";
import useSWR from "swr";
import { apiClient, handleResponse } from "./apiClient.tsx";
function NavTab(props: { to: string; children: ReactNode }) {
return (
cx("tab", isActive && "tab-active")}
to={props.to}
>
{props.children}
);
}
export function AppHeader(
props: { className?: string; sessionId?: string; onLogOut: () => void },
) {
const { className, sessionId, onLogOut } = props;
const session = useSWR(
sessionId ? ["sessions", "GET", { query: { sessionId } }] as const : null,
(args) => apiClient.fetch(...args).then(handleResponse),
{ onError: () => onLogOut() },
);
const user = useSWR(
session.data?.userId
? ["users", "GET", { query: { userId: session.data.userId } }] as const
: null,
(args) => apiClient.fetch(...args).then(handleResponse),
);
return (
);
}