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)"> <Assistant HeaderText="Create new project" IconName="add-project.svg" BaseHeight="new Assistant.Height(40, 55, 40)">
<div class="mb-3"> <div class="mb-3">
<label for="projectName" class="form-label fw-bold">Project Name:</label> <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> </div>
@if (DeviceInfo.Idiom == DeviceIdiom.Desktop) @if (DeviceInfo.Idiom == DeviceIdiom.Desktop)
@ -38,5 +38,5 @@
</div> </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> </Assistant>

View File

@ -7,6 +7,7 @@ public partial class LoadProject
{ {
private readonly List<RecentProject> recentProjects = new(); private readonly List<RecentProject> recentProjects = new();
private string newProjectName = string.Empty;
private string newProjectDestination = string.Empty; private string newProjectDestination = string.Empty;
#region Overrides of ComponentBase #region Overrides of ComponentBase
@ -39,6 +40,8 @@ public partial class LoadProject
private Task ChooseProjectDestination() private Task ChooseProjectDestination()
{ {
try
{
#if WINDOWS #if WINDOWS
return this.ChooseProjectDestinationWindows(); return this.ChooseProjectDestinationWindows();
#elif MACCATALYST #elif MACCATALYST
@ -47,9 +50,26 @@ public partial class LoadProject
return Task.CompletedTask; return Task.CompletedTask;
#endif #endif
} }
finally
{
this.StateHasChanged();
}
}
private Task CreateProject() private Task CreateProject()
{ {
return Task.CompletedTask; 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();
} }