|
1 | 1 | @page "/dragdrop" |
2 | 2 | @inject ITheme Theme |
| 3 | +@inject ToastService ToastService |
3 | 4 |
|
4 | 5 | <PageTitle>Drag & Drop</PageTitle> |
5 | 6 |
|
|
15 | 16 | on where they can and cannot place the dragged item. This will also work on touch devices like mobile! |
16 | 17 | </p> |
17 | 18 |
|
18 | | - <div class="mb-2 max-w-2xl mx-auto flex justify-between p-4 border border-gray-400"> |
| 19 | + <div class="mb-2 max-w-2xl flex justify-between p-4 border border-gray-400"> |
19 | 20 | <DragContext TData="int"> |
20 | 21 | <DragItem DragData="5" Copy="true"> |
21 | 22 | <div class="flex flex-col rounded-lg @Theme.Success.All"> |
|
87 | 88 | it contains the number <b>4</b>. |
88 | 89 | </p> |
89 | 90 |
|
90 | | - <div class="mb-2 max-w-4xl mx-auto overflow-auto flex justify-between p-4 border border-gray-400"> |
| 91 | + <div class="mb-2 max-w-4xl overflow-auto flex justify-between p-4 border border-gray-400"> |
91 | 92 | <DragContext TData="int"> |
92 | 93 | <div class="flex flex-col space-y-4"> |
93 | 94 | <DragItem DragData="5" Copy="true"> |
|
143 | 144 |
|
144 | 145 | <div class="mb-2 overflow-auto flex justify-between"> |
145 | 146 | <DragContext TData="Card" ShowAllDropAreas="false"> |
146 | | - <DropArea Context="Items" Items="@cards" OnDropCompleteAsync="MarkToDoCard"> |
147 | | - <div class="border border-gray-400 p-4 w-96"> |
| 147 | + <DropArea Context="Items" Items="@cards" OnDropComplete="MarkToDoCard"> |
| 148 | + <div class="border border-gray-400 p-4 w-48 sm:w-96"> |
148 | 149 | <h2 class="border-b border-gray-500 mb-2">Backlog</h2> |
149 | 150 | <div class="flex flex-col space-y-2"> |
150 | 151 | @foreach (var item in Items) |
|
154 | 155 | </div> |
155 | 156 | </div> |
156 | 157 | </DropArea> |
157 | | - <DropArea Context="Items" TData="Card" CanDropAsync="SeverityCheck" OnDropCompleteAsync="MarkInProgressCard"> |
158 | | - <div class="border border-gray-400 p-4 w-96"> |
| 158 | + <DropArea Context="Items" TData="Card" CanDrop="SeverityCheck" OnDropComplete="MarkInProgressCard" OnDragEnter="ShowToastEnter" OnDragLeave="ShowToastLeave"> |
| 159 | + <div class="border border-gray-400 p-4 w-48 sm:w-96"> |
159 | 160 | <h2 class="border-b border-gray-500 mb-2">Severe Items</h2> |
160 | 161 | <div class="flex flex-col space-y-2"> |
161 | 162 | @foreach (var item in Items) |
|
165 | 166 | </div> |
166 | 167 | </div> |
167 | 168 | </DropArea> |
168 | | - <DropArea Context="Items" TData="Card" CanDropAsync="ProgressCheck" OnDropCompleteAsync="CompleteCard"> |
169 | | - <div class="border border-gray-400 p-4 w-96"> |
| 169 | + <DropArea Context="Items" TData="Card" CanDrop="ProgressCheck" OnDropComplete="CompleteCard"> |
| 170 | + <div class="border border-gray-400 p-4 w-48 sm:w-96"> |
170 | 171 | <h2 class="border-b border-gray-500 mb-2">Completed</h2> |
171 | 172 | <div class="flex flex-col space-y-2"> |
172 | 173 | @foreach (var item in Items) |
|
183 | 184 | </div> |
184 | 185 |
|
185 | 186 | @code { |
186 | | - Task<bool> SeverityCheck(DragArgs<Card> card) |
| 187 | + void ShowToastEnter(DragArgs<Card> card) |
| 188 | + { |
| 189 | + ToastService.AddToast(new Toast { Header = "Transfer?", Message = $"{card.Data?.Name}" }); |
| 190 | + } |
| 191 | + void ShowToastLeave(DragArgs<Card> card) |
| 192 | + { |
| 193 | + ToastService.AddToast(new Toast { Header = "Nope", Message = $"{card.Data?.Name}" }); |
| 194 | + } |
| 195 | + bool SeverityCheck(DragArgs<Card> card) |
187 | 196 | { |
188 | 197 | var severity = card?.Data?.Severity; |
189 | | - return Task.FromResult(severity == "Medium"); |
| 198 | + return severity == "Medium"; |
190 | 199 | } |
191 | | - Task<bool> ProgressCheck(DragArgs<Card> card) |
| 200 | + bool ProgressCheck(DragArgs<Card> card) |
192 | 201 | { |
193 | | - return Task.FromResult(card?.Data?.Status == "In Progress"); |
| 202 | + return card?.Data?.Status == "In Progress"; |
194 | 203 | } |
195 | | - Task MarkToDoCard(DragArgs<Card> card) |
196 | | - { |
197 | | - card.Data.Status = "To Do"; |
198 | | - card.Data.Severity = "Medium"; |
199 | | - return Task.CompletedTask; |
| 204 | + void MarkToDoCard(DragArgs<Card> card) |
| 205 | + { |
| 206 | + if (card.Data != null) |
| 207 | + { |
| 208 | + card.Data.Status = "To Do"; |
| 209 | + card.Data.Severity = "Medium"; |
| 210 | + } |
200 | 211 | } |
201 | | - Task MarkInProgressCard(DragArgs<Card> card) |
202 | | - { |
203 | | - card.Data.Status = "In Progress"; |
204 | | - card.Data.Severity = "High"; |
205 | | - return Task.CompletedTask; |
| 212 | + void MarkInProgressCard(DragArgs<Card> card) |
| 213 | + { |
| 214 | + if (card.Data != null) |
| 215 | + { |
| 216 | + card.Data.Status = "In Progress"; |
| 217 | + card.Data.Severity = "High"; |
| 218 | + } |
| 219 | + ToastService.AddToast(new Toast { Header = "New Work Item!", Message = $"{card.Data?.Name} has been moved to a Severe Item" }); |
206 | 220 | } |
207 | | - Task CompleteCard(DragArgs<Card> card) |
| 221 | + void CompleteCard(DragArgs<Card> card) |
208 | 222 | { |
209 | | - card.Data.Status = "Complete"; |
210 | | - card.Data.Severity = "Done"; |
211 | | - return Task.CompletedTask; |
| 223 | + if (card.Data != null) |
| 224 | + { |
| 225 | + card.Data.Status = "Complete"; |
| 226 | + card.Data.Severity = "Done"; |
| 227 | + } |
212 | 228 | } |
213 | 229 |
|
214 | 230 | List<Card> cards = new() |
|
238 | 254 |
|
239 | 255 | class Card |
240 | 256 | { |
241 | | - public string Name { get; set; } |
242 | | - public string Description { get; set; } |
243 | | - public string Severity { get; set; } |
244 | | - public string Status { get; set; } |
| 257 | + public string? Name { get; set; } |
| 258 | + public string? Description { get; set; } |
| 259 | + public string? Severity { get; set; } |
| 260 | + public string? Status { get; set; } |
245 | 261 | } |
246 | 262 |
|
247 | 263 | private RenderFragment<Card> CardFragment = card => __builder => |
|
0 commit comments