forked from shuyu-labs/WebCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionListPanel.razor
More file actions
219 lines (207 loc) · 14.4 KB
/
SessionListPanel.razor
File metadata and controls
219 lines (207 loc) · 14.4 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
217
218
219
@using WebCodeCli.Domain.Domain.Model
@if (Show)
{
<div class="@ContainerClass">
@if (ShowHeader)
{
<div class="p-4 border-b-2 border-gray-200 flex items-center justify-between bg-gray-50">
<h2 class="text-lg font-bold text-gray-800 flex items-center gap-2">
<svg class="w-5 h-5 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
@TitleText
</h2>
<button @onclick="OnClose" class="p-2 hover:bg-gray-200 rounded-lg transition-colors" title="@CloseText">
<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
}
<div class="p-4 border-b border-gray-200">
@if (IsMultiSelectMode)
{
<div class="flex items-center gap-2">
<button @onclick="OnToggleSelectAll"
class="flex-1 px-3 py-2 text-sm border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors flex items-center justify-center gap-2"
title="@(IsAllSelected ? DeselectAllText : SelectAllText)">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>@(IsAllSelected ? DeselectAllText : SelectAllText)</span>
</button>
<button @onclick="OnShowBatchDelete"
disabled="@(SelectedSessionIds.Count == 0)"
class="px-3 py-2 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-2"
title="@BatchDeleteText">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
<span>@BatchDeleteText (@SelectedSessionIds.Count)</span>
</button>
<button @onclick="OnToggleMultiSelect"
class="px-3 py-2 text-sm border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors"
title="@CancelText">
@CancelText
</button>
</div>
}
else
{
<div class="flex items-center gap-2">
<button @onclick="OnCreateNewSession" class="flex-1 btn-primary flex items-center justify-center gap-2 py-3 shadow-md hover:shadow-lg transition-all">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
@NewSessionText
</button>
@if (Sessions.Count > 0)
{
<button @onclick="OnToggleMultiSelect"
class="p-3 border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors"
title="@MultiSelectText">
<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path>
</svg>
</button>
}
</div>
}
</div>
<div class="flex-1 overflow-y-auto" style="@ListContainerStyle">
@if (IsLoadingSessions)
{
<div class="p-8 text-center">
<div class="inline-block animate-spin rounded-full h-12 w-12 border-4 border-gray-300 border-t-gray-700 mb-4"></div>
<p class="text-sm text-gray-500">@LoadingText</p>
</div>
}
else if (Sessions.Any())
{
<div class="p-2 space-y-1">
@foreach (var session in Sessions)
{
<div class="@GetSessionItemClass(session) @(IsLoadingSession && CurrentSessionId == session.SessionId ? "opacity-50 pointer-events-none" : "")"
@onclick="@(async () => await OnSessionClick(session.SessionId))"
style="transition: all 0.2s ease-in-out;">
@if (IsMultiSelectMode)
{
<div class="flex items-center mr-2" @onclick:stopPropagation="true">
<input type="checkbox"
checked="@SelectedSessionIds.Contains(session.SessionId)"
@onchange="@(() => OnToggleSessionSelection.InvokeAsync(session.SessionId))"
class="w-4 h-4 text-gray-800 border-gray-300 rounded focus:ring-gray-500 cursor-pointer" />
</div>
}
<div class="flex-1 min-w-0">
<h3 class="font-semibold truncate text-sm">@session.Title</h3>
<p class="text-xs text-gray-500 mt-1">@FormatDateTime(session.UpdatedAt)</p>
@if (!string.IsNullOrEmpty(session.WorkspacePath))
{
<p class="text-xs text-gray-400 mt-0.5 truncate" title="@session.WorkspacePath">
@session.WorkspacePath
</p>
}
</div>
<div class="flex items-center gap-1 flex-shrink-0">
@if (IsLoadingSession && CurrentSessionId == session.SessionId)
{
<div class="inline-block animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-700"></div>
}
else if (!IsMultiSelectMode)
{
<button @onclick:stopPropagation="true" @onclick="() => OnShareSession.InvokeAsync(session)" class="p-1.5 hover:bg-indigo-100 rounded-lg transition-colors" title="@ShareSessionText">
<svg class="w-4 h-4 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"></path>
</svg>
</button>
<button @onclick:stopPropagation="true" @onclick="() => OnAuthorizeSession.InvokeAsync(session)" class="p-1.5 hover:bg-green-100 rounded-lg transition-colors" title="@AuthorizeSessionText">
<svg class="w-4 h-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
</svg>
</button>
<button @onclick:stopPropagation="true" @onclick="() => OnRenameSession.InvokeAsync(session)" class="p-1.5 hover:bg-gray-100 rounded-lg transition-colors" title="@RenameText">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
</svg>
</button>
<button @onclick:stopPropagation="true" @onclick="() => OnDeleteSession.InvokeAsync(session)" class="p-1.5 hover:bg-red-100 rounded-lg transition-colors" title="@DeleteText">
<svg class="w-4 h-4 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
</button>
}
</div>
</div>
}
</div>
}
else
{
<div class="p-8 text-center text-gray-400">
<div class="w-20 h-20 bg-gray-100 border border-gray-200 rounded-full flex items-center justify-center mx-auto mb-4 shadow-md">
<svg class="w-10 h-10 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"></path>
</svg>
</div>
<p class="text-base font-semibold text-gray-600">@NoSessionsText</p>
<p class="text-sm mt-2 text-gray-500">@CreateSessionHintText</p>
</div>
}
</div>
</div>
}
@code {
[Parameter] public bool Show { get; set; }
[Parameter] public bool Embedded { get; set; }
[Parameter] public bool ShowHeader { get; set; } = true;
[Parameter] public IReadOnlyList<SessionHistory> Sessions { get; set; } = Array.Empty<SessionHistory>();
[Parameter] public IReadOnlyCollection<string> SelectedSessionIds { get; set; } = Array.Empty<string>();
[Parameter] public bool IsMultiSelectMode { get; set; }
[Parameter] public bool IsLoadingSessions { get; set; }
[Parameter] public bool IsLoadingSession { get; set; }
[Parameter] public string CurrentSessionId { get; set; } = string.Empty;
[Parameter] public string TitleText { get; set; } = string.Empty;
[Parameter] public string CloseText { get; set; } = string.Empty;
[Parameter] public string DeselectAllText { get; set; } = string.Empty;
[Parameter] public string SelectAllText { get; set; } = string.Empty;
[Parameter] public string BatchDeleteText { get; set; } = string.Empty;
[Parameter] public string CancelText { get; set; } = string.Empty;
[Parameter] public string NewSessionText { get; set; } = string.Empty;
[Parameter] public string MultiSelectText { get; set; } = string.Empty;
[Parameter] public string LoadingText { get; set; } = string.Empty;
[Parameter] public string RenameText { get; set; } = string.Empty;
[Parameter] public string DeleteText { get; set; } = string.Empty;
[Parameter] public string ShareSessionText { get; set; } = string.Empty;
[Parameter] public string AuthorizeSessionText { get; set; } = string.Empty;
[Parameter] public string NoSessionsText { get; set; } = string.Empty;
[Parameter] public string CreateSessionHintText { get; set; } = string.Empty;
[Parameter] public EventCallback OnClose { get; set; }
[Parameter] public EventCallback OnCreateNewSession { get; set; }
[Parameter] public EventCallback OnToggleMultiSelect { get; set; }
[Parameter] public EventCallback OnToggleSelectAll { get; set; }
[Parameter] public EventCallback OnShowBatchDelete { get; set; }
[Parameter] public EventCallback<string> OnSessionSelected { get; set; }
[Parameter] public EventCallback<string> OnToggleSessionSelection { get; set; }
[Parameter] public EventCallback<SessionHistory> OnShareSession { get; set; }
[Parameter] public EventCallback<SessionHistory> OnAuthorizeSession { get; set; }
[Parameter] public EventCallback<SessionHistory> OnRenameSession { get; set; }
[Parameter] public EventCallback<SessionHistory> OnDeleteSession { get; set; }
[Parameter] public Func<SessionHistory, string> GetSessionItemClass { get; set; } = _ => string.Empty;
[Parameter] public Func<DateTime, string> FormatDateTime { get; set; } = _ => string.Empty;
private bool IsAllSelected => Sessions.Count > 0 && SelectedSessionIds.Count == Sessions.Count;
private string ContainerClass => Embedded
? "flex flex-col h-full w-full"
: "block fixed inset-y-0 left-0 w-80 bg-white shadow-2xl z-50 transform transition-transform duration-300 ease-in-out";
private string ListContainerStyle => Embedded
? string.Empty
: "height: calc(100vh - 180px);";
private Task OnSessionClick(string sessionId)
{
if (IsMultiSelectMode)
{
return OnToggleSessionSelection.InvokeAsync(sessionId);
}
return OnSessionSelected.InvokeAsync(sessionId);
}
}