mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
feat: enhance ElectricProvider and Tooltip components for improved user experience
- Updated ElectricProvider to check for user authentication via bearer token before rendering, preventing unnecessary loading screens for unauthenticated users. - Modified TooltipProvider to include a new disableHoverableContent prop, enhancing tooltip behavior and usability.
This commit is contained in:
parent
a51fe2ee69
commit
bba3cb1cf9
2 changed files with 9 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { currentUserAtom } from "@/atoms/user/user-query.atoms";
|
import { currentUserAtom } from "@/atoms/user/user-query.atoms";
|
||||||
|
import { getBearerToken } from "@/lib/auth-utils";
|
||||||
import {
|
import {
|
||||||
cleanupElectric,
|
cleanupElectric,
|
||||||
type ElectricClient,
|
type ElectricClient,
|
||||||
|
|
@ -105,9 +106,13 @@ export function ElectricProvider({ children }: ElectricProviderProps) {
|
||||||
};
|
};
|
||||||
}, [user?.id, isUserLoaded, electricClient]);
|
}, [user?.id, isUserLoaded, electricClient]);
|
||||||
|
|
||||||
|
// Check if user is authenticated first (has bearer token)
|
||||||
|
// This prevents showing loading screen for unauthenticated users on homepage
|
||||||
|
const hasToken = typeof window !== "undefined" && !!getBearerToken();
|
||||||
|
|
||||||
// For non-authenticated pages (like landing page), render immediately with null context
|
// For non-authenticated pages (like landing page), render immediately with null context
|
||||||
// Also render immediately if user query failed (e.g., token expired)
|
// Also render immediately if user query failed (e.g., token expired)
|
||||||
if (!isUserLoaded || !user?.id || isUserError) {
|
if (!hasToken || !isUserLoaded || !user?.id || isUserError) {
|
||||||
return <ElectricContext.Provider value={null}>{children}</ElectricContext.Provider>;
|
return <ElectricContext.Provider value={null}>{children}</ElectricContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,14 @@ import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function TooltipProvider({
|
function TooltipProvider({
|
||||||
delayDuration = 0,
|
delayDuration = 0,
|
||||||
|
disableHoverableContent = true,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||||
return (
|
return (
|
||||||
<TooltipPrimitive.Provider
|
<TooltipPrimitive.Provider
|
||||||
data-slot="tooltip-provider"
|
data-slot="tooltip-provider"
|
||||||
delayDuration={delayDuration}
|
delayDuration={delayDuration}
|
||||||
|
disableHoverableContent={disableHoverableContent}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
@ -42,7 +44,7 @@ function TooltipContent({
|
||||||
data-slot="tooltip-content"
|
data-slot="tooltip-content"
|
||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-black text-white font-medium shadow-xl px-3 py-1.5 dark:bg-zinc-800 dark:text-zinc-50 border-none animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit rounded-md text-xs text-balance",
|
"bg-black text-white font-medium shadow-xl px-3 py-1.5 dark:bg-zinc-800 dark:text-zinc-50 border-none animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit rounded-md text-xs text-balance pointer-events-none",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue