Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add focus tweaks to Credentials AddEdit page (#164)

Leendert de Borst881eb58a35a4
diff --git a/src/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor b/src/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
index 40819dc87..0760f9350 100644
--- a/src/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
+++ b/src/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
@@ -25,7 +25,7 @@
<ValidationMessage For="() => Model.ServiceUrl"/>
</div>
<div class="flex justify-between items-center">
- <button id="quickIdentitySubmit" type="submit" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
+ <button id="quickIdentitySubmit" type="submit" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
Create
</button>
</div>
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
index b00c32353..1d6986a80 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
@@ -8,6 +8,8 @@
@using AliasGenerators.Identity
@using AliasGenerators.Identity.Implementations
@using AliasGenerators.Identity.Models
+@inject IJSRuntime JSRuntime
+@implements IAsyncDisposable
@if (EditMode)
{
@@ -53,7 +55,7 @@ else
<DataAnnotationsValidator />
<div class="grid grid-cols-3 px-4 pt-6 lg:gap-4 dark:bg-gray-900">
<div class="col-1">
- <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
+ <div class="p-4 mb-4 bg-white border-2 border-primary-600 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<h3 class="mb-4 text-xl font-semibold dark:text-white">Service</h3>
<div class="grid gap-6">
<div class="col-span-6 sm:col-span-3">
@@ -61,7 +63,7 @@ else
<ValidationMessage For="() => Obj.ServiceName"/>
</div>
<div class="col-span-6 sm:col-span-3">
- <EditFormRow Id="service-url" Label="Service URL" @bind-Value="Obj.ServiceUrl"></EditFormRow>
+ <EditFormRow Id="service-url" OnFocus="OnFocusUrlInput" Label="Service URL" @bind-Value="Obj.ServiceUrl"></EditFormRow>
</div>
</div>
</div>
@@ -150,10 +152,22 @@ else
[Parameter]
public Guid? Id { get; set; }
+ private const string DefaultServiceUrl = "https://";
private bool EditMode { get; set; }
private EditForm EditFormRef { get; set; } = null!;
private bool Loading { get; set; } = true;
private CredentialEdit Obj { get; set; } = new();
+ private IJSObjectReference? Module;
+
+ /// <inheritdoc />
+ async ValueTask IAsyncDisposable.DisposeAsync()
+ {
+ await KeyboardShortcutService.UnregisterShortcutAsync("gc");
+ if (Module is not null)
+ {
+ await Module.DisposeAsync();
+ }
+ }
/// <inheritdoc />
protected override void OnInitialized()
@@ -193,6 +207,7 @@ else
if (firstRender)
{
+ Module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/modules/newIdentityWidget.js");
if (EditMode)
{
if (Id is null)
@@ -214,6 +229,10 @@ else
}
Obj = CredentialToCredentialEdit(alias);
+ if (Obj.ServiceUrl is null)
+ {
+ Obj.ServiceUrl = DefaultServiceUrl;
+ }
}
else
{
@@ -225,13 +244,37 @@ else
alias.Passwords = new List<Password> { new Password() };
Obj = CredentialToCredentialEdit(alias);
+ Obj.ServiceUrl = DefaultServiceUrl;
}
Loading = false;
StateHasChanged();
+
+ if (!EditMode)
+ {
+ // When creating a new identity: start with focus on the service name input.
+ await JsInteropService.FocusElementById("service-name");
+ }
}
}
+ /// <summary>
+ /// When the URL input is focused, place cursor at the end of the default URL to allow for easy typing.
+ /// </summary>
+ private void OnFocusUrlInput(FocusEventArgs e)
+ {
+ if (Obj.ServiceUrl != DefaultServiceUrl)
+ {
+ return;
+ }
+
+ // Use a small delay to ensure the focus is set after the browser's default behavior.
+ Task.Delay(1).ContinueWith(_ =>
+ {
+ JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('service-url').setSelectionRange({DefaultServiceUrl.Length}, {DefaultServiceUrl.Length})");
+ });
+ }
+
private void HandleAttachmentsChanged(List<Attachment> updatedAttachments)
{
Obj.Attachments = updatedAttachments;
diff --git a/src/AliasVault.Client/Main/Pages/Emails/Home.razor b/src/AliasVault.Client/Main/Pages/Emails/Home.razor
index 6bf03e831..0059d6246 100644
--- a/src/AliasVault.Client/Main/Pages/Emails/Home.razor
+++ b/src/AliasVault.Client/Main/Pages/Emails/Home.razor
@@ -31,6 +31,14 @@
{
<LoadingIndicator/>
}
+else if (NoEmailClaims)
+{
+ <div class="p-4 mx-4 mt-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 dark:bg-gray-800">
+ <div class="px-4 py-2 text-gray-400 rounded">
+ <p class="text-gray-500 dark:text-gray-400">You are not using any private email addresses (yet). Create a new identity and use a private email address supported by AliasVault. All emails received by these private email addresses will show up here.</p>
+ </div>
+ </div>
+}
else
{
<div class="overflow-x-auto px-4">
@@ -41,32 +49,40 @@ else
<h2 class="font-semibold text-gray-800">Inbox</h2>
</div>
<ul class="divide-y divide-gray-200">
- @foreach (var email in EmailList)
+ @if (EmailList.Count == 0)
{
- <li class="hover:bg-gray-50 transition duration-150 ease-in-out">
- <div @onclick="() => ShowAliasVaultEmailInModal(email.Id)" class="p-4 flex justify-start items-start">
- <div class="mr-4 flex-shrink-0">
- <SenderInitials SenderName="@email.FromName" SenderEmail="@email.FromEmail" />
- </div>
- <div class="flex-grow">
- <div class="flex items-center justify-between mb-2 mr-4">
- <div>
- <div class="text-gray-800 mb-2">
- @email.Subject
+ <li class="p-4 text-center text-gray-500">
+ No emails have been received yet.
+ </li>
+ }
+ else
+ {
+ @foreach (var email in EmailList)
+ {
+ <li class="hover:bg-gray-50 transition duration-150 ease-in-out">
+ <div @onclick="() => ShowAliasVaultEmailInModal(email.Id)" class="p-4 flex justify-start items-start">
+ <div class="mr-4 flex-shrink-0">
+ <SenderInitials SenderName="@email.FromName" SenderEmail="@email.FromEmail" />
+ </div>
+ <div class="flex-grow">
+ <div class="flex items-center justify-between mb-2 mr-4">
+ <div>
+ <div class="text-gray-800 mb-2">
+ @email.Subject
+ </div>
+ <div class="text-sm text-gray-400 line-clamp-2">
+ @email.MessagePreview
+ </div>
</div>
- <div class="text-sm text-gray-400 line-clamp-2">
- @email.MessagePreview
+ <div class="flex justify-end">
+ <div @onclick="() => NavigateToCredential(email.CredentialId)" class="text-sm text-gray-700 cursor-pointer mr-4 hover:underline">@email.CredentialName</div>
+ <div class="text-sm text-gray-500">@email.Date.ToString("yyyy-MM-dd")</div>
</div>
</div>
- <div class="flex justify-end">
- <div @onclick="() => NavigateToCredential(email.CredentialId)" class="text-sm text-gray-700 cursor-pointer mr-4 hover:underline">@email.CredentialName</div>
- <div class="text-sm text-gray-500">@email.Date.ToString("yyyy-MM-dd")</div>
- </div>
</div>
-
</div>
- </div>
- </li>
+ </li>
+ }
}
</ul>
</div>
@@ -80,6 +96,7 @@ else
private int PageSize { get; set; } = 50;
private int TotalRecords { get; set; }
private bool EmailModalVisible { get; set; }
+ private bool NoEmailClaims { get; set; }
private EmailApiModel EmailModalEmail { get; set; } = new();
/// <inheritdoc />
@@ -102,6 +119,7 @@ else
private async Task RefreshData()
{
IsLoading = true;
+ NoEmailClaims = false;
StateHasChanged();
var emailClaimList = await DbService.GetEmailClaimListAsync();
@@ -109,6 +127,7 @@ else
if (emailClaimList.Count == 0)
{
IsLoading = false;
+ NoEmailClaims = true;
StateHasChanged();
return;
}
diff --git a/src/AliasVault.Client/Services/CredentialService.cs b/src/AliasVault.Client/Services/CredentialService.cs
index 7242bdf57..0dda4d20f 100644
--- a/src/AliasVault.Client/Services/CredentialService.cs
+++ b/src/AliasVault.Client/Services/CredentialService.cs
@@ -325,6 +325,20 @@ public sealed class CredentialService(HttpClient httpClient, DbService dbService
.FirstAsync();
context.Credentials.Remove(login);
+
+ // Also remove associated alias and service. Later when
+ // aliases and services are shared between credentials, this
+ // should be removed.
+ var alias = await context.Aliases
+ .Where(x => x.Id == login.Alias.Id)
+ .FirstAsync();
+ context.Aliases.Remove(alias);
+
+ var service = await context.Services
+ .Where(x => x.Id == login.Service.Id)
+ .FirstAsync();
+ context.Services.Remove(service);
+
await context.SaveChangesAsync();
await dbService.SaveDatabaseAsync();
}
diff --git a/src/AliasVault.Client/wwwroot/css/tailwind.css b/src/AliasVault.Client/wwwroot/css/tailwind.css
index f7461b6da..fd0306c66 100644
--- a/src/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/src/AliasVault.Client/wwwroot/css/tailwind.css
@@ -1306,6 +1306,16 @@ video {
border-color: rgb(248 185 99 / var(--tw-border-opacity));
}
+.border-primary-500 {
+ --tw-border-opacity: 1;
+ border-color: rgb(244 149 65 / var(--tw-border-opacity));
+}
+
+.border-primary-600 {
+ --tw-border-opacity: 1;
+ border-color: rgb(214 131 56 / var(--tw-border-opacity));
+}
+
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));