|
17 | 17 |
|
18 | 18 | private List<FileEntry> _files = new(); |
19 | 19 | private bool _isLoading; |
| 20 | + private bool _isOpening; |
| 21 | + private bool _isUploading; |
| 22 | + private bool _isCopying; |
20 | 23 | private FileEntry? selectedFile; |
21 | 24 |
|
22 | 25 | protected override async Task OnInitializedAsync() |
|
41 | 44 | if (!EnableUpload) return; |
42 | 45 | var file = e.File; |
43 | 46 | if (file == null) return; |
44 | | - await using var stream = file.OpenReadStream(long.MaxValue); |
45 | | - await Provider.SaveFileAsync(file.Name, stream); |
| 47 | + _isUploading = true; |
| 48 | + StateHasChanged(); |
| 49 | + try |
| 50 | + { |
| 51 | + await using var stream = file.OpenReadStream(long.MaxValue); |
| 52 | + await Provider.SaveFileAsync(file.Name, stream); |
| 53 | + } |
| 54 | + finally |
| 55 | + { |
| 56 | + _isUploading = false; |
| 57 | + StateHasChanged(); |
| 58 | + } |
46 | 59 | await RefreshFiles(); |
47 | 60 | } |
48 | 61 |
|
49 | 62 | private async Task CopySelected() |
50 | 63 | { |
51 | 64 | if (!EnableCopy || selectedFile == null || TargetProvider == null) return; |
52 | | - await using var stream = await Provider.OpenReadAsync(selectedFile.FullPath) ?? Stream.Null; |
53 | | - if (stream == Stream.Null) return; |
54 | | - await TargetProvider.SaveFileAsync(Path.GetFileName(selectedFile.FullPath), stream); |
| 65 | + _isCopying = true; |
| 66 | + StateHasChanged(); |
| 67 | + try |
| 68 | + { |
| 69 | + await using var stream = await Provider.OpenReadAsync(selectedFile.FullPath) ?? Stream.Null; |
| 70 | + if (stream == Stream.Null) return; |
| 71 | + await TargetProvider.SaveFileAsync(Path.GetFileName(selectedFile.FullPath), stream); |
| 72 | + } |
| 73 | + finally |
| 74 | + { |
| 75 | + _isCopying = false; |
| 76 | + StateHasChanged(); |
| 77 | + } |
55 | 78 | } |
56 | 79 |
|
57 | 80 | private async Task OpenSelected() |
58 | 81 | { |
59 | 82 | if (!EnableOpen || selectedFile == null) return; |
60 | | - await using var stream = await Provider.OpenReadAsync(selectedFile.FullPath) ?? Stream.Null; |
61 | | - if (stream == Stream.Null) return; |
62 | | - using var reader = new StreamReader(stream); |
63 | | - var content = await reader.ReadToEndAsync(); |
64 | | - GCodeDoc.SetGCode(content); |
| 83 | + _isOpening = true; |
| 84 | + StateHasChanged(); |
| 85 | + try |
| 86 | + { |
| 87 | + await using var stream = await Provider.OpenReadAsync(selectedFile.FullPath) ?? Stream.Null; |
| 88 | + if (stream == Stream.Null) return; |
| 89 | + using var reader = new StreamReader(stream); |
| 90 | + var content = await reader.ReadToEndAsync(); |
| 91 | + GCodeDoc.SetGCode(content); |
| 92 | + } |
| 93 | + finally |
| 94 | + { |
| 95 | + _isOpening = false; |
| 96 | + StateHasChanged(); |
| 97 | + } |
65 | 98 | } |
66 | 99 |
|
67 | 100 | private async Task DeleteSelected() |
|
108 | 141 | { |
109 | 142 | var uploadId = $"fileUpload-{Title?.Replace(" ", string.Empty)}"; |
110 | 143 | <div class="input-group input-group-sm" style="max-width: 260px;"> |
111 | | - <InputFile id="@uploadId" class="form-control" OnChange="OnFileSelected" /> |
| 144 | + <InputFile id="@uploadId" class="form-control" OnChange="OnFileSelected" disabled="@_isUploading" /> |
112 | 145 | <label class="input-group-text" for="@uploadId"> |
113 | | - <i class="bi bi-upload me-1"></i>Upload |
| 146 | + @if (_isUploading) |
| 147 | + { |
| 148 | + <span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span> |
| 149 | + } |
| 150 | + else |
| 151 | + { |
| 152 | + <i class="bi bi-upload me-1"></i> |
| 153 | + } |
| 154 | + @Localizer[Resources.StorageExplorer_Upload] |
114 | 155 | </label> |
115 | 156 | </div> |
116 | 157 | } |
|
120 | 161 | </button> |
121 | 162 | @if (EnableCopy) |
122 | 163 | { |
123 | | - <button class="btn btn-sm btn-outline-success" @onclick="CopySelected" disabled="@(selectedFile == null)"> |
124 | | - <i class="bi bi-arrow-left-right"></i> |
| 164 | + <button class="btn btn-sm btn-outline-success" @onclick="CopySelected" disabled="@(selectedFile == null || _isCopying)"> |
| 165 | + @if (_isCopying) |
| 166 | + { |
| 167 | + <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> |
| 168 | + } |
| 169 | + else |
| 170 | + { |
| 171 | + <i class="bi bi-arrow-left-right"></i> |
| 172 | + } |
125 | 173 | </button> |
126 | 174 | } |
127 | 175 | @if (EnableOpen) |
128 | 176 | { |
129 | | - <button class="btn btn-sm btn-outline-info" @onclick="OpenSelected" disabled="@(selectedFile == null)"> |
130 | | - <i class="bi bi-eye"></i> |
| 177 | + <button class="btn btn-sm btn-outline-info" @onclick="OpenSelected" disabled="@(selectedFile == null || _isOpening)"> |
| 178 | + @if (_isOpening) |
| 179 | + { |
| 180 | + <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + <i class="bi bi-eye"></i> |
| 185 | + } |
131 | 186 | </button> |
132 | 187 | } |
133 | 188 | @if (EnableDelete) |
|
155 | 210 | <tr> |
156 | 211 | <td colspan="5" class="text-center"> |
157 | 212 | <div class="spinner-border text-primary" role="status"> |
158 | | - <span class="visually-hidden">Loading...</span> |
| 213 | + <span class="visually-hidden">@Localizer[Resources.StorageExplorer_Loading]</span> |
159 | 214 | </div> |
160 | 215 | </td> |
161 | 216 | </tr> |
|
0 commit comments