Made create project button aware of user input's state

This commit is contained in:
Thorsten Sommer 2022-08-15 21:03:01 +02:00
parent d77994b18b
commit c867514211
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 25 additions and 5 deletions

View File

@ -24,7 +24,7 @@
<Assistant HeaderText="Create new project" IconName="add-project.svg" BaseHeight="new Assistant.Height(40, 55, 40)">
<div class="mb-3">
<label for="projectName" class="form-label fw-bold">Project Name:</label>
<input type="text" class="form-control" id="projectName" placeholder="Type a project name">
<input type="text" class="form-control" id="projectName" placeholder="Type a project name" @bind="this.newProjectName" @bind:event="oninput" @onkeydown="this.ReevaluateState">
</div>
@if (DeviceInfo.Idiom == DeviceIdiom.Desktop)
@ -38,5 +38,5 @@
</div>
}
<button class="btn btn-secondary" type="button" @onclick="this.CreateProject">Create project</button>
<button class="btn btn-secondary" type="button" @onclick="this.CreateProject" disabled="@this.CannotCreateProject()">Create project</button>
</Assistant>

View File

@ -7,6 +7,7 @@ public partial class LoadProject
{
private readonly List<RecentProject> recentProjects = new();
private string newProjectName = string.Empty;
private string newProjectDestination = string.Empty;
#region Overrides of ComponentBase
@ -39,6 +40,8 @@ public partial class LoadProject
private Task ChooseProjectDestination()
{
try
{
#if WINDOWS
return this.ChooseProjectDestinationWindows();
#elif MACCATALYST
@ -47,9 +50,26 @@ public partial class LoadProject
return Task.CompletedTask;
#endif
}
finally
{
this.StateHasChanged();
}
}
private Task CreateProject()
{
return Task.CompletedTask;
}
private bool CannotCreateProject()
{
if (DeviceInfo.Idiom == DeviceIdiom.Desktop)
return string.IsNullOrWhiteSpace(this.newProjectName) || string.IsNullOrWhiteSpace(this.newProjectDestination);
else if (DeviceInfo.Idiom == DeviceIdiom.Phone || DeviceInfo.Idiom == DeviceIdiom.Tablet)
return string.IsNullOrWhiteSpace(this.newProjectName);
else
return true;
}
private void ReevaluateState() => this.StateHasChanged();
}