-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathPlaygroundSidebar.tsx
More file actions
216 lines (203 loc) · 6.21 KB
/
PlaygroundSidebar.tsx
File metadata and controls
216 lines (203 loc) · 6.21 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import React from "react";
import { IoCodeSlash } from "react-icons/io5";
import { VscOutput } from "react-icons/vsc";
import { FiTerminal, FiShare2, FiSettings } from "react-icons/fi";
import { FaCirclePlay } from "react-icons/fa6";
import { IoChatbubbleEllipsesOutline } from "react-icons/io5";
import useAppStore from "../store/store";
import { message, Tooltip } from "antd";
import FullScreenModal from "./FullScreenModal";
import SettingsModal from "./SettingsModal";
import tour from "./Tour";
import "../styles/components/PlaygroundSidebar.css";
const PlaygroundSidebar = () => {
const {
isEditorsVisible,
isPreviewVisible,
isProblemPanelVisible,
isAIChatOpen,
setEditorsVisible,
setPreviewVisible,
setProblemPanelVisible,
setAIChatOpen,
generateShareableLink,
setSettingsOpen,
} = useAppStore((state) => ({
isEditorsVisible: state.isEditorsVisible,
isPreviewVisible: state.isPreviewVisible,
isProblemPanelVisible: state.isProblemPanelVisible,
isAIChatOpen: state.isAIChatOpen,
setEditorsVisible: state.setEditorsVisible,
setPreviewVisible: state.setPreviewVisible,
setProblemPanelVisible: state.setProblemPanelVisible,
setAIChatOpen: state.setAIChatOpen,
generateShareableLink: state.generateShareableLink,
setSettingsOpen: state.setSettingsOpen,
}));
const handleShare = async () => {
try {
const link = generateShareableLink();
await navigator.clipboard.writeText(link);
void message.success('Link copied to clipboard!');
} catch (err) {
console.error('Error copying to clipboard:', err);
void message.error('Failed to copy link to clipboard');
}
};
const handleSettings = () => {
setSettingsOpen(true);
};
const handleStartTour = async () => {
try {
await tour.start();
localStorage.setItem("hasVisited", "true");
} catch (error) {
console.error("Tour failed to start:", error);
}
};
const handleEditorToggle = () => {
if (isEditorsVisible && !isPreviewVisible) {
void message.info('At least one panel must be visible');
return;
}
setEditorsVisible(!isEditorsVisible);
};
const handlePreviewToggle = () => {
if (isPreviewVisible && !isEditorsVisible) {
void message.info('At least one panel must be visible');
return;
}
setPreviewVisible(!isPreviewVisible);
};
interface NavItem {
title: string;
icon?: React.ComponentType<{ size: number }>;
component?: React.ReactNode;
onClick?: () => void;
active?: boolean;
}
const navTop: NavItem[] = [
{
title: "Editor",
icon: IoCodeSlash,
onClick: handleEditorToggle,
active: isEditorsVisible
},
{
title: "Preview",
icon: VscOutput,
onClick: handlePreviewToggle,
active: isPreviewVisible
},
{
title: "Problems",
icon: FiTerminal,
onClick: () => setProblemPanelVisible(!isProblemPanelVisible),
active: isProblemPanelVisible
},
{
title: "AI Assistant",
component: (
<div className="flex items-center justify-center">
<div className="relative w-6 h-6">
<IoChatbubbleEllipsesOutline size={24} />
<div
className="absolute -top-3 -right-3.5 text-[12.5px] font-bold px-1 py-0 rounded bg-white text-transparent bg-gradient-to-r from-[#a78bfa] via-[#ec4899] to-[#ef4444] bg-clip-text shadow-sm"
style={{
WebkitBackgroundClip: "text"
}}
>
AI
</div>
</div>
</div>
),
onClick: () => setAIChatOpen(!isAIChatOpen),
active: isAIChatOpen
},
{
title: "Fullscreen",
component: <FullScreenModal />
},
];
interface NavBottomItem {
title: string;
icon: React.ComponentType<{ size: number }>;
onClick: () => void;
}
const navBottom: NavBottomItem[] = [
{
title: "Share",
icon: FiShare2,
onClick: () => void handleShare()
},
{
title: "Start Tour",
icon: FaCirclePlay,
onClick: () => void handleStartTour()
},
{
title: "Settings",
icon: FiSettings,
onClick: handleSettings
},
];
return [
<aside key="sidebar" className="playground-sidebar">
<nav className="playground-sidebar-nav">
{navTop.map(({ title, icon: Icon, component, onClick, active }) => (
<Tooltip key={title} title={title} placement="right">
<div
role="button"
aria-label={title}
tabIndex={0}
onClick={onClick}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick?.();
}
}}
className={`group playground-sidebar-nav-item ${
active ? 'playground-sidebar-nav-item-active' : 'playground-sidebar-nav-item-inactive'
} tour-${title.toLowerCase().replace(' ', '-')}`}
>
{component ? (
<div className="playground-sidebar-nav-item-icon-container">
{component}
</div>
) : Icon ? (
<Icon size={20} />
) : null}
<span className="playground-sidebar-nav-item-title">{title}</span>
</div>
</Tooltip>
))}
</nav>
<nav className="playground-sidebar-nav-bottom">
{navBottom.map(({ title, icon: Icon, onClick }) => (
<Tooltip key={title} title={title} placement="right">
<div
role="button"
aria-label={title}
tabIndex={0}
onClick={onClick}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick();
}
}}
className={`group playground-sidebar-nav-bottom-item tour-${title.toLowerCase().replace(' ', '-')}`}
>
<Icon size={18} />
<span className="playground-sidebar-nav-item-title">{title}</span>
</div>
</Tooltip>
))}
</nav>
</aside>,
<SettingsModal key="settings-modal" />
];
};
export default PlaygroundSidebar;