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:
parent
e25881d016
commit
a29ff0be1a
19 changed files with 314 additions and 108 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { updateMachineStatus } from '../stores/machineInfoStore';
|
||||
import { addNotification } from '../stores/noti';
|
||||
import { handleIncomingMessages } from './messageHandler';
|
||||
|
||||
type AdbPayload = { type: string; payload: any };
|
||||
|
||||
|
|
@ -17,6 +18,26 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
case 'response':
|
||||
if (payload.payload instanceof String) {
|
||||
// single message response
|
||||
let raw_payload = payload.payload.toString();
|
||||
|
||||
if (raw_payload.startsWith('save_recipe_machine')) {
|
||||
let res = raw_payload.split('/');
|
||||
|
||||
let pd = res[1] ?? '';
|
||||
let action = res[2] ?? '';
|
||||
let uiAction = res[3] ?? '';
|
||||
|
||||
handleIncomingMessages(
|
||||
JSON.stringify({
|
||||
type: 'ui_action',
|
||||
payload: {
|
||||
action: uiAction,
|
||||
from: 'brew',
|
||||
ref: `${pd}.${action}`
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'ACK':
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { get, writable } from 'svelte/store';
|
||||
import { addNotification, notiStore } from '../stores/noti';
|
||||
import {
|
||||
currentRecipeVersionsSelector,
|
||||
materialFromServerQuery,
|
||||
recipeData,
|
||||
recipeDataError,
|
||||
|
|
@ -12,6 +13,8 @@ import {
|
|||
} from '../stores/recipeStore';
|
||||
import { buildOverviewFromServer } from '$lib/data/recipeService';
|
||||
import { auth } from '../client/firebase';
|
||||
import { type RecipeVersion } from '$lib/models/recipe_version.model';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
export const messages = writable<string[]>([]);
|
||||
|
||||
|
|
@ -32,18 +35,30 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
let stream_id = p.stream_id;
|
||||
let total_size = p.total_size;
|
||||
let chunk_size = p.chunk_size;
|
||||
let data_meta = p.metadata;
|
||||
|
||||
if (stream_id) {
|
||||
addNotification('INFO:Start streaming data');
|
||||
|
||||
let meta_list = data_meta?.split(',');
|
||||
let version = meta_list[0]?.split('=')[1] ?? '';
|
||||
let country = meta_list[1]?.split('=')[1] ?? '';
|
||||
|
||||
// recipeLoading.set(true);
|
||||
recipeStreamMeta.set({
|
||||
id: stream_id,
|
||||
total_size: total_size,
|
||||
chunk_size: chunk_size,
|
||||
progress: 0
|
||||
progress: 0,
|
||||
version,
|
||||
country
|
||||
});
|
||||
recipeData.set([]);
|
||||
recipeOverviewData.set([]);
|
||||
|
||||
materialFromServerQuery.set([]);
|
||||
toppingListFromServerQuery.set([]);
|
||||
toppingGroupFromServerQuery.set([]);
|
||||
}
|
||||
},
|
||||
stream_data_error: (p) => {
|
||||
|
|
@ -56,6 +71,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
},
|
||||
stream_data_chunk: (p) => {
|
||||
let current_meta = get(recipeStreamMeta);
|
||||
// console.log('current meta', current_meta);
|
||||
if (current_meta) {
|
||||
let stream_id = current_meta.id;
|
||||
|
||||
|
|
@ -92,6 +108,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
// build overview for recipe from server
|
||||
//
|
||||
|
||||
// console.log('ending stream');
|
||||
buildOverviewFromServer();
|
||||
},
|
||||
stream_data_extra: (p) => {
|
||||
|
|
@ -120,7 +137,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
curr_mat_query.push(m);
|
||||
}
|
||||
|
||||
// console.log('current materials: ', JSON.stringify(curr_mat_query));
|
||||
// // console.log('current materials: ', JSON.stringify(curr_mat_query));
|
||||
materialFromServerQuery.set(curr_mat_query);
|
||||
break;
|
||||
case 'topplist':
|
||||
|
|
@ -168,6 +185,28 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
// broadcast to all
|
||||
addNotification(`${noti_level}:${msg}`);
|
||||
}
|
||||
},
|
||||
ui_action: (p) => {
|
||||
if (p.action == 'refreshNow' && p.from == 'brew') {
|
||||
goto('/tools/brew');
|
||||
}
|
||||
},
|
||||
version_selectors: (p) => {
|
||||
if (p.versions.length > 0) {
|
||||
currentRecipeVersionsSelector.set([]);
|
||||
let result: RecipeVersion[] = [];
|
||||
|
||||
for (let vstr of p.versions) {
|
||||
let pure_version = vstr.split('_')[0];
|
||||
|
||||
result.push({
|
||||
display_version: pure_version,
|
||||
actual_version_name: vstr
|
||||
});
|
||||
}
|
||||
|
||||
currentRecipeVersionsSelector.set(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -41,25 +41,25 @@ export function sendCommandRequest(target: CommandRequest, values: any) {
|
|||
});
|
||||
}
|
||||
|
||||
export function sendMessage(msg: OutMessage): boolean {
|
||||
export function sendMessage(msg: OutMessage, ignore_queue_request: boolean = true): boolean {
|
||||
const socket = get(socketStore);
|
||||
const data = JSON.stringify(msg);
|
||||
|
||||
// console.log('try sending ', data);
|
||||
|
||||
if (!socket || socket.readyState !== WebSocket.OPEN) {
|
||||
console.warn('WebSocket not connected, put to queue');
|
||||
// console.warn('WebSocket not connected, put to queue');
|
||||
|
||||
let currentQueue = get(queue);
|
||||
if (currentQueue.length >= 10) {
|
||||
while (currentQueue.length >= 10) {
|
||||
currentQueue.shift();
|
||||
}
|
||||
}
|
||||
currentQueue.push(data);
|
||||
queue.set(currentQueue);
|
||||
// let currentQueue = get(queue);
|
||||
// if (currentQueue.length >= 10) {
|
||||
// while (currentQueue.length >= 10) {
|
||||
// currentQueue.shift();
|
||||
// }
|
||||
// }
|
||||
// currentQueue.push(data);
|
||||
// queue.set(currentQueue);
|
||||
|
||||
addNotification('WARN:Queuing request');
|
||||
// if (!ignore_queue_request) addNotification('WARN:Queuing request');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue