[frontend/components] Show an alert instead of crashing if renaming causes a conflict
This commit is contained in:
parent
1ee73e3648
commit
877d195fd7
1 changed files with 23 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
@using Iceshrimp.Shared.Schemas.Web
|
@using Iceshrimp.Shared.Schemas.Web
|
||||||
@using Microsoft.Extensions.Localization
|
@using Microsoft.Extensions.Localization
|
||||||
@using Iceshrimp.Assets.PhosphorIcons
|
@using Iceshrimp.Assets.PhosphorIcons
|
||||||
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
@inject ApiService Api;
|
@inject ApiService Api;
|
||||||
@inject IJSRuntime Js;
|
@inject IJSRuntime Js;
|
||||||
|
@ -106,11 +107,18 @@
|
||||||
var filename = await Js.InvokeAsync<string?>("prompt", "Rename file", File!.Filename);
|
var filename = await Js.InvokeAsync<string?>("prompt", "Rename file", File!.Filename);
|
||||||
if (string.IsNullOrWhiteSpace(filename)) return;
|
if (string.IsNullOrWhiteSpace(filename)) return;
|
||||||
|
|
||||||
var res = await Api.Drive.UpdateFileAsync(File!.Id, new UpdateDriveFileRequest { Filename = filename.Trim() });
|
try
|
||||||
if (res != null)
|
|
||||||
{
|
{
|
||||||
File.Filename = res.Filename;
|
var res = await Api.Drive.UpdateFileAsync(File!.Id, new UpdateDriveFileRequest { Filename = filename.Trim() });
|
||||||
StateHasChanged();
|
if (res != null)
|
||||||
|
{
|
||||||
|
File.Filename = res.Filename;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await Js.InvokeVoidAsync("alert", e.Response.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,11 +169,18 @@
|
||||||
var name = await Js.InvokeAsync<string?>("prompt", "Rename folder", Folder.Name);
|
var name = await Js.InvokeAsync<string?>("prompt", "Rename folder", Folder.Name);
|
||||||
if (string.IsNullOrWhiteSpace(name)) return;
|
if (string.IsNullOrWhiteSpace(name)) return;
|
||||||
|
|
||||||
var res = await Api.Drive.UpdateFolderAsync(Folder.Id, name.Trim());
|
try
|
||||||
if (res != null)
|
|
||||||
{
|
{
|
||||||
Folder.Name = res.Name;
|
var res = await Api.Drive.UpdateFolderAsync(Folder.Id, name.Trim());
|
||||||
StateHasChanged();
|
if (res != null)
|
||||||
|
{
|
||||||
|
Folder.Name = res.Name;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await Js.InvokeVoidAsync("alert", e.Response.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue