mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(web): icon-only modality tabs, merge documents and files
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { CATEGORIES, MODALITIES, type Modality, TOOLS } from "@snapotter/shared";
|
import { CATEGORIES, MODALITIES, type Modality, TOOLS } from "@snapotter/shared";
|
||||||
|
import { LayoutGrid } from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "@/contexts/i18n-context";
|
import { useTranslation } from "@/contexts/i18n-context";
|
||||||
import { useFuseSearch } from "@/hooks/use-fuse-search";
|
import { useFuseSearch } from "@/hooks/use-fuse-search";
|
||||||
@@ -10,7 +11,9 @@ import { useSettingsStore } from "@/stores/settings-store";
|
|||||||
import { SearchBar } from "../common/search-bar";
|
import { SearchBar } from "../common/search-bar";
|
||||||
import { ToolCard } from "../common/tool-card";
|
import { ToolCard } from "../common/tool-card";
|
||||||
|
|
||||||
type ModalityFilter = "all" | Modality;
|
type ModalityFilter = "all" | "document" | Exclude<Modality, "file">;
|
||||||
|
|
||||||
|
const TAB_MODALITIES = MODALITIES.filter((m) => m.id !== "file");
|
||||||
|
|
||||||
export function ToolPanel() {
|
export function ToolPanel() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -38,6 +41,10 @@ export function ToolPanel() {
|
|||||||
|
|
||||||
const modalityFilteredTools = useMemo(() => {
|
const modalityFilteredTools = useMemo(() => {
|
||||||
if (selectedModality === "all") return visibleTools;
|
if (selectedModality === "all") return visibleTools;
|
||||||
|
if (selectedModality === "document")
|
||||||
|
return visibleTools.filter(
|
||||||
|
(tool) => tool.modality === "document" || tool.modality === "file",
|
||||||
|
);
|
||||||
return visibleTools.filter((tool) => tool.modality === selectedModality);
|
return visibleTools.filter((tool) => tool.modality === selectedModality);
|
||||||
}, [visibleTools, selectedModality]);
|
}, [visibleTools, selectedModality]);
|
||||||
|
|
||||||
@@ -46,10 +53,7 @@ export function ToolPanel() {
|
|||||||
const groupedByModality = useMemo(() => {
|
const groupedByModality = useMemo(() => {
|
||||||
const byModality = new Map<string, Map<string, typeof TOOLS>>();
|
const byModality = new Map<string, Map<string, typeof TOOLS>>();
|
||||||
for (const tool of filteredTools) {
|
for (const tool of filteredTools) {
|
||||||
// In "all" mode, merge file-modality tools into the document section;
|
const key = tool.modality === "file" ? "document" : tool.modality;
|
||||||
// when a specific tab is active, keep the original modality key.
|
|
||||||
const key =
|
|
||||||
selectedModality === "all" && tool.modality === "file" ? "document" : tool.modality;
|
|
||||||
const cats = byModality.get(key) ?? new Map<string, typeof TOOLS>();
|
const cats = byModality.get(key) ?? new Map<string, typeof TOOLS>();
|
||||||
const list = cats.get(tool.category) ?? [];
|
const list = cats.get(tool.category) ?? [];
|
||||||
list.push(tool);
|
list.push(tool);
|
||||||
@@ -62,35 +66,37 @@ export function ToolPanel() {
|
|||||||
return (
|
return (
|
||||||
<div className="w-72 border-r border-border bg-background overflow-y-auto flex flex-col shrink-0">
|
<div className="w-72 border-r border-border bg-background overflow-y-auto flex flex-col shrink-0">
|
||||||
<div className="p-3 sticky top-0 bg-background z-10">
|
<div className="p-3 sticky top-0 bg-background z-10">
|
||||||
{/* Modality filter tabs */}
|
{/* Modality filter tabs -- icon-only, docs+files merged */}
|
||||||
<div className="flex flex-wrap gap-1 mb-2">
|
<div className="flex items-center gap-1 mb-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setSelectedModality("all")}
|
onClick={() => setSelectedModality("all")}
|
||||||
|
title="All tools"
|
||||||
className={cn(
|
className={cn(
|
||||||
"shrink-0 px-2.5 py-1 rounded-md text-xs font-medium transition-colors",
|
"p-1.5 rounded-md transition-colors",
|
||||||
selectedModality === "all"
|
selectedModality === "all"
|
||||||
? "bg-primary/10 text-primary"
|
? "bg-primary/10 text-primary"
|
||||||
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
All
|
<LayoutGrid className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
{MODALITIES.map((m) => {
|
{TAB_MODALITIES.map((m) => {
|
||||||
|
const Icon = ICON_MAP[m.icon] as React.ComponentType<{ className?: string }>;
|
||||||
const isActive = selectedModality === m.id;
|
const isActive = selectedModality === m.id;
|
||||||
const short = m.id === "document" ? "Docs" : m.id === "file" ? "Files" : m.name;
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={m.id}
|
key={m.id}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setSelectedModality(m.id)}
|
onClick={() => setSelectedModality(m.id as ModalityFilter)}
|
||||||
|
title={m.id === "document" ? "Documents & Files" : m.name}
|
||||||
className={cn(
|
className={cn(
|
||||||
"px-2 py-1 rounded-md text-xs font-medium transition-colors",
|
"p-1.5 rounded-md transition-colors",
|
||||||
!isActive && "text-muted-foreground hover:text-foreground hover:bg-muted",
|
!isActive && "text-muted-foreground hover:text-foreground hover:bg-muted",
|
||||||
)}
|
)}
|
||||||
style={isActive ? { backgroundColor: `${m.color}20`, color: m.color } : undefined}
|
style={isActive ? { backgroundColor: `${m.color}20`, color: m.color } : undefined}
|
||||||
>
|
>
|
||||||
{short}
|
{Icon && <Icon className="h-4 w-4" />}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -99,10 +105,8 @@ export function ToolPanel() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="px-3 pb-4 flex-1">
|
<div className="px-3 pb-4 flex-1">
|
||||||
{MODALITIES.filter((m) => {
|
{MODALITIES.filter((m) => {
|
||||||
// In "all" mode, file-modality tools are merged into the document
|
// File-modality tools always merge into the document section
|
||||||
// section so skip the standalone file entry. When the file tab is
|
if (m.id === "file") return false;
|
||||||
// active, keep it.
|
|
||||||
if (selectedModality === "all" && m.id === "file") return false;
|
|
||||||
return groupedByModality.has(m.id);
|
return groupedByModality.has(m.id);
|
||||||
}).map((modality, idx, arr) => {
|
}).map((modality, idx, arr) => {
|
||||||
const ModalityIcon = ICON_MAP[modality.icon] as React.ComponentType<{
|
const ModalityIcon = ICON_MAP[modality.icon] as React.ComponentType<{
|
||||||
@@ -127,9 +131,7 @@ export function ToolPanel() {
|
|||||||
{getModalityName(
|
{getModalityName(
|
||||||
t,
|
t,
|
||||||
modality.id,
|
modality.id,
|
||||||
modality.id === "document" && selectedModality === "all"
|
modality.id === "document" ? "Documents & Files" : modality.name,
|
||||||
? "Documents & Files"
|
|
||||||
: modality.name,
|
|
||||||
)}
|
)}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user