fix delay material fetching
This commit is contained in:
parent
db131d10c0
commit
4ece2cf30c
13 changed files with 220 additions and 143 deletions
|
|
@ -14,6 +14,7 @@ import { environment } from 'src/environments/environment';
|
|||
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';
|
||||
|
||||
type RecipeOverviewParams = {
|
||||
filename: string;
|
||||
|
|
@ -49,7 +50,7 @@ export class RecipeService {
|
|||
constructor(private _httpClient: HttpClient, private _route: ActivatedRoute) {}
|
||||
|
||||
getRecipesDashboard(
|
||||
params: RecipeDashboardParams = {
|
||||
params: any = {
|
||||
country: this.getCurrentCountry(this.department!),
|
||||
filename: this.getCurrentFile(),
|
||||
}
|
||||
|
|
@ -67,8 +68,8 @@ export class RecipeService {
|
|||
);
|
||||
}
|
||||
|
||||
getRecipeOverview(
|
||||
params: RecipeOverviewParams = {
|
||||
async getRecipeOverview(
|
||||
params: any = {
|
||||
country: this.getCurrentCountry(this.department!),
|
||||
filename: this.getCurrentFile(),
|
||||
materialIds: [],
|
||||
|
|
@ -76,7 +77,7 @@ export class RecipeService {
|
|||
take: 20,
|
||||
search: '',
|
||||
}
|
||||
): Observable<RecipeOverviewList> {
|
||||
): Promise<Observable<RecipeOverviewList>> {
|
||||
return this._httpClient.get<RecipeOverviewList>(
|
||||
environment.api + '/recipes/overview',
|
||||
{
|
||||
|
|
@ -94,13 +95,13 @@ export class RecipeService {
|
|||
);
|
||||
}
|
||||
|
||||
getRecipeDetail(productCode: string): Observable<RecipeDetail> {
|
||||
async getRecipeDetail(productCode: string): Promise<Observable<RecipeDetail>> {
|
||||
return this._httpClient.get<RecipeDetail>(
|
||||
environment.api + '/recipes/' + productCode,
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(this.department!),
|
||||
country: await this.getCurrentCountry(this.department!),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
|
|
@ -108,15 +109,15 @@ export class RecipeService {
|
|||
);
|
||||
}
|
||||
|
||||
getRecipeDetailMat(
|
||||
async getRecipeDetailMat(
|
||||
productCode: string
|
||||
): Observable<{ result: RecipeDetailMat[] }> {
|
||||
): Promise<Observable<{ result: RecipeDetailMat[]; }>> {
|
||||
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
|
||||
environment.api + '/recipes/' + productCode + '/mat',
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(this.department!),
|
||||
country: await this.getCurrentCountry(this.department!),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
|
|
@ -141,7 +142,7 @@ export class RecipeService {
|
|||
localStorage.setItem('currentRecipeFile', filename);
|
||||
}
|
||||
|
||||
getCurrentCountry(department?: string): string {
|
||||
async getCurrentCountry(department?: string): Promise<string> {
|
||||
|
||||
if(department){
|
||||
|
||||
|
|
@ -151,10 +152,15 @@ export class RecipeService {
|
|||
console.log('fullname: ', fullname);
|
||||
|
||||
// localStorage.setItem('currentRecipeCountry', fullname);
|
||||
|
||||
await AsyncStorage.setItem('currentRecipeCountry', fullname);
|
||||
|
||||
return fullname;
|
||||
}
|
||||
|
||||
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
|
||||
// const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
|
||||
|
||||
const currentRecipeCountry = await AsyncStorage.getItem<string>('currentRecipeCountry');
|
||||
if (currentRecipeCountry) {
|
||||
return currentRecipeCountry;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue