mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-02 22:01:05 +02:00
feat(sidebar): live pages meter via Zero for authenticated users
This commit is contained in:
parent
2a14c05282
commit
6b06416d47
3 changed files with 17 additions and 13 deletions
|
|
@ -681,14 +681,6 @@ export function LayoutDataProvider({ searchSpaceId, children }: LayoutDataProvid
|
||||||
}
|
}
|
||||||
}, [chatToRename, newChatTitle, queryClient, searchSpaceId, tSidebar]);
|
}, [chatToRename, newChatTitle, queryClient, searchSpaceId, tSidebar]);
|
||||||
|
|
||||||
// Page usage
|
|
||||||
const pageUsage = user
|
|
||||||
? {
|
|
||||||
pagesUsed: user.pages_used,
|
|
||||||
pagesLimit: user.pages_limit,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// Detect if we're on the chat page (needs overflow-hidden for chat's own scroll)
|
// Detect if we're on the chat page (needs overflow-hidden for chat's own scroll)
|
||||||
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
||||||
|
|
||||||
|
|
@ -723,7 +715,6 @@ export function LayoutDataProvider({ searchSpaceId, children }: LayoutDataProvid
|
||||||
onManageMembers={handleManageMembers}
|
onManageMembers={handleManageMembers}
|
||||||
onUserSettings={handleUserSettings}
|
onUserSettings={handleUserSettings}
|
||||||
onLogout={handleLogout}
|
onLogout={handleLogout}
|
||||||
pageUsage={pageUsage}
|
|
||||||
theme={theme}
|
theme={theme}
|
||||||
setTheme={setTheme}
|
setTheme={setTheme}
|
||||||
isChatPage={isChatPage}
|
isChatPage={isChatPage}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useQuery } from "@rocicorp/zero/react";
|
||||||
|
import { useIsAnonymous } from "@/contexts/anonymous-mode";
|
||||||
|
import { queries } from "@/zero/queries";
|
||||||
|
import { PageUsageDisplay } from "./PageUsageDisplay";
|
||||||
|
|
||||||
|
export function AuthenticatedPageUsageDisplay() {
|
||||||
|
const isAnonymous = useIsAnonymous();
|
||||||
|
const [me] = useQuery(queries.user.me({}));
|
||||||
|
|
||||||
|
if (isAnonymous || !me) return null;
|
||||||
|
|
||||||
|
return <PageUsageDisplay pagesUsed={me.pagesUsed} pagesLimit={me.pagesLimit} />;
|
||||||
|
}
|
||||||
|
|
@ -12,9 +12,9 @@ import { useIsAnonymous } from "@/contexts/anonymous-mode";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { SIDEBAR_MIN_WIDTH } from "../../hooks/useSidebarResize";
|
import { SIDEBAR_MIN_WIDTH } from "../../hooks/useSidebarResize";
|
||||||
import type { ChatItem, NavItem, PageUsage, SearchSpace, User } from "../../types/layout.types";
|
import type { ChatItem, NavItem, PageUsage, SearchSpace, User } from "../../types/layout.types";
|
||||||
|
import { AuthenticatedPageUsageDisplay } from "./AuthenticatedPageUsageDisplay";
|
||||||
import { ChatListItem } from "./ChatListItem";
|
import { ChatListItem } from "./ChatListItem";
|
||||||
import { NavSection } from "./NavSection";
|
import { NavSection } from "./NavSection";
|
||||||
import { PageUsageDisplay } from "./PageUsageDisplay";
|
|
||||||
import { PremiumTokenUsageDisplay } from "./PremiumTokenUsageDisplay";
|
import { PremiumTokenUsageDisplay } from "./PremiumTokenUsageDisplay";
|
||||||
import { SidebarButton } from "./SidebarButton";
|
import { SidebarButton } from "./SidebarButton";
|
||||||
import { SidebarCollapseButton } from "./SidebarCollapseButton";
|
import { SidebarCollapseButton } from "./SidebarCollapseButton";
|
||||||
|
|
@ -338,9 +338,7 @@ function SidebarUsageFooter({
|
||||||
return (
|
return (
|
||||||
<div className="px-3 py-3 border-t space-y-3">
|
<div className="px-3 py-3 border-t space-y-3">
|
||||||
<PremiumTokenUsageDisplay />
|
<PremiumTokenUsageDisplay />
|
||||||
{pageUsage && (
|
<AuthenticatedPageUsageDisplay />
|
||||||
<PageUsageDisplay pagesUsed={pageUsage.pagesUsed} pagesLimit={pageUsage.pagesLimit} />
|
|
||||||
)}
|
|
||||||
<div className="space-y-0.5">
|
<div className="space-y-0.5">
|
||||||
<Link
|
<Link
|
||||||
href={`/dashboard/${searchSpaceId}/more-pages`}
|
href={`/dashboard/${searchSpaceId}/more-pages`}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue