update get data priceslot
This commit is contained in:
parent
cd88d5aed9
commit
6a2f4e5945
5 changed files with 912 additions and 337 deletions
|
|
@ -21,6 +21,8 @@ import {
|
|||
handleSheetStreamEnd,
|
||||
handleSheetStreamError,
|
||||
handleCatalogsResponse,
|
||||
handlePriceSlotsResponse,
|
||||
isPriceSlotsPayload,
|
||||
handleListMenuResponse,
|
||||
sheetCatalogsLoading,
|
||||
handleRawStreamHeader,
|
||||
|
|
@ -283,22 +285,55 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
|
||||
if (from === 'sheet-service' && level === 'content') {
|
||||
const currentUid = auth.currentUser?.uid;
|
||||
const content = p.content ?? p.value ?? p.payload;
|
||||
|
||||
if (target && currentUid && target === currentUid) {
|
||||
if (!msg && p.content?.catalogs) {
|
||||
handleCatalogsResponse(p.content);
|
||||
addNotification(`INFO:Loaded ${p.content.catalogs?.length || 0} catalogs`);
|
||||
console.log('[Sheet] Notify content received:', {
|
||||
msg,
|
||||
target,
|
||||
currentUid,
|
||||
contentKeys: content && typeof content === 'object' ? Object.keys(content) : [],
|
||||
content
|
||||
});
|
||||
|
||||
if (!target || (currentUid && target === currentUid)) {
|
||||
if (!msg && content?.catalogs) {
|
||||
handleCatalogsResponse(content);
|
||||
addNotification(`INFO:Loaded ${content.catalogs?.length || 0} catalogs`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!msg &&
|
||||
(content?.priceSlots ||
|
||||
content?.priceslots ||
|
||||
content?.price_slots ||
|
||||
content?.slots ||
|
||||
content?.param === 'priceslot' ||
|
||||
content?.option === 'PriceSlot' ||
|
||||
isPriceSlotsPayload(content))
|
||||
) {
|
||||
handlePriceSlotsResponse(content);
|
||||
addNotification('INFO:Loaded PriceSlot data');
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle streaming messages (with msg field)
|
||||
switch (msg) {
|
||||
case 'priceslot':
|
||||
case 'price_slot':
|
||||
handlePriceSlotsResponse(content);
|
||||
addNotification('INFO:Loaded PriceSlot data');
|
||||
break;
|
||||
case 'start':
|
||||
handleSheetStreamStart(p);
|
||||
addNotification('INFO:Sheet data streaming started');
|
||||
break;
|
||||
case 'chunk':
|
||||
handleSheetStreamChunk(p);
|
||||
if (isPriceSlotsPayload(content)) {
|
||||
handlePriceSlotsResponse(content);
|
||||
} else {
|
||||
handleSheetStreamChunk(p);
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
handleSheetStreamEnd(p);
|
||||
|
|
@ -310,8 +345,15 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
break;
|
||||
default:
|
||||
// Handle other content notifications from sheet-service
|
||||
console.log('[Sheet] Received content:', p.content);
|
||||
console.log('[Sheet] Received content:', content);
|
||||
}
|
||||
} else {
|
||||
console.warn('[Sheet] Ignored content because target does not match current user:', {
|
||||
target,
|
||||
currentUid,
|
||||
msg,
|
||||
content
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -466,19 +508,30 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
// Header for price stream
|
||||
handleRawStreamHeader('price', p);
|
||||
},
|
||||
raw_stream_priceslot: (p) => {
|
||||
handleRawStreamHeader('priceslot', p);
|
||||
},
|
||||
raw_stream_chunk_price: (p) => {
|
||||
// Chunk for price stream
|
||||
handleRawStreamChunk('price', p);
|
||||
},
|
||||
raw_stream_chunk_priceslot: (p) => {
|
||||
handleRawStreamChunk('priceslot', p);
|
||||
},
|
||||
raw_stream_end_price: (p) => {
|
||||
// End for price stream
|
||||
handleRawStreamEnd('price', p);
|
||||
},
|
||||
raw_stream_end_priceslot: (p) => {
|
||||
handleRawStreamEnd('priceslot', p);
|
||||
}
|
||||
};
|
||||
|
||||
export function handleIncomingMessages(raw: string) {
|
||||
const msg: WSMessage = JSON.parse(raw);
|
||||
// console.log(`[WS MSG] type=${msg.type}`, msg.payload);
|
||||
if (msg.type !== 'heartbeat') {
|
||||
console.log(`[WS MSG] type=${msg.type}`, msg.payload);
|
||||
}
|
||||
if (msg == null) {
|
||||
// error response
|
||||
addNotification('ERR:No response from server');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue