-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathSidebar.tsx
More file actions
126 lines (117 loc) · 3.43 KB
/
Sidebar.tsx
File metadata and controls
126 lines (117 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React from "react";
import { useTranslation } from "react-i18next";
import { Cog, FlaskConical, History, Info, Sparkles, Replace } from "lucide-react";
import HandyTextLogo from "./icons/HandyTextLogo";
import HandyHand from "./icons/HandyHand";
import { useSettings } from "../hooks/useSettings";
import {
GeneralSettings,
AdvancedSettings,
HistorySettings,
DebugSettings,
AboutSettings,
PostProcessingSettings,
Replacements,
} from "./settings";
export type SidebarSection = keyof typeof SECTIONS_CONFIG;
interface IconProps {
width?: number | string;
height?: number | string;
size?: number | string;
className?: string;
[key: string]: any;
}
interface SectionConfig {
labelKey: string;
icon: React.ComponentType<IconProps>;
component: React.ComponentType;
enabled: (settings: any) => boolean;
}
export const SECTIONS_CONFIG = {
general: {
labelKey: "sidebar.general",
icon: HandyHand,
component: GeneralSettings,
enabled: () => true,
},
advanced: {
labelKey: "sidebar.advanced",
icon: Cog,
component: AdvancedSettings,
enabled: () => true,
},
replacements: {
labelKey: "sidebar.replacements",
icon: Replace,
component: Replacements,
enabled: () => true,
},
postprocessing: {
labelKey: "sidebar.postProcessing",
icon: Sparkles,
component: PostProcessingSettings,
enabled: (settings) => settings?.post_process_enabled ?? false,
},
history: {
labelKey: "sidebar.history",
icon: History,
component: HistorySettings,
enabled: () => true,
},
debug: {
labelKey: "sidebar.debug",
icon: FlaskConical,
component: DebugSettings,
enabled: (settings) => settings?.debug_mode ?? false,
},
about: {
labelKey: "sidebar.about",
icon: Info,
component: AboutSettings,
enabled: () => true,
},
} as const satisfies Record<string, SectionConfig>;
interface SidebarProps {
activeSection: SidebarSection;
onSectionChange: (section: SidebarSection) => void;
}
export const Sidebar: React.FC<SidebarProps> = ({
activeSection,
onSectionChange,
}) => {
const { t } = useTranslation();
const { settings } = useSettings();
const availableSections = Object.entries(SECTIONS_CONFIG)
.filter(([_, config]) => config.enabled(settings))
.map(([id, config]) => ({ id: id as SidebarSection, ...config }));
return (
<div className="flex flex-col w-40 h-full border-r border-mid-gray/20 items-center px-2">
<HandyTextLogo width={120} className="m-4" />
<div className="flex flex-col w-full items-center gap-1 pt-2 border-t border-mid-gray/20">
{availableSections.map((section) => {
const Icon = section.icon;
const isActive = activeSection === section.id;
return (
<div
key={section.id}
className={`flex gap-2 items-center p-2 w-full rounded-lg cursor-pointer transition-colors ${
isActive
? "bg-logo-primary/80"
: "hover:bg-mid-gray/20 hover:opacity-100 opacity-85"
}`}
onClick={() => onSectionChange(section.id)}
>
<Icon width={24} height={24} className="shrink-0" />
<p
className="text-sm font-medium truncate"
title={t(section.labelKey)}
>
{t(section.labelKey)}
</p>
</div>
);
})}
</div>
</div>
);
};