diff --git a/Components/NewStatusDialog.razor b/Components/NewStatusDialog.razor index 7d8c07f..f02314a 100644 --- a/Components/NewStatusDialog.razor +++ b/Components/NewStatusDialog.razor @@ -1,14 +1,15 @@ @inject IJSRuntime JS @inject State State @inject RestService api +@inject NavigationManager navigationManager -
- +
+
Share your status
- +
@code { - private string statusContent = string.Empty; - private string? statusEmoji = null; - private bool postToMastodon = true; - private bool loading = false; [Parameter] public string id { get; set; } + [Parameter] + public bool Active { get; set; } + [Parameter] + public string Content { get; set; } = string.Empty; + [Parameter] + public string? Emoji { get; set; } = null; + [Parameter] + public bool postToMastodon { get; set; } = true; + + private bool loading = false; public async Task PostStatus() { - await JS.InvokeVoidAsync("console.log", "hey from post status"); StatusPost post = new StatusPost { - Emoji = statusEmoji, - Content = statusContent + Emoji = Emoji, + Content = Content }; if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false){ @@ -71,15 +77,18 @@ } loading = true; - InvokeAsync(StateHasChanged); - var result = await api.StatusPost(State.SelectedAddressName, post); + await InvokeAsync(StateHasChanged); + var result = await api.StatusPost(State!.SelectedAddressName!, post); if(result != null){ - State.RefreshStatuses().ContinueWith(t => InvokeAsync(StateHasChanged)); + await State.RefreshStatuses(); + await InvokeAsync(StateHasChanged); + navigationManager.NavigateTo("/statuslog/latest"); } + this.Active = false; await JS.InvokeVoidAsync("ui", "#" + id); - statusContent = string.Empty; - statusEmoji = null; + Content = string.Empty; + Emoji = null; postToMastodon = true; loading = false; } diff --git a/Components/Pages/ShareText.razor b/Components/Pages/ShareText.razor index 6dc7747..1bf1b97 100644 --- a/Components/Pages/ShareText.razor +++ b/Components/Pages/ShareText.razor @@ -1,10 +1,45 @@ @page "/sharetext/{Text}" +@inject NavigationManager navigationManager +@inject AuthenticationStateProvider AuthStateProvider -

Sharing

+ + Share a post to status.lol + -

@Text

+ + + + + + @code { [Parameter] public string Text { get; set; } + + protected override async Task OnInitializedAsync() { + await checkLogin(); + } + + // protected override async Task OnAfterRenderAsync(bool firstRender) { + // await base.OnAfterRenderAsync(firstRender); + // if (firstRender && await checkLogin()) { + // await JS.InvokeVoidAsync("focusText"); + // } + // } + + private async Task checkLogin() { + var authState = await AuthStateProvider.GetAuthenticationStateAsync(); + var user = authState.User; + + if (user.Identity is not null && user.Identity.IsAuthenticated) { + return true; + } + else { + navigationManager.NavigateTo("/login"); + return false; + } + } }