fix(sorting): 🐛 fix unchanged sorting result

This commit is contained in:
pakintada@gmail.com 2024-03-18 11:27:57 +07:00
parent ef9cf48fc1
commit b53183d884
5 changed files with 358 additions and 103 deletions

View file

@ -326,11 +326,13 @@ export class RecipeService {
country: string,
filename: string,
sortKey: string,
ascending: boolean
): Promise<Observable<any>> {
return this._httpClient.post<any>(
environment.api + '/recipes/sort/' + country + '/' + filename ,
JSON.stringify({
"sortKey": sortKey
"sortKey": sortKey,
"ascending": ascending
}),
{ withCredentials: true, responseType: 'json' }
);

View file

@ -638,19 +638,38 @@ export class RecipesComponent implements OnInit, OnDestroy, AfterViewInit {
// activate sorting
console.log('sortByHeader', header);
// save toggle for each header
// get header if saved
let headerToggle = await AsyncStorage.getItem("sort_"+header);
let toggleAscend = true;
if(headerToggle == null || headerToggle == undefined){
await AsyncStorage.setItem("sort_"+header, "true");
} else if(headerToggle == "true") {
toggleAscend = false;
await AsyncStorage.setItem("sort_"+header, "false");
} else if(headerToggle == "false"){
toggleAscend = true;
await AsyncStorage.setItem("sort_"+header, "true");
}
//
console.log("sort ", headerToggle, " to ", header);
// send to server [/recipe/sort]
(
await this._recipeService.sortRecipe(
await this._recipeService.getCurrentCountry(),
this._recipeService.getCurrentFile(),
header
header,
toggleAscend
)
).subscribe({
next: (data: any) => {
if(data.status == 'OK'){
console.log(data.result);
alert("refresh ... ");
window.location.reload();
}
}