mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
B: Fix library cache updates
This commit is contained in:
parent
fd47a4560a
commit
227b0dd72c
|
@ -7,6 +7,11 @@ import { usePreferencesStore } from '@/stores/preferences';
|
|||
|
||||
import { libraryApi } from './api';
|
||||
|
||||
export function useLibraryListKey() {
|
||||
const adminMode = usePreferencesStore(state => state.adminMode);
|
||||
return libraryApi.getLibraryQueryOptions({ isAdmin: adminMode }).queryKey;
|
||||
}
|
||||
|
||||
export function useLibrarySuspense() {
|
||||
const adminMode = usePreferencesStore(state => state.adminMode);
|
||||
const { user } = useAuthSuspense();
|
||||
|
|
|
@ -7,9 +7,11 @@ import { KEYS } from '@/backend/configuration';
|
|||
|
||||
import { libraryApi } from './api';
|
||||
import { type AccessPolicy, type ILibraryItem } from './types';
|
||||
import { useLibraryListKey } from './use-library';
|
||||
|
||||
export const useSetAccessPolicy = () => {
|
||||
const client = useQueryClient();
|
||||
const libraryKey = useLibraryListKey();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-location'],
|
||||
mutationFn: libraryApi.setAccessPolicy,
|
||||
|
@ -36,7 +38,7 @@ export const useSetAccessPolicy = () => {
|
|||
client.setQueryData(rsKey, (prev: IRSFormDTO | undefined) =>
|
||||
!prev ? undefined : { ...prev, access_policy: variables.policy }
|
||||
);
|
||||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
client.setQueryData(libraryKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, access_policy: variables.policy } : item))
|
||||
);
|
||||
},
|
||||
|
|
|
@ -7,9 +7,11 @@ import { KEYS } from '@/backend/configuration';
|
|||
|
||||
import { libraryApi } from './api';
|
||||
import { type ILibraryItem } from './types';
|
||||
import { useLibraryListKey } from './use-library';
|
||||
|
||||
export const useSetLocation = () => {
|
||||
const client = useQueryClient();
|
||||
const libraryKey = useLibraryListKey();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-location'],
|
||||
mutationFn: libraryApi.setLocation,
|
||||
|
@ -36,7 +38,7 @@ export const useSetLocation = () => {
|
|||
client.setQueryData(rsKey, (prev: IRSFormDTO | undefined) =>
|
||||
!prev ? undefined : { ...prev, location: variables.location }
|
||||
);
|
||||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
client.setQueryData(libraryKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, location: variables.location } : item))
|
||||
);
|
||||
},
|
||||
|
|
|
@ -7,9 +7,11 @@ import { KEYS } from '@/backend/configuration';
|
|||
|
||||
import { libraryApi } from './api';
|
||||
import { type ILibraryItem } from './types';
|
||||
import { useLibraryListKey } from './use-library';
|
||||
|
||||
export const useSetOwner = () => {
|
||||
const client = useQueryClient();
|
||||
const libraryKey = useLibraryListKey();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-owner'],
|
||||
mutationFn: libraryApi.setOwner,
|
||||
|
@ -36,7 +38,7 @@ export const useSetOwner = () => {
|
|||
client.setQueryData(rsKey, (prev: IRSFormDTO | undefined) =>
|
||||
!prev ? undefined : { ...prev, owner: variables.owner }
|
||||
);
|
||||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
client.setQueryData(libraryKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, owner: variables.owner } : item))
|
||||
);
|
||||
},
|
||||
|
|
|
@ -7,9 +7,11 @@ import { KEYS } from '@/backend/configuration';
|
|||
|
||||
import { libraryApi } from './api';
|
||||
import { type ILibraryItem, type IUpdateLibraryItemDTO, LibraryItemType } from './types';
|
||||
import { useLibraryListKey } from './use-library';
|
||||
|
||||
export const useUpdateItem = () => {
|
||||
const client = useQueryClient();
|
||||
const libraryKey = useLibraryListKey();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'update-item'],
|
||||
mutationFn: libraryApi.updateItem,
|
||||
|
@ -18,7 +20,7 @@ export const useUpdateItem = () => {
|
|||
data.item_type === LibraryItemType.RSFORM
|
||||
? KEYS.composite.rsItem({ itemID: data.id })
|
||||
: KEYS.composite.ossItem({ itemID: data.id });
|
||||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
client.setQueryData(libraryKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === data.id ? data : item))
|
||||
);
|
||||
client.setQueryData(itemKey, (prev: IRSFormDTO | IOperationSchemaDTO | undefined) =>
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { libraryApi } from './api';
|
||||
import { type ILibraryItem } from './types';
|
||||
import { useLibraryListKey } from './use-library';
|
||||
|
||||
export function useUpdateTimestamp() {
|
||||
const client = useQueryClient();
|
||||
const libraryKey = useLibraryListKey();
|
||||
return {
|
||||
updateTimestamp: (target: number) =>
|
||||
client.setQueryData(
|
||||
libraryApi.libraryListKey, //
|
||||
libraryKey, //
|
||||
(prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === target ? { ...item, time_update: Date() } : item))
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user