Guilhermes
This commit is contained in:
83
GuilhermesApp/Pages/FormsHistoryPage.xaml.cs
Normal file
83
GuilhermesApp/Pages/FormsHistoryPage.xaml.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using GuilhermesApp.Helpers;
|
||||
using Firebase.Database.Query;
|
||||
|
||||
namespace GuilhermesApp.Pages;
|
||||
|
||||
public partial class FormsHistoryPage : ContentPage
|
||||
{
|
||||
private FirebaseService _firebaseService = new FirebaseService();
|
||||
|
||||
public FormsHistoryPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
await CarregarHistorico();
|
||||
}
|
||||
|
||||
private async Task CarregarHistorico()
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _firebaseService.AuthClient.User;
|
||||
if (user == null) return;
|
||||
|
||||
// Vai buscar todos os registos na pasta Forms do utilizador
|
||||
var forms = await _firebaseService.DbClient
|
||||
.Child("Forms")
|
||||
.Child(user.Uid)
|
||||
.OnceAsync<FormResult>();
|
||||
|
||||
LoadingIndicator.IsRunning = false;
|
||||
LoadingIndicator.IsVisible = false;
|
||||
|
||||
if (forms.Count == 0)
|
||||
{
|
||||
EmptyLabel.IsVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Converte os dados, inverte a ordem (para o mais recente ficar no topo) e mostra na lista
|
||||
var listaOrdenada = forms.Select(f => f.Object).Reverse().ToList();
|
||||
FormsCollection.ItemsSource = listaOrdenada;
|
||||
FormsCollection.IsVisible = true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
LoadingIndicator.IsRunning = false;
|
||||
LoadingIndicator.IsVisible = false;
|
||||
await DisplayAlert("Erro", "Não foi possível carregar o histórico.", "OK");
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnFormSelected(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.CurrentSelection.FirstOrDefault() is FormResult form)
|
||||
{
|
||||
string exercicio = form.FezExercicio ? "Sim" : "Não";
|
||||
string mensagem = $"Humor: {form.Humor}\nStress: {form.Stress}/10\nSono: {form.Sono}\nExercício: {exercicio}\nNotas: {form.Notas}";
|
||||
|
||||
await DisplayAlert($"Detalhes de {form.Data}", mensagem, "Fechar");
|
||||
|
||||
// Limpa a seleção para permitir clicar novamente no mesmo
|
||||
((CollectionView)sender).SelectedItem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Classe de apoio para mapear os dados do Firebase
|
||||
public class FormResult
|
||||
{
|
||||
public string? Data { get; set; }
|
||||
public string? Humor { get; set; }
|
||||
public double Stress { get; set; }
|
||||
public string? Sono { get; set; }
|
||||
public bool FezExercicio { get; set; }
|
||||
public string? Notas { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user