import "@mantine/core/styles.css";
import { navigate } from "vike/client/router";
import {
AppShell,
Box,
Burger,
Button,
Group,
Image,
MantineProvider,
NavLink,
ScrollArea,
Title,
} from "@mantine/core";
import {
IconHome2,
IconChevronRight,
IconActivity,
IconTrash,
IconCircle,
IconCircleFilled,
IconTrashFilled,
IconPlus,
IconBrandGoogle,
} from "@tabler/icons-react";
import { useDisclosure } from "@mantine/hooks";
import theme from "./theme.js";
import logoUrl from "../assets/logo.png";
import { useEffect, useState } from "react";
import { TRPCProvider, useTRPC } from "../pages/trpc-client.js";
import { usePageContext } from "vike-react/usePageContext";
import "./hover.css";
import {
QueryClient,
QueryClientProvider,
useMutation,
useQuery,
useQueryClient,
} from "@tanstack/react-query";
import {
createTRPCClient,
httpBatchLink,
httpSubscriptionLink,
splitLink,
} from "@trpc/client";
import type { AppRouter } from "@server/trpc/router.js";
function makeQueryClient() {
return new QueryClient({
defaultOptions: {
queries: {
// With SSR, we usually want to set some default staleTime
// above 0 to avoid refetching immediately on the client
staleTime: 60 * 1000,
},
},
});
}
let browserQueryClient: QueryClient | undefined = undefined;
function getQueryClient() {
if (typeof window === "undefined") {
// Server: always make a new query client
return makeQueryClient();
}
// Browser: make a new query client if we don't already have one
// This is very important, so we don't re-make a new client if React
// suspends during the initial render. This may not be needed if we
// have a suspense boundary BELOW the creation of the query client
if (!browserQueryClient) browserQueryClient = makeQueryClient();
// This code is for all users
window.__TANSTACK_QUERY_CLIENT__ = browserQueryClient;
return browserQueryClient;
}
// This code is only for TypeScript
declare global {
interface Window {
__TANSTACK_QUERY_CLIENT__: import("@tanstack/query-core").QueryClient;
}
}
export function SignInWithGoogle() {
const pageContext = usePageContext();
/** This is populated using the +onCreatePageContext.server.ts hook */
const user = pageContext?.user;
const [csrfToken, setCsrfToken] = useState("");
useEffect(() => {
fetch("/api/auth/csrf")
.then((res) => res.json())
.then((obj) => setCsrfToken(obj.csrfToken));
}, []);
if (user?.id) {
return (