Added character counter and alert for new statuses

This commit is contained in:
Gordon Pedersen 2024-07-16 09:47:42 +10:00
parent 1bf7e74a5a
commit 859f8348f0
3 changed files with 19 additions and 5 deletions

View file

@ -3,5 +3,6 @@
namespace Neighbourhood.omg.lol { namespace Neighbourhood.omg.lol {
public class NavigatorService { public class NavigatorService {
internal NavigationManager? NavigationManager { get; set; } internal NavigationManager? NavigationManager { get; set; }
internal Page? Page { get; set; }
} }
} }

View file

@ -2,6 +2,7 @@
@inject State State @inject State State
@inject RestService api @inject RestService api
@inject NavigationManager navigationManager @inject NavigationManager navigationManager
@inject NavigatorService navigatorService
<div class="overlay @(Active ? "active" : string.Empty)" data-ui="#@id"></div> <div class="overlay @(Active ? "active" : string.Empty)" data-ui="#@id"></div>
<dialog id="@id" class="@(Active ? "active" : string.Empty)" open="@Active"> <dialog id="@id" class="@(Active ? "active" : string.Empty)" open="@Active">
@ -27,7 +28,8 @@
</button> </button>
</div> </div>
<div class="field textarea border max"> <div class="field textarea border max">
<InputTextArea @bind-Value="Content"></InputTextArea> <textarea @bind="@Content" @bind:event="oninput" />
<div class="right-align"><small class="@( Content.Length >= 500 ? "red" : Content.Length >= 260 ? "yellow-text" : "")">@Content.Length / 500</small></div>
</div> </div>
</div> </div>
<nav class="right-align no-space"> <nav class="right-align no-space">
@ -66,16 +68,26 @@
public async Task PostStatus() { public async Task PostStatus() {
StatusPost post = new StatusPost StatusPost post = new StatusPost {
{
Emoji = Emoji, Emoji = Emoji,
Content = Content Content = Content
}; };
if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false){ if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false) {
post.SkipMastodonPost = !postToMastodon; post.SkipMastodonPost = !postToMastodon;
} }
if(Content.Length >= 500) {
bool answer = await navigatorService.Page!.DisplayAlert(
"Character limit reached",
"Your message is over 500 characters, which is a lot for a status.\n"
+ ((postToMastodon && !(post.SkipMastodonPost ?? true))? "If you continue, your post will not make it over to Mastodon.\n" : "")
+ "Do you wish to post it anyway?",
"Yes", "No"
);
if (!answer) return;
}
loading = true; loading = true;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
var result = await api.StatusPost(State!.SelectedAddressName!, post); var result = await api.StatusPost(State!.SelectedAddressName!, post);

View file

@ -18,7 +18,8 @@ namespace Neighbourhood.omg.lol {
protected override Window CreateWindow(IActivationState? activationState) { protected override Window CreateWindow(IActivationState? activationState) {
// always create new windows. This allows share intents to not crash on android // always create new windows. This allows share intents to not crash on android
// (with the side effect that multiple windows are opened, which is messy but better than a crash) // (with the side effect that multiple windows are opened, which is messy but better than a crash)
return new Window(new AppShell()); NavigatorService.Page = new AppShell();
return new Window(NavigatorService.Page);
} }
} }
} }