From fac37fcdd6f99414b974502e187c8b8577d2834c Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Tue, 2 Jan 2024 17:23:57 +0900 Subject: [PATCH] Start User Profile page --- website/FishyFlipSite.sln | 3 + website/FishyFlipSite/MainLayout.razor | 1 + website/FishyFlipSite/Pages/UserProfile.razor | 131 ++++++++++++++++++ website/FishyFlipSite/Program.cs | 1 + 4 files changed, 136 insertions(+) create mode 100644 website/FishyFlipSite/Pages/UserProfile.razor diff --git a/website/FishyFlipSite.sln b/website/FishyFlipSite.sln index 903f10a0..24275192 100644 --- a/website/FishyFlipSite.sln +++ b/website/FishyFlipSite.sln @@ -25,4 +25,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ECB477D7-CB82-42CA-BA0A-BD0C6319A2C7} + EndGlobalSection EndGlobal diff --git a/website/FishyFlipSite/MainLayout.razor b/website/FishyFlipSite/MainLayout.razor index 7cfff655..1a026eb0 100644 --- a/website/FishyFlipSite/MainLayout.razor +++ b/website/FishyFlipSite/MainLayout.razor @@ -10,6 +10,7 @@ Home Firehose + Profile diff --git a/website/FishyFlipSite/Pages/UserProfile.razor b/website/FishyFlipSite/Pages/UserProfile.razor new file mode 100644 index 00000000..b647acfb --- /dev/null +++ b/website/FishyFlipSite/Pages/UserProfile.razor @@ -0,0 +1,131 @@ +@page "/profile" +@inject ILogger logger; +@using Drastic.Tools; +@using FishyFlip; +@using FishyFlip.Events; +@using FishyFlip.Models; +@using FishyFlip.Tools; +@using Microsoft.Extensions.Logging.Debug; +@using System.Collections.ObjectModel; + +@* Error Block *@ +@if (!string.IsNullOrEmpty(error)) +{ +
+

@error

+
+} + +
+ + +
+ +
+ + +
+ +
+ +
+ +@if (isLoading) +{ +

Loading...

+} + +@if (profile is not null) +{ +
+

Did: @did

+

Display Name: @profile.Value?.DisplayName

+

Uri: @profile.Uri

+

Description: @profile.Value?.Description

+

Avatar: @ImageUrl

+
+} + +@if (posts.Count > 0) +{ +
+ @foreach (var item in posts) + { +
+ @item.Type +

@item.Text

+ @item.CreatedAt +
+ } +
+} + +@code { + private string? error; + private string? handle = "drasticactions.dev"; + private string? instance = "bsky.social"; + private ATProtocol? protocol; + private bool isLoading = false; + private ActorRecord? profile; + private ATDid? did; + private List posts = new(); + + private string? ImageUrl { + get { + if (protocol is null || profile is null || profile.Uri is null || profile.Value?.Avatar is null || profile.Value?.Avatar.Ref is null || profile.Value?.Avatar.Ref.Link is null) + { + return null; + } + + return $"https://{protocol.Options.Url.Host}{Constants.Urls.ATProtoSync.GetBlob}?did={profile.Uri.Did!}&cid={profile.Value.Avatar.Ref.Link}"; + } + } + private async Task Load() + { + this.Unload(); + + try + { + var host = instance ?? "bsky.social"; + + if (!Uri.TryCreate(host, UriKind.Absolute, out Uri? uri)) + { + uri = new Uri($"https://{host}"); + } + + if (uri is null) + { + return; + } + + var builder = new ATProtocolBuilder(); + protocol = builder.WithInstanceUrl(uri) + .WithLogger(this.logger).Build(); + + this.isLoading = true; + + var handleResolution = (await protocol.Identity.ResolveHandleAsync(ATHandle.Create(handle))).HandleResult(); + this.did = handleResolution?.Did; + this.profile = (await protocol.Repo.GetActorAsync(handleResolution.Did)).HandleResult(); + + var posts = (await protocol.Repo.ListPostsAsync(handleResolution.Did)).HandleResult(); + this.posts.AddRange(posts?.Records.Select(n => (Post)n.Value)); + } + catch (Exception ex) + { + this.error = ex.Message; + this.logger.LogError(ex, ex.Message); + } + + this.isLoading = false; + this.StateHasChanged(); + } + + private void Unload() + { + this.error = null; + this.protocol?.Dispose(); + this.protocol = null; + this.posts.Clear(); + } +} diff --git a/website/FishyFlipSite/Program.cs b/website/FishyFlipSite/Program.cs index 5cf3b258..65f0fb7b 100644 --- a/website/FishyFlipSite/Program.cs +++ b/website/FishyFlipSite/Program.cs @@ -10,6 +10,7 @@ builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); +builder.Services.AddLogging(); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); await builder.Build().RunAsync();