Share new status (from share target, Android)

This commit is contained in:
Gordon Pedersen 2024-06-18 11:58:51 +10:00
parent 413051ad4c
commit 63d844e7a3
2 changed files with 63 additions and 19 deletions

View file

@ -1,14 +1,15 @@
@inject IJSRuntime JS @inject IJSRuntime JS
@inject State State @inject State State
@inject RestService api @inject RestService api
@inject NavigationManager navigationManager
<div class="overlay" data-ui="#@id"></div> <div class="overlay @(Active ? "active" : string.Empty)" data-ui="#@id"></div>
<dialog id="@id"> <dialog id="@id" class="@(Active ? "active" : string.Empty)" open="@Active">
<h5>Share your status</h5> <h5>Share your status</h5>
<div class="row"> <div class="row">
<div class="min square extra"> <div class="min square extra">
<button class="transparent square extra no-margin"> <button class="transparent square extra no-margin">
<object id="status-emoji" class="large emoji @(statusEmoji == null ? "animated" : string.Empty)" data-emoji="@(statusEmoji ?? "🫥")">@(statusEmoji ?? "🫥")</object> <object id="status-emoji" class="large emoji @(Emoji == null ? "animated" : string.Empty)" data-emoji="@(Emoji ?? "🫥")">@(Emoji ?? "🫥")</object>
<menu class="no-wrap"> <menu class="no-wrap">
<script type="module" src="https://cdn.jsdelivr.net/npm/emoji-picker-element@@^1/index.js"></script> <script type="module" src="https://cdn.jsdelivr.net/npm/emoji-picker-element@@^1/index.js"></script>
<emoji-picker emoji-version="15.1"></emoji-picker> <emoji-picker emoji-version="15.1"></emoji-picker>
@ -26,7 +27,7 @@
</button> </button>
</div> </div>
<div class="field textarea border max"> <div class="field textarea border max">
<InputTextArea @bind-Value="statusContent"></InputTextArea> <InputTextArea @bind-Value="Content"></InputTextArea>
</div> </div>
</div> </div>
<nav class="right-align no-space"> <nav class="right-align no-space">
@ -36,7 +37,7 @@
<span>Post this to Mastodon</span> <span>Post this to Mastodon</span>
</label> </label>
} }
<InputText id="status-emoji-input" class="invisible" @bind-Value="statusEmoji"></InputText> <InputText id="status-emoji-input" class="invisible" @bind-Value="Emoji"></InputText>
<button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button> <button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button>
<button @onclick="PostStatus" disabled="@loading"> <button @onclick="PostStatus" disabled="@loading">
@if (loading) { @if (loading) {
@ -50,20 +51,25 @@
</dialog> </dialog>
@code { @code {
private string statusContent = string.Empty;
private string? statusEmoji = null;
private bool postToMastodon = true;
private bool loading = false;
[Parameter] [Parameter]
public string id { get; set; } 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() { public async Task PostStatus() {
await JS.InvokeVoidAsync("console.log", "hey from post status");
StatusPost post = new StatusPost StatusPost post = new StatusPost
{ {
Emoji = statusEmoji, Emoji = Emoji,
Content = statusContent Content = Content
}; };
if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false){ if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false){
@ -71,15 +77,18 @@
} }
loading = true; loading = true;
InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
var result = await api.StatusPost(State.SelectedAddressName, post); var result = await api.StatusPost(State!.SelectedAddressName!, post);
if(result != null){ 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); await JS.InvokeVoidAsync("ui", "#" + id);
statusContent = string.Empty; Content = string.Empty;
statusEmoji = null; Emoji = null;
postToMastodon = true; postToMastodon = true;
loading = false; loading = false;
} }

View file

@ -1,10 +1,45 @@
@page "/sharetext/{Text}" @page "/sharetext/{Text}"
@inject NavigationManager navigationManager
@inject AuthenticationStateProvider AuthStateProvider
<h3>Sharing</h3> <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>
<p>@Text</p> <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 { @code {
[Parameter] [Parameter]
public string Text { get; set; } 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<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;
}
}
} }