Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Merge PR #1455: disable sidebar viewport prefetch

Bingxi Zhao (Frank)3170e27f58ce
diff --cc web/components/sidebar/SidebarNav.tsx
index 667a35fc9,f39e78e40..5ac32d2c2
--- a/web/components/sidebar/SidebarNav.tsx
+++ b/web/components/sidebar/SidebarNav.tsx
@@@ -515,76 -508,6 +517,77 @@@ export function SidebarNav(
);
}
+export function SidebarHome({
+ collapsed = false,
+ onHomeClick,
+}: {
+ collapsed?: boolean;
+ onHomeClick: (event: React.MouseEvent) => void;
+}) {
+ const { t } = useTranslation();
+ const pathname = usePathname();
+ const { has } = useCapabilityAccess();
+ const entry = NAV_BY_HREF.get("/chat")!;
+ const active = isNavActive(pathname, entry.href);
+ const locked = entry.requires ? !has(entry.requires) : false;
+ const lockedTooltip = t("Locked — contact your administrator to get access.");
+ if (collapsed) {
+ return (
+ <div className="mt-1 flex shrink-0 justify-center">
+ <RailRow
+ href="/chat"
+ active={active}
+ locked={locked}
+ lockedTooltip={lockedTooltip}
+ onHomeClick={onHomeClick}
+ />
+ </div>
+ );
+ }
+ const Icon = entry.icon;
+ const content = (
+ <>
+ <Icon size={15} strokeWidth={active ? 1.9 : 1.6} className="shrink-0" />
+ <span>{t(entry.label)}</span>
+ </>
+ );
+ const className =
+ "flex min-h-8 items-center gap-2 rounded-md px-2.5 py-1.5 text-[13px] transition-colors";
+ return (
+ <div className="shrink-0 px-2 pb-1 pt-1">
+ {locked ? (
+ <Tooltip
+ label={t(entry.label)}
+ description={lockedTooltip}
+ side="right"
+ >
+ <div
+ aria-disabled
+ aria-label={`${t(entry.label)} — ${lockedTooltip}`}
+ className={`${className} cursor-not-allowed text-muted-foreground/40`}
+ >
+ {content}
+ <Lock size={13} className="ml-auto" />
+ </div>
+ </Tooltip>
+ ) : (
+ <Link
+ href="/chat"
++ prefetch={false}
+ onClick={onHomeClick}
+ className={`${className} ${
+ active
+ ? "bg-[var(--accent)] font-medium text-[var(--foreground)]"
+ : "text-foreground/85 hover:bg-background/60 hover:text-[var(--foreground)]"
+ }`}
+ >
+ {content}
+ </Link>
+ )}
+ </div>
+ );
+}
+
function RailRow({
href,
active,
diff --cc web/components/sidebar/SidebarShell.tsx
index 633a8afb6,3b0a82217..c609aad92
--- a/web/components/sidebar/SidebarShell.tsx
+++ b/web/components/sidebar/SidebarShell.tsx
@@@ -246,13 -301,14 +248,13 @@@ export function SidebarShell(
/* ---- Expanded state ---- */
return (
- <aside className="flex w-[220px] h-dvh shrink-0 flex-col bg-[var(--secondary)] transition-all duration-200">
+ <aside
+ style={{ "--sidebar-width": `${resize.width}px` } as CSSProperties}
+ className="relative flex h-dvh w-[var(--sidebar-width)] max-w-[45vw] shrink-0 flex-col bg-[var(--secondary)] max-md:w-[220px] max-md:max-w-[85vw]"
+ >
{/* Header: logo + collapse toggle */}
- <div className="flex h-14 items-center justify-between px-4">
- <Link
- href="/"
- prefetch={false}
- className="group flex items-center gap-1.5"
- >
+ <div className="flex h-[52px] shrink-0 items-center justify-between px-4">
- <Link href="/" className="group flex items-center gap-1.5">
++ <Link href="/" prefetch={false} className="group flex items-center gap-1.5">
<Image
src="/logo.png"
alt="DeepTutor"
@@@ -350,52 -396,59 +352,53 @@@
compact
/>
)}
- </div>
- </section>
- ) : null}
-
- {recycleBinSlot}
-
- {/* With no session list at all, fill the gap above the footer. */}
- {(!showSessions ||
- !onSelectSession ||
- !onRenameSession ||
- !onDeleteSession) && <div className="flex-1" />}
+ </section>
+ ) : null}
+ </div>
{/* Secondary nav + footer */}
- <div className="border-t border-[var(--border)]/40 px-2 py-2">
- {SECONDARY_NAV.map((item) => {
- const active = isNavActive(pathname, item.href);
- return (
- <Link
- key={item.href}
- href={item.href}
- prefetch={false}
- onClick={closeDrawerOnNav}
- className={`flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13.5px] transition-colors ${
- active
- ? "bg-[var(--accent)] font-medium text-[var(--foreground)]"
- : "text-[var(--foreground)]/85 hover:bg-[var(--background)]/60 hover:text-[var(--foreground)]"
- }`}
- >
- <item.icon size={16} strokeWidth={active ? 1.9 : 1.5} />
- <span>{t(item.label)}</span>
- </Link>
- );
- })}
+ <div className="shrink-0 border-t border-border/40 px-2 py-2">
{renderedFooter}
- <div className="mt-0.5 flex items-center gap-0.5">
- <VersionBadge />
- <a
- href={DOCS_URL}
- target="_blank"
- rel="noreferrer noopener"
- title={t("Docs") as string}
- aria-label={t("Docs") as string}
- className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--muted-foreground)]/55 transition-colors hover:bg-[var(--background)]/50 hover:text-[var(--muted-foreground)]"
- >
- <BookText
- size={15}
- strokeWidth={1.9}
- className="text-blue-600 dark:text-blue-400"
- />
- </a>
- <GitHubMarkLink />
+ <div className="flex items-center gap-1">
+ {SECONDARY_NAV.map((item) => {
+ const active = isNavActive(pathname, item.href);
+ return (
+ <Link
+ key={item.href}
+ href={item.href}
++ prefetch={false}
+ onClick={closeDrawerOnNav}
+ className={`flex min-h-8 min-w-0 flex-1 items-center gap-2 rounded-md px-2.5 py-1.5 text-[13px] transition-colors ${
+ active
+ ? "bg-[var(--accent)] font-medium text-[var(--foreground)]"
+ : "text-foreground/85 hover:bg-background/60 hover:text-[var(--foreground)]"
+ }`}
+ >
+ <item.icon size={15} strokeWidth={active ? 1.9 : 1.6} />
+ <span>{t(item.label)}</span>
+ </Link>
+ );
+ })}
+ <VersionBadge onNavigate={closeDrawerOnNav} />
</div>
</div>
+ {!isMobile && (
+ <div
+ role="separator"
+ aria-label={t("Resize sidebar")}
+ aria-orientation="vertical"
+ aria-valuemin={resize.min}
+ aria-valuemax={resize.max}
+ aria-valuenow={resize.width}
+ tabIndex={0}
+ {...resize.handleProps}
+ className="group/resize absolute inset-y-0 -right-1 z-30 w-2 touch-none cursor-col-resize outline-none max-md:hidden"
+ >
+ <div
+ className={`mx-auto h-full w-0.5 transition-colors group-hover/resize:bg-[var(--ring)] group-focus-visible/resize:bg-[var(--ring)] ${resize.resizing ? "bg-[var(--ring)]" : "bg-transparent"}`}
+ />
+ </div>
+ )}
</aside>
);
}
diff --cc web/components/sidebar/VersionBadge.tsx
index f947f1b8a,9ff86d607..931477549
--- a/web/components/sidebar/VersionBadge.tsx
+++ b/web/components/sidebar/VersionBadge.tsx
@@@ -63,11 -75,19 +63,12 @@@ export function VersionBadge({ onNaviga
return (
<Link
- href="/settings#about"
+ href="/settings/about"
+ prefetch={false}
- scroll={false}
- onClick={(event) => {
- if (pathname !== "/settings") return;
- event.preventDefault();
- window.history.replaceState(null, "", "/settings#about");
- scrollToSettingsSection("about", "auto");
- requestSettingsSection("about");
- }}
- title={`${displayTag} · ${state.label}`}
- aria-label={`${displayTag} · ${state.label}`}
- className="group/ver flex min-w-0 flex-1 items-center gap-2 rounded-lg px-3 py-1.5 font-serif text-[14px] font-semibold tabular-nums tracking-[-0.025em] text-[var(--foreground)]/80 transition-colors hover:bg-[var(--background)]/50 hover:text-[var(--foreground)]"
+ onClick={onNavigate}
+ title={state.label as string}
+ aria-label={state.label as string}
+ className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-background/50 hover:text-[var(--foreground)]"
>
<span
aria-hidden="true"