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

Function pinChat

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

Source from the content-addressed store, hash-verified

901});
902
903export const pinChat = (queryClient: QueryClient) => ({
904 mutationFn: (chatId: string) =>
905 API.experimental.updateChat(chatId, { pin_order: 1 }),
906 onMutate: async (chatId: string) => {
907 await queryClient.cancelQueries({
908 queryKey: chatsKey,
909 predicate: isChatListQuery,
910 });
911 await queryClient.cancelQueries({
912 queryKey: chatKey(chatId),
913 exact: true,
914 });
915 const previousChat = queryClient.getQueryData<TypesGen.Chat>(
916 chatKey(chatId),
917 );
918 const optimisticPinOrder = getNextOptimisticPinOrder(queryClient);
919 updateInfiniteChatsCache(queryClient, (chats) =>
920 chats.map((chat) =>
921 chat.id === chatId ? { ...chat, pin_order: optimisticPinOrder } : chat,
922 ),
923 );
924 if (previousChat) {
925 queryClient.setQueryData<TypesGen.Chat>(chatKey(chatId), {
926 ...previousChat,
927 pin_order: optimisticPinOrder,
928 });
929 }
930 return { previousChat };
931 },
932 onError: (
933 _error: unknown,
934 chatId: string,
935 context:
936 | {
937 previousChat?: TypesGen.Chat;
938 }
939 | undefined,
940 ) => {
941 // Rollback: invalidate to re-fetch the correct state.
942 void invalidateChatListQueries(queryClient);
943 if (context?.previousChat) {
944 queryClient.setQueryData<TypesGen.Chat>(
945 chatKey(chatId),
946 context.previousChat,
947 );
948 }
949 },
950 onSettled: async (_data: unknown, _error: unknown, chatId: string) => {
951 await invalidateChatListQueries(queryClient);
952 await queryClient.invalidateQueries({
953 queryKey: chatKey(chatId),
954 exact: true,
955 });
956 },
957});
958
959export const unpinChat = (queryClient: QueryClient) => ({
960 mutationFn: (chatId: string) =>

Callers 2

AgentsPageFunction · 0.90
chats.test.tsFile · 0.90

Calls 4

chatKeyFunction · 0.85
updateInfiniteChatsCacheFunction · 0.85

Tested by

no test coverage detected