feat : pagination
continuous-integration/drone/push Build is passing Details

Multiplayer_Php
Yvan CALATAYUD 1 year ago
parent 50b16d2115
commit b513054114

@ -43,19 +43,16 @@ public partial class Administrators
{ {
return; return;
} }
// Calculez l'index de départ pour la pagination
int page = ((e.Page - 1) * e.PageSize) / 10 + 1;
var response = Http.GetFromJsonAsync<Administrator[]>(API.API_URL+"administrators/"+API.TOKEN).Result; // Envoyez une requête à l'API pour récupérer les questions de la page actuelle
var response = await Http.GetFromJsonAsync<Administrator[]>(API.API_URL + "administrators/" + API.TOKEN + $"?page={page}");
if (!e.CancellationToken.IsCancellationRequested && response != null) if (!e.CancellationToken.IsCancellationRequested && response != null)
{ {
administrators = new List<Administrator>(response); // an actual data for the current page administrators = new List<Administrator>(response); // an actual data for the current page
totalItem = administrators.Count; totalItem = administrators.Count;
var currentData = await LocalStorage.GetItemAsync<Administrator[]>("data");
if (currentData == null || currentData.Length != administrators.Count)
{
var originalData = Http.GetFromJsonAsync<Administrator[]>(API.API_URL + "administrators/" + API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
} }
} }

@ -77,18 +77,16 @@ public partial class Chapters
return; return;
} }
var response = Http.GetFromJsonAsync<Chapter[]>(API.API_URL+"chapters/"+API.TOKEN).Result; // Calculez l'index de départ pour la pagination
int page = ((e.Page - 1) * e.PageSize) / 10 + 1;
// Envoyez une requête à l'API pour récupérer les questions de la page actuelle
var response = await Http.GetFromJsonAsync<Chapter[]>(API.API_URL + "chapters/" + API.TOKEN + $"?page={page}");
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
chapters = new List<Chapter>(response); // an actual data for the current page chapters = new List<Chapter>(response); // an actual data for the current page
totalChapter = chapters.Count; totalChapter = chapters.Count;
var currentData = await LocalStorage.GetItemAsync<Chapter[]>("data");
if (currentData == null || currentData.Length != chapters.Count)
{
var originalData = Http.GetFromJsonAsync<Chapter[]>(API.API_URL+"chapters/"+API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
} }
} }
} }

@ -78,18 +78,16 @@ public partial class Players
return; return;
} }
var response = Http.GetFromJsonAsync<Player[]>(API.API_URL+"players/"+API.TOKEN).Result; // Calculez l'index de départ pour la pagination
int page = ((e.Page - 1) * e.PageSize) / 10 + 1;
// Envoyez une requête à l'API pour récupérer les questions de la page actuelle
var response = await Http.GetFromJsonAsync<Player[]>(API.API_URL + "players/" + API.TOKEN + $"?page={page}");
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
players = new List<Player>(response); // an actual data for the current page players = new List<Player>(response); // an actual data for the current page
totalPlayer = players.Count; totalPlayer = players.Count;
var currentData = await LocalStorage.GetItemAsync<Player[]>("data");
if (currentData == null || currentData.Length != players.Count)
{
var originalData = Http.GetFromJsonAsync<Player[]>(API.API_URL+"players/"+API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
} }
} }
} }

@ -84,8 +84,11 @@ public partial class Questions
return; return;
} }
// Calculez l'index de départ pour la pagination
var response = Http.GetFromJsonAsync<Question[]>(API.API_URL+"questions/"+API.TOKEN).Result; int page = ((e.Page - 1) * e.PageSize)/10 + 1;
// Envoyez une requête à l'API pour récupérer les questions de la page actuelle
var response = await Http.GetFromJsonAsync<Question[]>(API.API_URL + "questions/" + API.TOKEN + $"?page={page}");
if (!e.CancellationToken.IsCancellationRequested && response != null) if (!e.CancellationToken.IsCancellationRequested && response != null)
{ {
@ -99,15 +102,6 @@ public partial class Questions
questions = selectedQuestions; questions = selectedQuestions;
totalQuestion = questions.Count; totalQuestion = questions.Count;
var currentData = await LocalStorage.GetItemAsync<Question[]>("data");
// Check if data exist in the local storage
if (currentData == null || currentData.Length != questions.Count)
{
// this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method)
var originalData = Http.GetFromJsonAsync<Question[]>(API.API_URL+"chapters/"+API.TOKEN).Result;
await LocalStorage.SetItemAsync("data", originalData);
}
} }
} }

Loading…
Cancel
Save