@go-avro/avro-js 0.0.7 → 0.0.8-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -164,6 +164,12 @@ declare module '../client/QueryClient' {
164
164
  payment_option_id: string;
165
165
  }[];
166
166
  }>>;
167
+ useCreateMessage(chatId: string): ReturnType<typeof useMutation<{
168
+ id: string;
169
+ }, StandardError, {
170
+ content: string;
171
+ sent_at?: number;
172
+ }>>;
167
173
  useCreateProposal(): ReturnType<typeof useMutation<{
168
174
  id: string;
169
175
  }, StandardError, {
@@ -1,4 +1,4 @@
1
- import { useInfiniteQuery } from "@tanstack/react-query";
1
+ import { useInfiniteQuery, useMutation } from "@tanstack/react-query";
2
2
  import { AvroQueryClient } from "../../client/QueryClient";
3
3
  AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
4
4
  const queryClient = this.getQueryClient();
@@ -28,3 +28,22 @@ AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
28
28
  }
29
29
  return result;
30
30
  };
31
+ AvroQueryClient.prototype.useCreateMessage = function (chatId) {
32
+ const queryClient = this.getQueryClient();
33
+ return useMutation({
34
+ mutationFn: async ({ content, sent_at, id }) => {
35
+ const message = await this.post(`/chat/${chatId}/message`, {
36
+ message: {
37
+ content,
38
+ sent_at: sent_at ?? Math.floor(Date.now() / 1000),
39
+ id,
40
+ },
41
+ });
42
+ return message;
43
+ },
44
+ onMutate: (message) => {
45
+ queryClient.setQueryData(['message', message.id], message);
46
+ queryClient.invalidateQueries({ queryKey: ['messages', chatId] });
47
+ },
48
+ });
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.7",
3
+ "version": "0.0.8-beta.1",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",