fix(CurrentRecipePointer): 🐛 Fix cache recipe

Remove continue last opened version
This commit is contained in:
pakintada@gmail.com 2024-04-11 16:59:37 +07:00
parent 4219c1cb43
commit 2b8745679f
16 changed files with 481 additions and 174 deletions

View file

@ -15,6 +15,8 @@ import { RecipeMetaData } from 'src/app/shared/types/recipe';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
import { ActivatedRoute } from '@angular/router';
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
import { SocketIOService } from 'src/app/shared/services/websocket.service';
import { UserService } from './user.service';
type RecipeOverviewParams = {
filename: string;
@ -49,10 +51,14 @@ export class RecipeService {
constructor(
private _httpClient: HttpClient,
private _route: ActivatedRoute
) {}
private _route: ActivatedRoute,
private _user: UserService,
// private _socket: SocketIOService
) {
// this._socket.checkIn(this._user.getCurrentUser()!.name, 'recipe:response');
}
shareHttpClient(){
shareHttpClient() {
return this._httpClient;
}
@ -62,6 +68,26 @@ export class RecipeService {
filename: this.getCurrentFile(),
}
): Observable<RecipesDashboard> {
// test socket service
// this._socket.getPayload(`${this._user.getCurrentUser()!.name}:recipe:response:cache`)?.subscribe({
// next: (c: any)=> {
// console.log("cache from server", c);
// }
// });
// this._socket.sendTopic('recipe:dashboard', {
// room: 'recipe:response',
// topic: 'recipe:dashboard',
// user: this._user.getCurrentUser()!.name,
// country: params.country,
// filename: params.filename,
// });
// return this._socket.getPayload(
// `recipe:dashboard:${this._user.getCurrentUser()!.name}:payload`
// )!;
return this._httpClient.get<RecipesDashboard>(
environment.api + '/recipes/dashboard',
{
@ -85,6 +111,20 @@ export class RecipeService {
search: '',
}
): Promise<Observable<RecipeOverviewList>> {
console.log("overview: ", params);
// this._socket.sendTopic('recipe:overview', {
// room: 'recipe:response',
// topic: 'recipe:overview',
// user: this._user.getCurrentUser()!.name,
// ...params
// });
// return this._socket.getPayload(
// `recipe:overview:${this._user.getCurrentUser()!.name}:payload`
// )!;
return this._httpClient.get<RecipeOverviewList>(
environment.api + '/recipes/overview',
{
@ -240,7 +280,7 @@ export class RecipeService {
});
}
upgradeRecipe(country: string, filename: string, ctx: any){
upgradeRecipe(country: string, filename: string, ctx: any) {
return this._httpClient.post<any>(
environment.api + ('/recipes/upgrade/' + country + '/' + filename),
ctx,
@ -316,29 +356,27 @@ export class RecipeService {
country: string,
filename: string
): Observable<any> {
console.log("try get patches", country, filename);
console.log('try get patches', country, filename);
return this._httpClient.get<any>(
environment.api + '/recipes/patch/get/' + country + '/' + filename ,
environment.api + '/recipes/patch/get/' + country + '/' + filename,
{ withCredentials: true, responseType: 'json' }
);
}
async sortRecipe(
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,
"ascending": ascending
}),
{ withCredentials: true, responseType: 'json' }
);
}
): Promise<Observable<any>> {
return this._httpClient.post<any>(
environment.api + '/recipes/sort/' + country + '/' + filename,
JSON.stringify({
sortKey: sortKey,
ascending: ascending,
}),
{ withCredentials: true, responseType: 'json' }
);
}
}