Добавьте файлы проекта.
This commit is contained in:
44
src/Massenger.Client/Pages/ChatPage.xaml.cs
Normal file
44
src/Massenger.Client/Pages/ChatPage.xaml.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user