MCPcopy Index your code
hub / github.com/coder/coder / unpinChat

Function unpinChat

site/src/api/queries/chats.ts:959–1012  ·  view source on GitHub ↗
(queryClient: QueryClient)

Source from the content-addressed store, hash-verified

957});
958
959export const unpinChat = (queryClient: QueryClient) => ({
960 mutationFn: (chatId: string) =>
961 API.experimental.updateChat(chatId, { pin_order: 0 }),
962 onMutate: async (chatId: string) => {
963 await queryClient.cancelQueries({
964 queryKey: chatsKey,
965 predicate: isChatListQuery,
966 });
967 await queryClient.cancelQueries({
968 queryKey: chatKey(chatId),
969 exact: true,
970 });
971 const previousChat = queryClient.getQueryData<TypesGen.Chat>(
972 chatKey(chatId),
973 );
974 updateInfiniteChatsCache(queryClient, (chats) =>
975 chats.map((chat) =>
976 chat.id === chatId ? { ...chat, pin_order: 0 } : chat,
977 ),
978 );
979 if (previousChat) {
980 queryClient.setQueryData<TypesGen.Chat>(chatKey(chatId), {
981 ...previousChat,
982 pin_order: 0,
983 });
984 }
985 return { previousChat };
986 },
987 onError: (
988 _error: unknown,
989 chatId: string,
990 context:
991 | {
992 previousChat?: TypesGen.Chat;
993 }
994 | undefined,
995 ) => {
996 // Rollback: invalidate to re-fetch the correct state.
997 void invalidateChatListQueries(queryClient);
998 if (context?.previousChat) {
999 queryClient.setQueryData<TypesGen.Chat>(
1000 chatKey(chatId),
1001 context.previousChat,
1002 );
1003 }
1004 },
1005 onSettled: async (_data: unknown, _error: unknown, chatId: string) => {
1006 await invalidateChatListQueries(queryClient);
1007 await queryClient.invalidateQueries({
1008 queryKey: chatKey(chatId),
1009 exact: true,
1010 });
1011 },
1012});
1013
1014export const reorderPinnedChat = (queryClient: QueryClient) => ({
1015 mutationFn: ({ chatId, pinOrder }: { chatId: string; pinOrder: number }) =>

Callers 2

AgentsPageFunction · 0.90
chats.test.tsFile · 0.90

Calls 3

chatKeyFunction · 0.85
updateInfiniteChatsCacheFunction · 0.85

Tested by

no test coverage detected