@nivaro/react 0.3.17 → 0.3.18

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.
@@ -564,13 +564,17 @@ function ot(e, t = {}) {
564
564
  t.sender && (n.sender = t.sender), t.room && (n.room = t.room), t.from && (n.from = t.from), t.to && (n.to = t.to), t.has_attachment && (n.has_attachment = "1"), t.mentions_me && (n.mentions_me = "1");
565
565
  const o = Object.keys(n).length > 1, { data: r, isLoading: a } = y({
566
566
  queryKey: ["nvr-chat-search", n],
567
- queryFn: async () => (await s.request(
568
- g("/chat/search", n)
569
- )).data ?? [],
567
+ queryFn: async () => {
568
+ var c;
569
+ const i = await s.request(
570
+ g("/chat/search", n)
571
+ );
572
+ return { hits: i.data ?? [], meaning: ((c = i.meta) == null ? void 0 : c.meaning) ?? null };
573
+ },
570
574
  enabled: e.trim().length >= 2 || o,
571
575
  staleTime: 15e3
572
576
  });
573
- return { hits: r ?? [], loading: a };
577
+ return { hits: (r == null ? void 0 : r.hits) ?? [], meaning: (r == null ? void 0 : r.meaning) ?? null, loading: a };
574
578
  }
575
579
  function at() {
576
580
  const e = m(), t = v();
@@ -1,59 +1,76 @@
1
- import { useQueryClient as C, useQuery as I } from "@tanstack/react-query";
2
- import { useEffect as f, useRef as h } from "react";
3
- import { useNivaroClient as R } from "../../context.js";
4
- import { get as E, put as Q, del as S } from "../../lib/commands.js";
5
- import { useOptionalRealtime as D } from "../../lib/realtime.js";
6
- const U = 1500, l = Math.random().toString(36).slice(2, 12);
7
- function M(t = !0) {
8
- const r = R(), e = D(), a = C(), { data: s } = I({
1
+ import { useQueryClient as D, useQuery as U } from "@tanstack/react-query";
2
+ import { useEffect as d, useRef as f } from "react";
3
+ import { useNivaroClient as I } from "../../context.js";
4
+ import { get as Q, put as $, del as g } from "../../lib/commands.js";
5
+ import { useOptionalRealtime as S } from "../../lib/realtime.js";
6
+ const K = 1500, h = Math.random().toString(36).slice(2, 12);
7
+ function x(e = !0) {
8
+ const r = I(), n = S(), l = D(), { data: s } = U({
9
9
  queryKey: ["nvr-chat-drafts"],
10
- queryFn: () => r.request(E("/chat/drafts")).then((u) => (u.data ?? []).map((d) => d.room)),
11
- enabled: t,
10
+ queryFn: () => r.request(Q("/chat/drafts")).then((i) => (i.data ?? []).map((m) => m.room)),
11
+ enabled: e,
12
12
  staleTime: 6e4
13
13
  });
14
- return f(() => {
15
- if (!(!t || !e))
16
- return e.on(
14
+ return d(() => {
15
+ if (!(!e || !n))
16
+ return n.on(
17
17
  "chat:draft",
18
- () => void a.invalidateQueries({ queryKey: ["nvr-chat-drafts"] })
18
+ () => void l.invalidateQueries({ queryKey: ["nvr-chat-drafts"] })
19
19
  );
20
- }, [t, e, a]), new Set(s ?? []);
20
+ }, [e, n, l]), new Set(s ?? []);
21
21
  }
22
- function N(t, r, e, a) {
23
- const s = R(), u = D(), d = C(), c = h(""), p = h(e);
24
- p.current = e;
25
- const m = h(!1), q = async (n) => {
26
- var o;
22
+ function B(e, r, n, l) {
23
+ const s = I(), i = S(), m = D(), c = f(""), v = f(n);
24
+ v.current = n;
25
+ const y = f(!1), q = async (t) => {
26
+ var u;
27
27
  try {
28
- const i = ((o = (await s.request(
29
- E(`/chat/drafts/${encodeURIComponent(t)}`)
30
- )).data) == null ? void 0 : o.body) ?? "", y = p.current;
31
- (n ? y === "" : y === c.current) ? (c.current = i, i !== y && a(i)) : n && (c.current = i);
28
+ const a = ((u = (await s.request(
29
+ Q(`/chat/drafts/${encodeURIComponent(e)}`)
30
+ )).data) == null ? void 0 : u.body) ?? "", p = v.current;
31
+ (t ? p === "" : p === c.current) ? (c.current = a, a !== p && l(a)) : t && (c.current = a);
32
32
  } catch {
33
33
  } finally {
34
- m.current = !0;
34
+ y.current = !0;
35
35
  }
36
36
  };
37
- f(() => {
38
- r && (m.current = !1, c.current = "", q(!0));
39
- }, [t, r]), f(() => {
40
- if (!(!r || !u))
41
- return u.on("chat:draft", (n) => {
42
- !n || n.room !== t || n.device === l || q(!1);
37
+ d(() => {
38
+ r && (y.current = !1, c.current = "", q(!0));
39
+ }, [e, r]), d(() => {
40
+ if (!(!r || !i))
41
+ return i.on("chat:draft", (t) => {
42
+ !t || t.room !== e || t.device === h || q(!1);
43
43
  });
44
- }, [r, u, t]), f(() => {
45
- if (!r || !m.current || e === c.current) return;
46
- const n = setTimeout(() => {
47
- const o = e, v = () => {
48
- c.current = o, d.invalidateQueries({ queryKey: ["nvr-chat-drafts"] });
44
+ }, [r, i, e]);
45
+ const C = (t, u) => {
46
+ const E = () => {
47
+ t === R.current && (c.current = u), m.invalidateQueries({ queryKey: ["nvr-chat-drafts"] });
48
+ };
49
+ (u.trim() ? s.request($(`/chat/drafts/${encodeURIComponent(t)}`, { body: u, device: h })) : s.request(g(`/chat/drafts/${encodeURIComponent(t)}?device=${h}`))).then(E).catch(() => {
50
+ });
51
+ }, R = f(e);
52
+ R.current = e;
53
+ const o = f(null);
54
+ d(() => {
55
+ if (!r || !y.current) return;
56
+ if (n === c.current) {
57
+ o.current = null;
58
+ return;
59
+ }
60
+ o.current = { room: e, body: n };
61
+ const t = setTimeout(() => {
62
+ o.current = null, C(e, n);
63
+ }, K);
64
+ return () => clearTimeout(t);
65
+ }, [n, e, r]), d(() => {
66
+ if (r)
67
+ return () => {
68
+ const t = o.current;
69
+ o.current = null, t && t.room === e && C(t.room, t.body);
49
70
  };
50
- (o.trim() ? s.request(Q(`/chat/drafts/${encodeURIComponent(t)}`, { body: o, device: l })) : s.request(S(`/chat/drafts/${encodeURIComponent(t)}?device=${l}`))).then(v).catch(() => {
51
- });
52
- }, U);
53
- return () => clearTimeout(n);
54
- }, [e, t, r]);
71
+ }, [e, r]);
55
72
  }
56
73
  export {
57
- M as useDraftRooms,
58
- N as useDraftSync
74
+ x as useDraftRooms,
75
+ B as useDraftSync
59
76
  };