2c02f2c499
This PR implements a first working version of SSE for View and ViewField. We could improve the logic but we re-use the same actual codepath for refreshing the views of an object. This does not handle filters and sorts for now. # Demo https://github.com/user-attachments/assets/73367f3a-a5fc-4b06-a2e2-fad3b99deec7
30 lines
936 B
TypeScript
30 lines
936 B
TypeScript
import { coreViewsState } from '@/views/states/coreViewState';
|
|
import { type CoreViewWithRelations } from '@/views/types/CoreViewWithRelations';
|
|
import { useStore } from 'jotai';
|
|
import { useCallback } from 'react';
|
|
import { ViewType } from '~/generated-metadata/graphql';
|
|
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
|
|
|
export const useSetIndexViews = () => {
|
|
const store = useStore();
|
|
|
|
const setIndexViews = useCallback(
|
|
(indexViews: CoreViewWithRelations[]) => {
|
|
const existingCoreViews = store.get(coreViewsState.atom);
|
|
const existingFieldsWidgetViews = existingCoreViews.filter(
|
|
(view) => view.type === ViewType.FIELDS_WIDGET,
|
|
);
|
|
const mergedViews = [...indexViews, ...existingFieldsWidgetViews];
|
|
|
|
if (!isDeeplyEqual(existingCoreViews, mergedViews)) {
|
|
store.set(coreViewsState.atom, mergedViews);
|
|
}
|
|
},
|
|
[store],
|
|
);
|
|
|
|
return {
|
|
setIndexViews,
|
|
};
|
|
};
|