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