diff --git a/Classes/RestService.cs b/Classes/RestService.cs index cbbfb8c..91b5b7b 100644 --- a/Classes/RestService.cs +++ b/Classes/RestService.cs @@ -194,7 +194,7 @@ namespace Neighbourhood.omg.lol public async Task PutPic(string address, byte[] bytes) => await PutPic(address, Convert.ToBase64String(bytes)); - public async Task PostPicDescription(string address, string id, string description) => + public async Task PostPicDescription(string address, string id, string? description) => (await Post($"/address/{address}/pics/{id}", new PostPic { Description = description })); public async Task DeletePic(string address, string id) => (await Delete($"/address/{address}/pics/{id}")); diff --git a/Components/EditPicDialog.razor b/Components/EditPicDialog.razor index 87ce719..1dcaeb2 100644 --- a/Components/EditPicDialog.razor +++ b/Components/EditPicDialog.razor @@ -52,10 +52,11 @@ public string? Description { get; set; } private bool loading = false; [Parameter] - public string id { get; set; } + public string? id { get; set; } private bool confirmDelete { get; set; } protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); Description = Pic?.Description; } @@ -70,7 +71,7 @@ await InvokeAsync(StateHasChanged); if (!string.IsNullOrEmpty(Pic?.Id)) { - await api.DeletePic(State.SelectedAddressName, Pic.Id); + await api.DeletePic(State.SelectedAddressName!, Pic.Id); await State.RefreshPics(); State.SendRefresh(); await InvokeAsync(StateHasChanged); @@ -91,7 +92,7 @@ await InvokeAsync(StateHasChanged); if(!string.IsNullOrEmpty(Pic?.Id)) { - await api.PostPicDescription(State.SelectedAddressName, Pic.Id, Description); + await api.PostPicDescription(State.SelectedAddressName!, Pic.Id, Description); await State.RefreshPics(); State.SendRefresh(); await InvokeAsync(StateHasChanged); diff --git a/Components/EditStatusDialog.razor b/Components/EditStatusDialog.razor index 55be210..6845ca4 100644 --- a/Components/EditStatusDialog.razor +++ b/Components/EditStatusDialog.razor @@ -70,10 +70,11 @@ public string? Emoji { get; set; } private bool loading = false; [Parameter] - public string id { get; set; } + public string? id { get; set; } private bool confirmDelete { get; set; } protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); Content = Status?.Content; Emoji = Status?.Emoji; } @@ -89,7 +90,7 @@ await InvokeAsync(StateHasChanged); if (!string.IsNullOrEmpty(Status?.Id)) { - await api.DeleteStatus(State.SelectedAddressName, Status.Id); + await api.DeleteStatus(State.SelectedAddressName!, Status.Id); await State.RefreshStatuses(); State.SendRefresh(); await InvokeAsync(StateHasChanged); @@ -111,7 +112,7 @@ await InvokeAsync(StateHasChanged); if (!string.IsNullOrEmpty(Status?.Id)) { - await api.PatchStatus(State.SelectedAddressName, Status.Id, Content, Emoji); + await api.PatchStatus(State.SelectedAddressName!, Status.Id, Content ?? String.Empty, Emoji); await State.RefreshStatuses(); State.SendRefresh(); await InvokeAsync(StateHasChanged); diff --git a/Components/ExternalPageComponent.razor b/Components/ExternalPageComponent.razor index 950a3b1..a0c3435 100644 --- a/Components/ExternalPageComponent.razor +++ b/Components/ExternalPageComponent.razor @@ -7,9 +7,9 @@ @code { [Parameter] - public string Url { get; set; } + public string? Url { get; set; } [Parameter] - public string id { get; set; } + public string? id { get; set; } public MarkupString? Html { get; set; } protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -19,13 +19,13 @@ } public async Task Reload() { - // if (Html == null){ + if (Url != null){ Html = await api.GetHtml(Url); string? HtmlString = Html?.ToString(); HtmlString = HtmlString?.Replace("", ""); HtmlString = HtmlString?.Replace("", ""); - Html = (MarkupString)HtmlString; - // } + Html = (MarkupString)(HtmlString ?? string.Empty); + } await InvokeAsync(StateHasChanged); } } diff --git a/Components/Layout/FollowingList.razor b/Components/Layout/FollowingList.razor index 3af791d..1f37ecd 100644 --- a/Components/Layout/FollowingList.razor +++ b/Components/Layout/FollowingList.razor @@ -19,5 +19,5 @@ @code { [Parameter] - public string @class { get; set; } + public string? @class { get; set; } } \ No newline at end of file diff --git a/Components/LoadingCard.razor b/Components/LoadingCard.razor index eabf9be..8afb1b3 100644 --- a/Components/LoadingCard.razor +++ b/Components/LoadingCard.razor @@ -8,9 +8,9 @@ @code { [Parameter] - public string id { get; set; } + public string? id { get; set; } [Parameter] public string? @class { get; set; } [Parameter] - public string icon { get; set; } + public string? icon { get; set; } } diff --git a/Components/NewEphemeral.razor b/Components/NewEphemeral.razor index bb0b235..0cadf3e 100644 --- a/Components/NewEphemeral.razor +++ b/Components/NewEphemeral.razor @@ -32,7 +32,7 @@ @code { [Parameter] - public string id { get; set; } + public string? id { get; set; } [Parameter] public bool Active { get; set; } [Parameter] diff --git a/Components/NewPicDialog.razor b/Components/NewPicDialog.razor index 71bb534..e1b23fd 100644 --- a/Components/NewPicDialog.razor +++ b/Components/NewPicDialog.razor @@ -55,7 +55,7 @@ [Parameter] public string? Description { get; set; } [Parameter] - public string id { get; set; } + public string? id { get; set; } [Parameter] public bool Active { get; set; } @@ -74,9 +74,9 @@ loading = true; await InvokeAsync(StateHasChanged); - PutPicResponseData? response = await api.PutPic(State.SelectedAddressName, Base64File); + PutPicResponseData? response = await api.PutPic(State.SelectedAddressName!, Base64File!); if(!string.IsNullOrEmpty(Description) && response != null && !string.IsNullOrEmpty(response.Id)) { - await api.PostPicDescription(State.SelectedAddressName, response.Id, Description); + await api.PostPicDescription(State.SelectedAddressName!, response.Id, Description); await State.RefreshPics(); State.SendRefresh(); await InvokeAsync(StateHasChanged); @@ -116,8 +116,17 @@ } private async Task PopulateFileDetails() { - FileContentType = File.ContentType; - FileSize = await Utilities.FileSize(File); - Base64File = await Utilities.Base64FromFile(File); + if (File == null) + { + FileContentType = null; + FileSize = null; + Base64File = null; + } + else + { + FileContentType = File.ContentType; + FileSize = await Utilities.FileSize(File); + Base64File = await Utilities.Base64FromFile(File); + } } } diff --git a/Components/NewStatusDialog.razor b/Components/NewStatusDialog.razor index d7d3ee7..0a6c5a0 100644 --- a/Components/NewStatusDialog.razor +++ b/Components/NewStatusDialog.razor @@ -52,7 +52,7 @@ @code { [Parameter] - public string id { get; set; } + public string? id { get; set; } [Parameter] public bool Active { get; set; } [Parameter] diff --git a/Components/PageHeading.razor b/Components/PageHeading.razor index 801234e..25e9178 100644 --- a/Components/PageHeading.razor +++ b/Components/PageHeading.razor @@ -13,9 +13,9 @@ @code { [Parameter] - public string icon { get; set; } + public string? icon { get; set; } [Parameter] - public string title { get; set; } + public string? title { get; set; } [Parameter] - public RenderFragment Description { get; set; } + public RenderFragment? Description { get; set; } } diff --git a/Components/Pages/EditNow.razor b/Components/Pages/EditNow.razor index c5cd797..03e704e 100644 --- a/Components/Pages/EditNow.razor +++ b/Components/Pages/EditNow.razor @@ -30,22 +30,22 @@ @code { - private MarkdownEditor Editor; + private MarkdownEditor? Editor; private bool listed; - private string markdownValue; + private string? markdownValue; private bool loading = false; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - NowContentData? data = await api.GetNowPage(State.SelectedAddressName); + NowContentData? data = await api.GetNowPage(State.SelectedAddressName!); if (data != null) { listed = data.Listed == 1; markdownValue = data.Content; - await Editor.SetValueAsync(markdownValue); + await Editor!.SetValueAsync(markdownValue); } - InvokeAsync(StateHasChanged); + await InvokeAsync(StateHasChanged); } Task OnMarkdownValueChanged(string value) { @@ -55,7 +55,7 @@ public async Task Save() { loading = true; await InvokeAsync(StateHasChanged); - var result = await api.PostNowPage(State.SelectedAddressName, markdownValue, listed); + var result = await api.PostNowPage(State.SelectedAddressName!, markdownValue ?? string.Empty, listed); if (result != null) { await State.RefreshNow(); await InvokeAsync(StateHasChanged); diff --git a/Components/Pages/SharePic.razor b/Components/Pages/SharePic.razor index e0a3059..d68fc7d 100644 --- a/Components/Pages/SharePic.razor +++ b/Components/Pages/SharePic.razor @@ -17,7 +17,7 @@ @code { - public string SharePhoto { get; set; } + public string? SharePhoto { get; set; } public long? SharePhotoSize { get; set; } public string? SharePhotoContentType { get; set; } public string? SharePhotoText { get; set; } diff --git a/Components/PicCard.razor b/Components/PicCard.razor index c1fb02c..6c33ccb 100644 --- a/Components/PicCard.razor +++ b/Components/PicCard.razor @@ -35,22 +35,22 @@ @code { [Parameter] - public Pic Pic {get; set;} + public Pic? Pic {get; set;} [Parameter] public bool Editable { get; set; } = false; [Parameter] public EditPicDialog? Dialog { get; set; } private async Task EditPic(EventArgs e){ - Dialog.Pic = Pic; + Dialog!.Pic = Pic; await InvokeAsync(StateHasChanged); await JS.InvokeVoidAsync("ui", "#" + Dialog?.id); } public async Task ShareClick(EventArgs e){ await Share.Default.RequestAsync(new ShareTextRequest{ - Uri = Pic.Url, - Text = Pic.Description, + Uri = Pic!.Url, + Text = Pic!.Description, Title = "I saw this on some.pics", Subject = "I saw this on some.pics" }); diff --git a/Components/PicList.razor b/Components/PicList.razor index cf77205..3e7bc6d 100644 --- a/Components/PicList.razor +++ b/Components/PicList.razor @@ -14,7 +14,7 @@ @code { [Parameter] - public Func?>> PicsFunc { get; set; } + public Func?>>? PicsFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; @@ -25,6 +25,8 @@ // TODO: There is a noticable rendering delay between the pics loading and the page rendering protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); + if (PicsFunc == null) return; + if (pics == null || pics.Count == 0) pics = await PicsFunc(false); State.PropertyChanged += StateChanged; State.CanRefresh = true; @@ -33,6 +35,8 @@ } private async void StateChanged(object? sender, PropertyChangedEventArgs e) { + if (PicsFunc == null) return; + if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { using (State.GetRefreshToken()){ pics = await PicsFunc(true); diff --git a/Components/StatusCard.razor b/Components/StatusCard.razor index e7515f2..2d9a5f5 100644 --- a/Components/StatusCard.razor +++ b/Components/StatusCard.razor @@ -36,21 +36,21 @@ @code { [Parameter] - public Status Status { get; set; } + public Status? Status { get; set; } [Parameter] public bool Editable { get; set; } = false; [Parameter] public EditStatusDialog? Dialog { get; set; } private async Task EditStatus(EventArgs e) { - Dialog.Status = Status; + Dialog!.Status = Status; await InvokeAsync(StateHasChanged); await JS.InvokeVoidAsync("ui", "#" + Dialog?.id); } public async Task ShareClick(EventArgs e){ await Share.Default.RequestAsync(new ShareTextRequest{ - Text = $"{Status.Content}\n- from [@{Status.Address}]({Status.Url})", + Text = $"{Status!.Content}\n- from [@{Status.Address}]({Status.Url})", Title = "I saw this on status.lol", Subject = "I saw this on status.lol" }); diff --git a/Components/StatusList.razor b/Components/StatusList.razor index 4a00190..3eea82a 100644 --- a/Components/StatusList.razor +++ b/Components/StatusList.razor @@ -14,7 +14,7 @@ @code { [Parameter] - public Func?>> StatusFunc { get; set; } + public Func?>>? StatusFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; @@ -24,6 +24,8 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); + if (StatusFunc == null) return; + if (statuses == null || statuses.Count == 0) statuses = await StatusFunc(false); State.PropertyChanged += StateChanged; State.CanRefresh = true; @@ -32,6 +34,8 @@ } private async void StateChanged(object? sender, PropertyChangedEventArgs e) { + if (StatusFunc == null) return; + if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { using (State.GetRefreshToken()) { statuses = await StatusFunc(true); diff --git a/Models/API/PostPic.cs b/Models/API/PostPic.cs index ca52388..440b8fa 100644 --- a/Models/API/PostPic.cs +++ b/Models/API/PostPic.cs @@ -6,6 +6,6 @@ using System.Threading.Tasks; namespace Neighbourhood.omg.lol.Models { public class PostPic { - public string Description { get; set; } + public string? Description { get; set; } } }