Files
Massenger/src/Massenger.Client/Pages/ChatPage.xaml.cs
2026-03-13 21:01:04 +03:00

45 lines
956 B
C#

using Massenger.Client.Services;
using Massenger.Client.ViewModels;
namespace Massenger.Client.Pages;
[QueryProperty(nameof(ChatId), "chatId")]
public partial class ChatPage : ContentPage
{
private readonly ChatViewModel _viewModel;
private string? _chatId;
public string? ChatId
{
get => _chatId;
set
{
_chatId = value;
_ = LoadChatAsync(value);
}
}
public ChatPage()
{
InitializeComponent();
_viewModel = ServiceHelper.GetRequiredService<ChatViewModel>();
_viewModel.AttachRealtime();
BindingContext = _viewModel;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
_viewModel.DetachRealtime();
}
private async Task LoadChatAsync(string? chatId)
{
if (Guid.TryParse(chatId, out var parsed))
{
await _viewModel.LoadAsync(parsed);
}
}
}