fix default file reader bug

This commit is contained in:
pakintada@gmail.com 2024-01-17 17:38:23 +07:00
parent 21109e4bf9
commit db131d10c0
15 changed files with 636 additions and 254 deletions

View file

@ -12,6 +12,8 @@ import {
} from '../models/recipe.model';
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';
type RecipeOverviewParams = {
filename: string;
@ -38,15 +40,17 @@ export class RecipeService {
private tmp_files: string[] = [];
private department = this._route.snapshot.paramMap.get('department');
private get tmpfiles(): string[] {
return this.tmp_files;
}
constructor(private _httpClient: HttpClient) {}
constructor(private _httpClient: HttpClient, private _route: ActivatedRoute) {}
getRecipesDashboard(
params: RecipeDashboardParams = {
country: this.getCurrentCountry(),
country: this.getCurrentCountry(this.department!),
filename: this.getCurrentFile(),
}
): Observable<RecipesDashboard> {
@ -65,7 +69,7 @@ export class RecipeService {
getRecipeOverview(
params: RecipeOverviewParams = {
country: this.getCurrentCountry(),
country: this.getCurrentCountry(this.department!),
filename: this.getCurrentFile(),
materialIds: [],
offset: 0,
@ -96,7 +100,7 @@ export class RecipeService {
{
params: {
filename: this.getCurrentFile(),
country: this.getCurrentCountry(),
country: this.getCurrentCountry(this.department!),
},
withCredentials: true,
responseType: 'json',
@ -112,7 +116,7 @@ export class RecipeService {
{
params: {
filename: this.getCurrentFile(),
country: this.getCurrentCountry(),
country: this.getCurrentCountry(this.department!),
},
withCredentials: true,
responseType: 'json',
@ -121,19 +125,35 @@ export class RecipeService {
}
getCurrentFile(): string {
// TODO: get default from server
const currentRecipeFile = localStorage.getItem('currentRecipeFile');
if (currentRecipeFile) {
return currentRecipeFile;
}
return 'coffeethai02_580.json';
return 'default';
}
setCurrentFile(filename: string) {
localStorage.setItem('currentRecipeFile', filename);
}
getCurrentCountry(): string {
getCurrentCountry(department?: string): string {
if(department){
// translate back to full name
let fullname = getCountryMapSwitcher(department);
console.log('fullname: ', fullname);
// localStorage.setItem('currentRecipeCountry', fullname);
return fullname;
}
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
if (currentRecipeCountry) {
return currentRecipeCountry;