Skip to content

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

feat(sidebar): add i18n-aware tooltips, init new Tooltip component, and refactoring PRIMARY_NAV_BAR in SidebarShell

Phillip Lagoc2f3af5289081
diff --git a/web/components/sidebar/SidebarShell.tsx b/web/components/sidebar/SidebarShell.tsx
index 9c7aeb9b0..98b71516f 100644
--- a/web/components/sidebar/SidebarShell.tsx
+++ b/web/components/sidebar/SidebarShell.tsx
@@ -24,20 +24,47 @@ import SessionList from "@/components/SessionList";
import { TutorBotRecent } from "@/components/sidebar/TutorBotRecent";
import { VersionBadge } from "@/components/sidebar/VersionBadge";
import type { SessionSummary } from "@/lib/session-api";
+import { Tooltip } from "@/components/ui/Tooltip";
interface NavEntry {
href: string;
label: string;
icon: LucideIcon;
+ tooltipKey?: string;
}
const PRIMARY_NAV: NavEntry[] = [
- { href: "/chat", label: "Chat", icon: MessageSquare },
- { href: "/agents", label: "TutorBot", icon: Bot },
- { href: "/co-writer", label: "Co-Writer", icon: PenLine },
- { href: "/book", label: "Book", icon: Library },
- { href: "/knowledge", label: "Knowledge", icon: BookOpen },
- { href: "/space", label: "Space", icon: LayoutGrid },
+ {
+ href: "/chat",
+ label: "Chat",
+ icon: MessageSquare,
+ tooltipKey: "Chat tooltip",
+ },
+ {
+ href: "/agents",
+ label: "TutorBot",
+ icon: Bot,
+ tooltipKey: "TutorBot tooltip",
+ },
+ {
+ href: "/co-writer",
+ label: "Co-Writer",
+ icon: PenLine,
+ tooltipKey: "Co-Writer tooltip",
+ },
+ { href: "/book", label: "Book", icon: Library, tooltipKey: "Book tooltip" },
+ {
+ href: "/knowledge",
+ label: "Knowledge",
+ icon: BookOpen,
+ tooltipKey: "Knowledge tooltip",
+ },
+ {
+ href: "/space",
+ label: "Space",
+ icon: LayoutGrid,
+ tooltipKey: "Space tooltip",
+ },
];
const SECONDARY_NAV: NavEntry[] = [
@@ -130,22 +157,32 @@ export function SidebarShell({
<nav className="flex w-full flex-col items-center gap-1 px-1.5">
{PRIMARY_NAV.map((item) => {
const active = pathname.startsWith(item.href);
+ const tooltipProps = item.tooltipKey
+ ? { description: t(item.tooltipKey) }
+ : {}; // Pass description to tooltip if it exists
return (
- <Link
+ <Tooltip
key={item.href}
- href={item.href}
- title={t(item.label) as string}
- className={`relative flex h-9 w-9 items-center justify-center rounded-xl transition-all duration-150 ${
- active
- ? "bg-[var(--background)]/80 text-[var(--foreground)] shadow-sm"
- : "text-[var(--muted-foreground)] hover:bg-[var(--background)]/50 hover:text-[var(--foreground)]"
- }`}
+ label={t(item.label)}
+ side="right"
+ {...tooltipProps}
>
- {active && (
- <span className="absolute -left-1.5 top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-full bg-[var(--foreground)]/80" />
- )}
- <item.icon size={18} strokeWidth={active ? 2 : 1.6} />
- </Link>
+ <Link
+ key={item.href}
+ href={item.href}
+ title={t(item.label) as string}
+ className={`relative flex h-9 w-9 items-center justify-center rounded-xl transition-all duration-150 ${
+ active
+ ? "bg-[var(--background)]/80 text-[var(--foreground)] shadow-sm"
+ : "text-[var(--muted-foreground)] hover:bg-[var(--background)]/50 hover:text-[var(--foreground)]"
+ }`}
+ >
+ {active && (
+ <span className="absolute -left-1.5 top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-full bg-[var(--foreground)]/80" />
+ )}
+ <item.icon size={18} strokeWidth={active ? 2 : 1.6} />
+ </Link>
+ </Tooltip>
);
})}
</nav>
diff --git a/web/components/ui/Tooltip.tsx b/web/components/ui/Tooltip.tsx
new file mode 100644
index 000000000..9e44e73a1
--- /dev/null
+++ b/web/components/ui/Tooltip.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import { ReactNode } from "react";
+
+interface TooltipProps {
+ label: string;
+ description?: string;
+ children: ReactNode;
+ side?: "right" | "bottom";
+}
+
+export function Tooltip({
+ label,
+ description,
+ children,
+ side = "right",
+}: TooltipProps) {
+ const sideStyles = {
+ right: "left-full top-1/2 -translate-y-1/2 ml-2",
+ bottom: "top-full left-1/2 -translate-x-1/2 mt-2",
+ };
+
+ return (
+ <div className="group relative inline-flex">
+ {children}
+ <div
+ className={`
+ absolute z-50 whitespace-nowrap rounded-lg bg-[var(--popover)] px-3 py-1.5 text-xs text-[var(--popover-foreground)] shadow-md
+ opacity-0 group-hover:opacity-100 transition-opacity duration-200
+ pointer-events-none
+ ${sideStyles[side]}
+ `}
+ >
+ <div className="font-medium">{label}</div>
+ {description && (
+ <div className="mt-0.5 text-[var(--muted-foreground)] text-[11px]">
+ {description}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 43793a083..48aaccec3 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -1597,5 +1597,11 @@
"Please use the attached file(s) and this chapter as context.": "Please use the attached file(s) and this chapter as context.",
"Context": "Context",
"Ask a question about this page. The current chapter content is sent to the assistant automatically.": "Ask a question about this page. The current chapter content is sent to the assistant automatically.",
- "Ask about this page...": "Ask about this page..."
+ "Ask about this page...": "Ask about this page...",
+ "Chat tooltip": "This is the Chat tooltip.",
+ "TutorBot tooltip": "This is the TutorBot tooltip.",
+ "Co-Writer tooltip": "This is the Co-Writer tooltip.",
+ "Book tooltip": "This is the Book tooltip.",
+ "Knowledge tooltip": "This is the Knowledge tooltip.",
+ "Space tooltip": "This is the Space tooltip."
}
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 48b240784..916d32812 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -1597,5 +1597,11 @@
"Please use the attached file(s) and this chapter as context.": "请结合附件文件和本章节上下文回答。",
"Context": "上下文",
"Ask a question about this page. The current chapter content is sent to the assistant automatically.": "可以询问本页内容。当前章节内容会自动发送给助手。",
- "Ask about this page...": "询问本页内容…"
+ "Ask about this page...": "询问本页内容…",
+ "Chat tooltip": "This is the Chat tooltip.",
+ "TutorBot tooltip": "This is the TutorBot tooltip.",
+ "Co-Writer tooltip": "This is the Co-Writer tooltip.",
+ "Book tooltip": "This is the Book tooltip.",
+ "Knowledge tooltip": "This is the Knowledge tooltip.",
+ "Space tooltip": "This is the Space tooltip."
}