Skip to content

Commit f000164

Browse files
committed
feat: add profile page to display user logged in
1 parent 8190bad commit f000164

2 files changed

Lines changed: 189 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="MatchingGame.Vistas.ModalPage.ProfilePage"
5+
NavigationPage.HasNavigationBar="True">
6+
<ContentPage.Content>
7+
<ScrollView BackgroundColor="#140429">
8+
<StackLayout VerticalOptions="CenterAndExpand" MinimumHeightRequest="900">
9+
<Frame
10+
HorizontalOptions="Center"
11+
BackgroundColor="Transparent"
12+
WidthRequest="170"
13+
HeightRequest="170"
14+
CornerRadius="999" >
15+
<Image
16+
Source="addProfile"
17+
WidthRequest="170"
18+
HeightRequest="170"
19+
Aspect="AspectFit"
20+
x:Name="SelectAvatar" />
21+
</Frame>
22+
<StackLayout HorizontalOptions="Center" Padding="20,0">
23+
<Label
24+
Text="Luis Gabriel"
25+
FontSize="20"
26+
FontAttributes="Bold"
27+
HorizontalOptions="Center"
28+
Margin="0,20,0,0"
29+
x:Name="Name" />
30+
<Label
31+
Text="janco7249@gmail.com"
32+
FontSize="20"
33+
HorizontalOptions="Center"
34+
Margin="0,0,0,40"
35+
x:Name="Email" />
36+
<StackLayout Orientation="Horizontal" Margin="0,0,0,40">
37+
<Frame BackgroundColor="#411645" CornerRadius="16" Padding="0,10" Margin="0" HorizontalOptions="Start" WidthRequest="100">
38+
<StackLayout Orientation="Vertical">
39+
<Label
40+
Text="444"
41+
FontSize="24"
42+
FontAttributes="Bold"
43+
HorizontalOptions="Center"
44+
x:Name="Score" />
45+
<Label
46+
Text="Score"
47+
FontSize="16"
48+
HorizontalOptions="Center" />
49+
</StackLayout>
50+
</Frame>
51+
<Frame BackgroundColor="#411645" CornerRadius="16" Padding="0,10" Margin="0" HorizontalOptions="Start" WidthRequest="100">
52+
<StackLayout Orientation="Vertical">
53+
<Label
54+
Text="1"
55+
FontSize="24"
56+
FontAttributes="Bold"
57+
HorizontalOptions="Center"
58+
x:Name="Position" />
59+
<Label
60+
Text="Top"
61+
FontSize="16"
62+
HorizontalOptions="Center" />
63+
</StackLayout>
64+
</Frame>
65+
<Frame BackgroundColor="#411645" CornerRadius="16" Padding="0,10" Margin="0" HorizontalOptions="Start" WidthRequest="100">
66+
<StackLayout Orientation="Vertical">
67+
<Label
68+
Text="10"
69+
FontSize="24"
70+
FontAttributes="Bold"
71+
HorizontalOptions="Center"
72+
x:Name="MaxLevel" />
73+
<Label
74+
Text="Max. Nivel"
75+
FontSize="16"
76+
HorizontalOptions="Center" />
77+
</StackLayout>
78+
</Frame>
79+
</StackLayout>
80+
</StackLayout>
81+
<Button
82+
Text="Cerrar Sesión"
83+
FontSize="22"
84+
FontAttributes="Bold"
85+
CornerRadius="24"
86+
Margin="70,0"
87+
HeightRequest="54"
88+
BackgroundColor="#F55050"
89+
BorderColor="#411645"
90+
BorderWidth="4"
91+
x:Name="Logout"
92+
Clicked="Logout_Clicked"/>
93+
</StackLayout>
94+
</ScrollView>
95+
</ContentPage.Content>
96+
</ContentPage>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using MatchingGame.Clases;
2+
using MatchingGame.Vistas.HomePage;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Net.Http;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
using Xamarin.Forms;
12+
using Xamarin.Forms.Xaml;
13+
14+
namespace MatchingGame.Vistas.ModalPage
15+
{
16+
[XamlCompilation(XamlCompilationOptions.Compile)]
17+
public partial class ProfilePage : ContentPage
18+
{
19+
public ProfilePage()
20+
{
21+
InitializeComponent();
22+
if (Application.Current.Properties.ContainsKey("Photo")
23+
&& Application.Current.Properties.ContainsKey("Name")
24+
&& Application.Current.Properties.ContainsKey("Email")
25+
&& Application.Current.Properties.ContainsKey("Score"))
26+
{
27+
SelectAvatar.Source = Application.Current.Properties["Photo"] as string;
28+
Name.Text = Application.Current.Properties["Name"] as string;
29+
Email.Text = Application.Current.Properties["Email"] as string;
30+
Score.Text = Application.Current.Properties["Score"].ToString();
31+
MaxLevel.Text = Application.Current.Properties["MaxLevel"].ToString();
32+
GetMyPositionLaderboard();
33+
}
34+
}
35+
36+
public async void GetMyPositionLaderboard()
37+
{
38+
try
39+
{
40+
Uri RequestUri = new("https://matchinggame.vercel.app/api/matching-game");
41+
var client = new HttpClient();
42+
HttpResponseMessage response = await client.GetAsync(RequestUri);
43+
if (response.IsSuccessStatusCode)
44+
{
45+
var content = await response.Content.ReadAsStringAsync();
46+
User[] users = JsonConvert.DeserializeObject<User[]>(content);
47+
48+
if (Application.Current.Properties.ContainsKey("Email"))
49+
{
50+
var email = Application.Current.Properties["Email"] as string;
51+
for (int i = 0; i < users.Length; i++)
52+
{
53+
if (users[i].email == email)
54+
{
55+
Position.Text = (i + 1).ToString();
56+
}
57+
}
58+
}
59+
}
60+
}
61+
catch (Exception error)
62+
{
63+
await DisplayAlert("Error", error.Message, "Cancelar");
64+
}
65+
}
66+
67+
private async void Logout_Clicked(object sender, EventArgs e)
68+
{
69+
Application.Current.Properties.Remove("Token");
70+
Application.Current.Properties.Remove("Name");
71+
Application.Current.Properties.Remove("Email");
72+
Application.Current.Properties.Remove("Password");
73+
Application.Current.Properties.Remove("Score");
74+
Application.Current.Properties.Remove("Photo");
75+
Application.Current.Properties.Remove("Id");
76+
Application.Current.Properties.Remove("MaxLevel");
77+
78+
await Application.Current.SavePropertiesAsync();
79+
await Navigation.PushAsync(new Home());
80+
}
81+
82+
protected override bool OnBackButtonPressed()
83+
{
84+
PromptForExit();
85+
return true;
86+
}
87+
88+
private async void PromptForExit()
89+
{
90+
await Navigation.PopToRootAsync();
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)