Neighbourhood.omg.lol/Components/Pages/ShareText.razor

48 lines
1.3 KiB
Text
Raw Normal View History

@page "/sharetext"
@inject NavigationManager navigationManager
@inject AuthenticationStateProvider AuthStateProvider
@inject State State
<PageHeading title="Status.lol" icon="fa-solid fa-message-smile">
<Description>Share a post to <a href="https://status.lol">status.lol</a></Description>
</PageHeading>
<AuthorizeView>
<Authorized>
<button class="fab circle extra large-elevate" data-ui="#post-modal">
<i class="fa-solid fa-pen-to-square"></i>
</button>
<NewStatusDialog id="post-modal" Active="true" Content="@Text"></NewStatusDialog>
</Authorized>
</AuthorizeView>
@code {
public string? Text { get; set; }
protected override async Task OnInitializedAsync() {
await checkLogin();
Text = State.ShareString;
if (!string.IsNullOrWhiteSpace(State.ShareStringSubject)) {
Text = $"{State.ShareStringSubject}\n\n{State.ShareString}";
}
State.ShareStringSubject = null;
State.ShareString = null;
}
private async Task<bool> 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;
}
}
}