diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor b/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor index 82e4609..ebf5eee 100644 --- a/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor +++ b/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor @@ -3,34 +3,4 @@ @inject NavigationManager nav @inject AppState state -

@message

- -@code { - string message = "Logging you on with No Agenda Social..."; - - protected override async Task OnInitializedAsync() - { - // Exchange authorization code for a JWT - var query = QueryHelpers.ParseQuery(nav.ToAbsoluteUri(nav.Uri).Query); - if (query.TryGetValue("code", out var authCode)) - { - var logOnResult = await ServerApi.LogOn(http, authCode); - - if (logOnResult.IsOk) - { - var logOn = logOnResult.Ok; - state.User = new UserInfo(logOn.CitizenId, logOn.Name); - state.Jwt = logOn.Jwt; - nav.NavigateTo("/citizen/dashboard"); - } - else - { - message = logOnResult.Error; - } - } - else - { - message = "Did not receive a token from No Agenda Social (perhaps you clicked \"Cancel\"?)"; - } - } -} +

@Message

diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor.cs b/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor.cs new file mode 100644 index 0000000..06d6c2c --- /dev/null +++ b/src/JobsJobsJobs/Client/Pages/Citizen/Authorized.razor.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.WebUtilities; +using System.Threading.Tasks; + +namespace JobsJobsJobs.Client.Pages.Citizen +{ + public partial class Authorized : ComponentBase + { + /// + /// The message to be displayed on this page + /// + private string Message { get; set; } = "Logging you on with No Agenda Social..."; + + protected override async Task OnInitializedAsync() + { + // Exchange authorization code for a JWT + var query = QueryHelpers.ParseQuery(nav.ToAbsoluteUri(nav.Uri).Query); + if (query.TryGetValue("code", out var authCode)) + { + var logOnResult = await ServerApi.LogOn(http, authCode); + + if (logOnResult.IsOk) + { + var logOn = logOnResult.Ok; + state.User = new UserInfo(logOn.CitizenId, logOn.Name); + state.Jwt = logOn.Jwt; + nav.NavigateTo("/citizen/dashboard"); + } + else + { + Message = logOnResult.Error; + } + } + else + { + Message = "Did not receive a token from No Agenda Social (perhaps you clicked \"Cancel\"?)"; + } + } + } +} diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor b/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor index 59e4a78..ecf4dc1 100644 --- a/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor +++ b/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor @@ -1,6 +1,8 @@ @page "/citizen/dashboard" +@inject HttpClient http +@inject AppState state -

Welcome, @State.User!.Name!

+

Welcome, @state.User!.Name!

@if (RetrievingData) { @@ -8,34 +10,25 @@ } else { - if (Profile != null) - { + + @if (Profile != null) + { +

+ Your employment profile was last updated . Your profile currently + lists @Profile.Skills.Length skill@(Profile.Skills.Length != 1 ? "s" : ""). +

+ } + else + { +

You do not have an employment profile established; click “Profile”* in the menu to get started!

+ }

- Your employment profile was last updated . Your profile currently - lists @SkillCount skill@(SkillCount != 1 ? "s" : ""). + There @(ProfileCount == 1 ? "is" : "are") @(ProfileCount == 0 ? "no" : ProfileCount) employment + profile@(ProfileCount != 1 ? "s" : "") from citizens of Gitmo Nation. + @if (ProfileCount > 0) + { + Take a look around and see if you can help them find work! + }

- } - else - { -

You do not have an employment profile established; click “Profile”* in the menu to get started!

- } -

- There @(ProfileCount == 1 ? "is" : "are") @(ProfileCount == 0 ? "no" : ProfileCount) employment - profile@(ProfileCount != 1 ? "s" : "") from citizens of Gitmo Nation. - @if (ProfileCount > 0) - { - Take a look around and see if you can help them find work! - } -

-} - -@if (ErrorMessages.Count > 0) -{ -

The following error(s) occurred:

-

- @foreach (var msg in ErrorMessages) - { - @msg
- } -

+
} diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor.cs b/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor.cs index 79ba0cc..71dccac 100644 --- a/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor.cs +++ b/src/JobsJobsJobs/Client/Pages/Citizen/Dashboard.razor.cs @@ -1,9 +1,8 @@ -using JobsJobsJobs.Shared; -using JobsJobsJobs.Shared.Api; +using JobsJobsJobs.Shared.Api; using Microsoft.AspNetCore.Components; using System.Collections.Generic; -using System.Net.Http; using System.Threading.Tasks; +using Domain = JobsJobsJobs.Shared; namespace JobsJobsJobs.Client.Pages.Citizen { @@ -20,46 +19,27 @@ namespace JobsJobsJobs.Client.Pages.Citizen /// /// The user's profile /// - private Profile? Profile { get; set; } = null; - - /// - /// The number of skills in the user's profile - /// - private long SkillCount { get; set; } = 0L; + private Domain.Profile? Profile { get; set; } = null; /// /// The number of profiles /// - private long ProfileCount { get; set; } = 0L; + private int ProfileCount { get; set; } /// /// Error messages from data access /// private IList ErrorMessages { get; } = new List(); - /// - /// The HTTP client to use for API access - /// - [Inject] - public HttpClient Http { get; set; } = default!; - - /// - /// The current application state - /// - [Inject] - public AppState State { get; set; } = default!; - - protected override async Task OnInitializedAsync() { - if (State.User != null) + if (state.User != null) { - ServerApi.SetJwt(Http, State); - var profileTask = ServerApi.RetrieveProfile(Http, State); - var profileCountTask = ServerApi.RetrieveOne(Http, "profile/count"); - var skillCountTask = ServerApi.RetrieveOne(Http, "profile/skill-count"); + ServerApi.SetJwt(http, state); + var profileTask = ServerApi.RetrieveProfile(http, state); + var profileCountTask = ServerApi.RetrieveOne(http, "profile/count"); - await Task.WhenAll(profileTask, profileCountTask, skillCountTask); + await Task.WhenAll(profileTask, profileCountTask); if (profileTask.Result.IsOk) { @@ -79,18 +59,8 @@ namespace JobsJobsJobs.Client.Pages.Citizen ErrorMessages.Add(profileCountTask.Result.Error); } - if (skillCountTask.Result.IsOk) - { - SkillCount = skillCountTask.Result.Ok?.Value ?? 0; - } - else - { - ErrorMessages.Add(skillCountTask.Result.Error); - } - RetrievingData = false; } } - } } diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor b/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor index ac2d451..e652248 100644 --- a/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor +++ b/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor @@ -1,4 +1,7 @@ @page "/citizen/profile" +@inject HttpClient http +@inject AppState state +@inject IToastService toast

Employment Profile

@@ -14,12 +17,12 @@ } else { - +
- +
@@ -28,22 +31,22 @@
- + @foreach (var (id, name) in Continents) { } - + ProfileForm.ContinentId) />
- - + ProfileForm.Region) />
@@ -51,21 +54,21 @@
- - + + ProfileForm.Biography) />
- +
- +
@@ -73,11 +76,11 @@

Skills   - +

@foreach (var skill in ProfileForm.Skills) { - + }

Experience

@@ -88,13 +91,13 @@

- +
- + diff --git a/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs b/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs index 251c5f6..1a3f637 100644 --- a/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs +++ b/src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs @@ -1,10 +1,8 @@ -using Blazored.Toast.Services; -using JobsJobsJobs.Shared; +using JobsJobsJobs.Shared; using JobsJobsJobs.Shared.Api; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; @@ -40,32 +38,13 @@ namespace JobsJobsJobs.Client.Pages.Citizen /// private IList ErrorMessages { get; } = new List(); - /// - /// HTTP client instance to use for API access - /// - [Inject] - private HttpClient Http { get; set; } = default!; - - /// - /// Application state - /// - [Inject] - private AppState State { get; set; } = default!; - - /// - /// Toast service - /// - [Inject] - private IToastService Toasts { get; set; } = default!; - protected override async Task OnInitializedAsync() { - ServerApi.SetJwt(Http, State); - var continentTask = ServerApi.RetrieveMany(Http, "continent/all"); - var profileTask = ServerApi.RetrieveProfile(Http, State); - var skillTask = ServerApi.RetrieveMany(Http, "profile/skills"); + ServerApi.SetJwt(http, state); + var continentTask = ServerApi.RetrieveMany(http, "continent/all"); + var profileTask = ServerApi.RetrieveProfile(http, state); - await Task.WhenAll(continentTask, profileTask, skillTask); + await Task.WhenAll(continentTask, profileTask); if (continentTask.Result.IsOk) { @@ -81,28 +60,11 @@ namespace JobsJobsJobs.Client.Pages.Citizen ProfileForm = (profileTask.Result.Ok == null) ? new ProfileForm() : ProfileForm.FromProfile(profileTask.Result.Ok); - } - else - { - ErrorMessages.Add(profileTask.Result.Error); - } - - if (skillTask.Result.IsOk) - { - foreach (var skill in skillTask.Result.Ok) - { - ProfileForm.Skills.Add(new SkillForm - { - Id = skill.Id.ToString(), - Description = skill.Description, - Notes = skill.Notes ?? "" - }); - } if (ProfileForm.Skills.Count == 0) AddNewSkill(); } else { - ErrorMessages.Add(skillTask.Result.Error); + ErrorMessages.Add(profileTask.Result.Error); } AllLoaded = true; @@ -132,16 +94,16 @@ namespace JobsJobsJobs.Client.Pages.Citizen .ToList(); foreach (var blankSkill in blankSkills) ProfileForm.Skills.Remove(blankSkill); - var res = await Http.PostAsJsonAsync("/api/profile/save", ProfileForm); + var res = await http.PostAsJsonAsync("/api/profile/save", ProfileForm); if (res.IsSuccessStatusCode) { - Toasts.ShowSuccess("Profile Saved Successfully"); + toast.ShowSuccess("Profile Saved Successfully"); } else { var error = await res.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(error)) error = $"- {error}"; - Toasts.ShowError($"{(int)res.StatusCode} {error}"); + toast.ShowError($"{(int)res.StatusCode} {error}"); } } diff --git a/src/JobsJobsJobs/Client/Pages/Index.razor b/src/JobsJobsJobs/Client/Pages/Index.razor index 726e469..d99f9a8 100644 --- a/src/JobsJobsJobs/Client/Pages/Index.razor +++ b/src/JobsJobsJobs/Client/Pages/Index.razor @@ -10,7 +10,7 @@ Do you not understand the terms in the paragraph above? No worries; just head over to The Best Podcast in the Universe - (it’s true!) and find out what you’re missing. + (it’s true!) and find out what you’re missing.