Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created December 3, 2024 14:56
Show Gist options
  • Save MartinZikmund/57dce683e39bfcc73cd8de59097040a7 to your computer and use it in GitHub Desktop.
Save MartinZikmund/57dce683e39bfcc73cd8de59097040a7 to your computer and use it in GitHub Desktop.
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