mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: content list not getting updated
This commit is contained in:
parent
7b57d50c47
commit
6a863e3be0
@ -194,6 +194,8 @@ export const Contents = () => {
|
|||||||
id: params.row.id,
|
id: params.row.id,
|
||||||
params: {
|
params: {
|
||||||
status: !params.row.status,
|
status: !params.row.status,
|
||||||
|
title: params.row.title,
|
||||||
|
entity: (params.row.entity as any).id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
} from "@/types/base.types";
|
} from "@/types/base.types";
|
||||||
import { merge } from "@/utils/object";
|
import { merge } from "@/utils/object";
|
||||||
|
|
||||||
import { useNormalizeAndCache } from "./helpers";
|
import { isSameEntity, useNormalizeAndCache } from "./helpers";
|
||||||
import { useGetFromCache } from "./useGet";
|
import { useGetFromCache } from "./useGet";
|
||||||
import { useEntityApiClient } from "../useApiClient";
|
import { useEntityApiClient } from "../useApiClient";
|
||||||
|
|
||||||
@ -42,12 +42,27 @@ export const useUpdate = <
|
|||||||
) => {
|
) => {
|
||||||
const api = useEntityApiClient<TAttr, TBasic, TFull>(entity);
|
const api = useEntityApiClient<TAttr, TBasic, TFull>(entity);
|
||||||
const normalizeAndCache = useNormalizeAndCache<TBasic, string>(entity);
|
const normalizeAndCache = useNormalizeAndCache<TBasic, string>(entity);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { invalidate = true } = options || {};
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({ id, params }) => {
|
mutationFn: async ({ id, params }) => {
|
||||||
const data = await api.update(id, params);
|
const data = await api.update(id, params);
|
||||||
const { entities, result } = normalizeAndCache(data);
|
const { entities, result } = normalizeAndCache(data);
|
||||||
|
|
||||||
|
if (invalidate) {
|
||||||
|
queryClient.removeQueries({
|
||||||
|
predicate: ({ queryKey }) => {
|
||||||
|
const [qType, qEntity] = queryKey;
|
||||||
|
|
||||||
|
return (
|
||||||
|
(qType === QueryType.count || qType === QueryType.collection) &&
|
||||||
|
isSameEntity(qEntity, entity)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return entities[entity]?.[result] as unknown as TBasic;
|
return entities[entity]?.[result] as unknown as TBasic;
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
|
Loading…
Reference in New Issue
Block a user