fix: api watch data
This commit is contained in:
@@ -125,11 +125,21 @@ const useSetChunkRequest = () => {
|
||||
};
|
||||
|
||||
const resetResultSchema = (result: any[]) => {
|
||||
// ============ handle list data ============
|
||||
// return _.map(result, (data: any) => {
|
||||
// if (data.type === WatchEventType.DELETE) {
|
||||
// data.ids = _.map(data.items, (item: any) => item.id);
|
||||
// }
|
||||
// data.collection = data.items || [];
|
||||
// return data;
|
||||
// });
|
||||
// ============ handle list data ============
|
||||
|
||||
return _.map(result, (data: any) => {
|
||||
if (data.type === WatchEventType.DELETE) {
|
||||
data.ids = _.map(data.items, (item: any) => item.id);
|
||||
data.ids = data.data?.id ? [data.data.id] : [];
|
||||
}
|
||||
data.collection = data.items || [];
|
||||
data.collection = data.data ? [data.data] : [];
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ export default function useEventSource() {
|
||||
|
||||
eventSourceRef.current.onmessage = (res: any) => {
|
||||
try {
|
||||
console.log('event source message: ', { res, resData: res });
|
||||
const data = JSON.parse(res.data);
|
||||
console.log('event source message: ', { data, resData: res });
|
||||
onmessage(data);
|
||||
} catch (error) {
|
||||
// error
|
||||
|
||||
@@ -3,8 +3,9 @@ import _ from 'lodash';
|
||||
|
||||
interface ChunkedCollection {
|
||||
ids: string[];
|
||||
data: any;
|
||||
collection: any[];
|
||||
type: string;
|
||||
type: string | number;
|
||||
}
|
||||
// Only used to update lists without nested state
|
||||
export function useUpdateChunkedList(
|
||||
|
||||
Reference in New Issue
Block a user