1
0

49 lines
1.3 KiB
C#

using System;
using System.Reactive;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Flawless.Client.Service;
using ReactiveUI;
using ReactiveUI.SourceGenerators;
using Refit;
namespace Flawless.Client.ViewModels;
public partial class ServerSetupPageViewModel : RoutableViewModelBase
{
[Reactive] private string _host = "http://localhost:5256/";
public IObservable<bool> CanSetHost { get; }
public ServerSetupPageViewModel(IScreen hostScreen) : base(hostScreen)
{
// Must clear this gateway
if (Api.C.IsGatewayReady) Api.C.ClearGateway();
CanSetHost = this.WhenAnyValue(x => x.Host, s => !string.IsNullOrWhiteSpace(s));
}
[ReactiveCommand]
private async Task SetHostAsync()
{
try
{
await Api.C.SetGatewayAsync(Host);
HostScreen.Router.Navigate.Execute(new LoginPageViewModel(HostScreen));
}
catch (ApiException ex)
{
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
UIHelper.NotifyError(ex);
}
catch (Exception ex)
{
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
UIHelper.NotifyError(ex);
}
}
}