Created
December 3, 2024 14:56
-
-
Save MartinZikmund/57dce683e39bfcc73cd8de59097040a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class MainViewModel : PageViewModel | |
{ | |
private readonly IBlueskyService _blueskyService; | |
public MainViewModel(INavigationService navigationService, IBlueskyService blueskyService) : base(navigationService) | |
{ | |
_blueskyService = blueskyService; | |
} | |
[ObservableProperty] | |
private List<FeedItemViewModel> _feed; | |
[ObservableProperty] | |
private string _text; | |
[RelayCommand] | |
public async Task RefreshAsync() | |
{ | |
var timeline = await _blueskyService.GetTimelineAsync(); | |
if (timeline?.AsT0 is { Feed: { } } timelineData) | |
{ | |
Feed = timelineData.Feed | |
.Select(f => f.Post) | |
.Where(p => p is not null) | |
.Select(post => new FeedItemViewModel( | |
post!.Author?.DisplayName ?? "", | |
(post.Record as Post)?.Text ?? "", | |
post.LikeCount ?? 0, | |
post.RepostCount ?? 0, | |
post.ReplyCount ?? 0)).ToList(); | |
} | |
} | |
[RelayCommand] | |
public async Task PostAsync() | |
{ | |
await _blueskyService.PostAsync(Text); | |
await RefreshAsync(); | |
Text = ""; | |
} | |
public override async void OnNavigatedTo(object? parameter) | |
{ | |
base.OnNavigatedTo(parameter); | |
await RefreshAsync(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment