nicolium: kompilator wytrzyma

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-27 01:53:08 +01:00
parent 9c2d7b3788
commit 2ed029247b
3 changed files with 19 additions and 12 deletions

View File

@ -39,22 +39,29 @@ const normalizeChatMessage = (
type ChatMessage = ReturnType<typeof normalizeChatMessage>;
const normalizeChatMessagesList = ({
previous,
next,
items,
...response
}: PaginatedResponse<BaseChatMessage>): PaginatedResponse<ChatMessage> => ({
...response,
previous: previous ? () => previous().then((res) => normalizeChatMessagesList(res)) : null,
next: next ? () => next().then((res) => normalizeChatMessagesList(res)) : null,
items: items.map(normalizeChatMessage),
});
const useChatMessages = (chat: Chat) => {
const client = useClient();
const isBlocked = !!useRelationshipQuery(chat?.account.id).data?.blocked_by;
const getChatMessages = async (
chatId: string,
pageParam?: Pick<PaginatedResponse<BaseChatMessage>, 'next'>,
pageParam?: Pick<PaginatedResponse<ChatMessage>, 'next'>,
) => {
const response = await (pageParam?.next
? pageParam.next()
: client.chats.getChatMessages(chatId));
if (pageParam?.next) return pageParam.next();
return {
...response,
items: response.items.map(normalizeChatMessage),
};
return normalizeChatMessagesList(await client.chats.getChatMessages(chatId));
};
const queryInfo = useInfiniteQuery({
@ -63,11 +70,11 @@ const useChatMessages = (chat: Chat) => {
enabled: !isBlocked,
gcTime: 0,
staleTime: 0,
initialPageParam: { next: null as (() => Promise<PaginatedResponse<BaseChatMessage>>) | null },
initialPageParam: { next: null as (() => Promise<PaginatedResponse<ChatMessage>>) | null },
getNextPageParam: (config) => (config.next ? config : undefined),
});
const data = flattenPages<ChatMessage>(queryInfo.data as any)?.toReversed();
const data = flattenPages<ChatMessage>(queryInfo.data)?.toReversed();
return {
...queryInfo,

View File

@ -19,7 +19,7 @@ type Me = string | null | false;
const initialState: Me = null;
const handleForbidden = (state: Me, error: { response: PlfeResponse }) => {
if (([401, 403] as any[]).includes(error.response?.status)) {
if (error.response?.status && [401, 403].includes(error.response.status)) {
return false;
}
return state;

View File

@ -14,7 +14,7 @@ import type { Chat } from 'pl-api';
* @param newChat - Chat entity.
*/
const updateChatInChatSearchQuery = (newChat: Chat) => {
updatePageItem<Chat>(queryKeys.chats.search, newChat as any, (o, n) => o.id === n.id);
updatePageItem<Chat>(queryKeys.chats.search, newChat, (o, n) => o.id === n.id);
};
/**