feat: recipe version selector

- fix recipe not show on overview
- fix recipe show late after select country
- disable queue message on no connection ws
- fix infinite topping(s) list if moving between pages

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-05-04 16:50:15 +07:00
parent e25881d016
commit a29ff0be1a
19 changed files with 314 additions and 108 deletions

View file

@ -6,6 +6,7 @@ import { extractCookieOnNonBrowser } from '$lib/helpers/cookie';
import { browser } from '$app/environment';
import { permission } from '../stores/permissions';
import { addNotification } from '../stores/noti';
import { recipeData, recipeOverviewData } from '../stores/recipeStore';
export async function getRecipes() {
if (browser && !get(departmentStore)) {
@ -31,7 +32,10 @@ export async function getRecipes() {
// construct path. fetch (GET) {server}/recipe/{countryTarget}/{version}
let idToken = await get(auth)?.getIdToken();
console.log('country target get recipe', country);
console.log('country target get recipe', countryTarget);
recipeData.set([]);
recipeOverviewData.set([]);
sendMessage({
type: 'recipe',
@ -46,3 +50,48 @@ export async function getRecipes() {
return [];
}
export async function getRecipeWithVersion(version: string) {
if (browser && !get(departmentStore)) {
console.log('cannot get dep', get(departmentStore));
return [];
}
let countryTarget = get(departmentStore);
let country = '';
let countryPerm = `document.read.${countryTarget}`;
let user_perms = get(permission);
if (!user_perms.includes(countryPerm)) {
addNotification('ERR:Invalid permission');
return [];
}
// if (!countryTarget && !browser) {
// countryTarget = extractCookieOnNonBrowser()['department'];
// }
// construct path. fetch (GET) {server}/recipe/{countryTarget}/{version}
let idToken = await get(auth)?.getIdToken();
console.log('country target get recipe', countryTarget);
recipeData.set([]);
recipeOverviewData.set([]);
// NOTE: although version is provided, actual version field is still need to be latest
// Just in case version is not found
sendMessage({
type: 'recipe',
payload: {
auth: idToken ?? '',
partial: false,
country: countryTarget ?? '',
version: -1,
parameters: 'use_legacy_version=true,version=' + version
}
});
return [];
}