Skip to content

Commit

Permalink
Add email to user information display
Browse files Browse the repository at this point in the history
Add user's email to the UI of PresenceLight.

* Add a new property `Email` to `AppState` in `src/PresenceLight.Core/Configuration/AppState.cs` to store the user's email.
* Create `GetProfileAndPresenceHandler` in `src/PresenceLight.Core/GraphServices/GetProfileAndPresenceHandler.cs` to extract and return the user's email.
* Modify `MainWindow.xaml.cs` in `src/DesktopClient/PresenceLight/MainWindow.xaml.cs` to retrieve and store the user's email in the `AppState`.
* Update `LoginDisplay.razor` in `src/PresenceLight.Razor/Components/Shared/LoginDisplay.razor` to display the user's email along with their name.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/isaacrlevin/presencelight?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
isaacrlevin committed Sep 17, 2024
1 parent 23969bd commit b18c99f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/DesktopClient/PresenceLight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private async Task InteractWithLights()
{
if (_appState.User == null || string.IsNullOrEmpty(_appState.User.DisplayName))
{
var (profile, presence) = await _mediator.Send(new Core.GraphServices.GetProfileAndPresenceCommand());
var (profile, presence, email) = await _mediator.Send(new Core.GraphServices.GetProfileAndPresenceCommand());

var photo = await GetPhoto();

Expand All @@ -506,6 +506,8 @@ private async Task InteractWithLights()
MapUI(presence);
_appState.SetUserInfo(profile, presence, $"data:image/gif;base64,{Convert.ToBase64String(photo)}");
}

_appState.Email = email;
}
await Task.Delay(Convert.ToInt32(_appState.Config.LightSettings.PollingInterval * 1000));

Expand Down
6 changes: 6 additions & 0 deletions src/PresenceLight.Core/Configuration/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public class AppState
/// </summary>
public BaseConfig Config { get; set; } = new BaseConfig();

/// <summary>
/// Gets or sets the user's email.
/// </summary>
public string Email { get; set; }

/// <summary>
/// Sets the configuration.
/// </summary>
Expand All @@ -135,6 +140,7 @@ public void SetUserInfo(User? user, Presence? presence, string? photo = null)
User = user;
Presence = presence;
ProfileImage = photo;
Email = user?.Mail;
NotifyStateChanged();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using MediatR;
using Microsoft.Graph.Models;
using System.Threading;
using System.Threading.Tasks;

namespace PresenceLight.Core.GraphServices
{
internal class GetProfileAndPresenceHandler : IRequestHandler<GetProfileAndPresenceCommand, (User User, Presence Presence, string Email)>
{
GraphWrapper _graph;

public GetProfileAndPresenceHandler(GraphWrapper graph)
{
_graph = graph;
}

public async Task<(User User, Presence Presence, string Email)> Handle(GetProfileAndPresenceCommand command, CancellationToken cancellationToken)
{
var (user, presence) = await _graph.GetProfileAndPresence(cancellationToken);
var email = user.Mail;
return (user, presence, email);
}
}
}
4 changes: 2 additions & 2 deletions src/PresenceLight.Razor/Components/Shared/LoginDisplay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
<MudMenu AnchorOrigin="Origin.CenterCenter" Dense="true" Class="mt-1 ml-4">
<ActivatorContent>
<MudText Typo="Typo.body2" Class="px-4 py-2"> Hello, @appState.User.DisplayName!</MudText>
<MudText Typo="Typo.body2" Class="px-4 py-2"> Hello, @appState.User.DisplayName! (@appState.Email)</MudText>
</ActivatorContent>
<ChildContent>
<MudListItem Text="Logout" Icon="@Icons.Material.Filled.Logout" OnClick="SignOut" />
Expand Down Expand Up @@ -80,4 +80,4 @@ else
{
InvokeAsync(StateHasChanged);
}
}
}

0 comments on commit b18c99f

Please sign in to comment.