nicolium: migrate compose
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@@ -3,10 +3,10 @@ import { create } from 'mutative';
|
||||
import { mediaAttachmentSchema } from 'pl-api';
|
||||
import * as v from 'valibot';
|
||||
|
||||
import { useAppDispatch } from '@/hooks/use-app-dispatch';
|
||||
import { useOwnAccount } from '@/hooks/use-own-account';
|
||||
import { filteredArray } from '@/schemas/utils';
|
||||
import KVStore from '@/storage/kv-store';
|
||||
import { useComposeStore } from '@/stores/compose';
|
||||
import { APIEntity } from '@/types/entities';
|
||||
|
||||
const draftStatusSchema = v.pipe(
|
||||
@@ -72,27 +72,24 @@ const useDraftStatusesCountQuery = () =>
|
||||
|
||||
const usePersistDraftStatus = () => {
|
||||
const { data: account } = useOwnAccount();
|
||||
const dispatch = useAppDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return (composeId: string) => {
|
||||
dispatch((_, getState) => {
|
||||
const compose = getState().compose[composeId];
|
||||
const compose = useComposeStore.getState().actions.getCompose(composeId);
|
||||
|
||||
const draft = {
|
||||
...compose,
|
||||
draft_id: compose.draftId ?? crypto.randomUUID(),
|
||||
};
|
||||
const draft = {
|
||||
...compose,
|
||||
draft_id: compose.draftId ?? crypto.randomUUID(),
|
||||
};
|
||||
|
||||
const drafts = queryClient.getQueryData<Record<string, DraftStatus>>(['draftStatuses']) ?? {};
|
||||
const drafts = queryClient.getQueryData<Record<string, DraftStatus>>(['draftStatuses']) ?? {};
|
||||
|
||||
const newDrafts: Record<string, DraftStatus> = create(drafts, (oldDrafts) => {
|
||||
oldDrafts[draft.draft_id] = v.parse(draftStatusSchema, draft);
|
||||
});
|
||||
return persistDrafts(account!.url, newDrafts).then(() =>
|
||||
queryClient.invalidateQueries({ queryKey: ['draftStatuses'] }),
|
||||
);
|
||||
const newDrafts: Record<string, DraftStatus> = create(drafts, (oldDrafts) => {
|
||||
oldDrafts[draft.draft_id] = v.parse(draftStatusSchema, draft);
|
||||
});
|
||||
return persistDrafts(account!.url, newDrafts).then(() =>
|
||||
queryClient.invalidateQueries({ queryKey: ['draftStatuses'] }),
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type InfiniteData, infiniteQueryOptions, type QueryKey } from '@tanstack/react-query';
|
||||
|
||||
import { store } from '@/store';
|
||||
import { getClient } from '@/api';
|
||||
|
||||
import {
|
||||
PaginatedResponseArray,
|
||||
@@ -23,8 +23,7 @@ const makePaginatedResponseQueryOptions =
|
||||
(...params: T1) =>
|
||||
infiniteQueryOptions({
|
||||
queryKey: typeof queryKey === 'object' ? queryKey : queryKey(...params),
|
||||
queryFn: ({ pageParam }) =>
|
||||
pageParam.next?.() ?? queryFn(store.getState().auth.client, params),
|
||||
queryFn: ({ pageParam }) => pageParam.next?.() ?? queryFn(getClient(), params),
|
||||
initialPageParam: {
|
||||
previous: null,
|
||||
next: null,
|
||||
|
||||
Reference in New Issue
Block a user