Skip to content

Commit

Permalink
fix SignIn
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Dec 18, 2022
1 parent fff5c29 commit 1309d63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml;
using System.Application.Services;

namespace System.Application.UI.Views.Pages
namespace System.Application.UI.Views.Pages;

public partial class UserItem : UserControl
{
public partial class UserItem : UserControl
public UserItem()
{
public UserItem()
{
InitializeComponent();
}
InitializeComponent();
}

private void InitializeComponent()
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
if (UserService.Current.User != null)
{
AvaloniaXamlLoader.Load(this);
var lastSignInTime = UserService.Current.LastSignInTime;
if (lastSignInTime.HasValue)
{
if (DateTimeOffset.Now - lastSignInTime.Value >= TimeSpan.FromDays(1))
{
UserService.Current.User.IsSignIn = true;
}
}
}

base.OnAttachedToLogicalTree(e);
}
}
8 changes: 3 additions & 5 deletions src/ST.Client/Services/Mvvm/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public async void SignOut()
}
}

public DateTimeOffset? LastSignInTime { get; set; }

public async Task SignIn()
{
if (User == null)
Expand All @@ -101,16 +103,12 @@ public async Task SignIn()
var state = await csc.AccountClockIn();
if (state.IsSuccess)
{
LastSignInTime = DateTimeOffset.Now;
User.Experience = state.Content!.Experience;
User.NextExperience = state.Content!.NextExperience;
User.Level = state.Content!.Level;
User.EngineOil = state.Content!.Strength;
User.IsSignIn = true;
//_ = Task.Run(async () =>
//{
// await Task.Delay(DateTime.Now.Date.AddDays(1).Subtract(DateTime.Now));
// IsSignedIn = false;
//});
Toast.Show(AppResources.User_SignIn_Ok);
}
else
Expand Down

0 comments on commit 1309d63

Please sign in to comment.