@notificationapi/react 0.0.35 → 0.0.36

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as z } from "react/jsx-runtime";
2
- import { createContext as Q, useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as P, useContext as Y } from "react";
2
+ import { createContext as Q, useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as S, useContext as Y } from "react";
3
3
  const Z = async (e, r, o, a, f, b, h) => {
4
4
  const l = ee(a, f, b), g = await fetch(
5
5
  `https://${r}/${a}/users/${encodeURIComponent(
@@ -170,16 +170,16 @@ const Z = async (e, r, o, a, f, b, h) => {
170
170
  },
171
171
  ...e,
172
172
  user: "userId" in e ? { id: e.userId } : e.user
173
- }, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, y] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, N] = I(o.webPushOptInMessage), [x, J] = I(!1), W = m(() => {
173
+ }, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, P] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, N] = I(o.webPushOptInMessage), [x, J] = I(!1), W = m(() => {
174
174
  o.playSoundOnNewNotification && new Audio(o.newNotificationSoundPath).play().catch((s) => {
175
175
  console.log("Failed to play new notification sound:", s);
176
176
  });
177
- }, [o.newNotificationSoundPath, o.playSoundOnNewNotification]), S = m((t) => {
177
+ }, [o.newNotificationSoundPath, o.playSoundOnNewNotification]), y = m((t) => {
178
178
  const s = (/* @__PURE__ */ new Date()).toISOString();
179
- f((n) => (t = t.filter((d) => {
179
+ f((n) => (t = Array.isArray(t) ? t : [], t = t.filter((d) => {
180
180
  const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
181
181
  return !p && !D;
182
- }), n ? [
182
+ }), Array.isArray(n) ? [
183
183
  ...t.filter((d) => !n.find((D) => D.id === d.id)),
184
184
  ...n
185
185
  ] : t));
@@ -189,7 +189,7 @@ const Z = async (e, r, o, a, f, b, h) => {
189
189
  userId: o.user.id,
190
190
  hashedUserId: o.hashedUserId,
191
191
  onNewInAppNotifications: (s) => {
192
- W(), S(s);
192
+ W(), y(s);
193
193
  }
194
194
  });
195
195
  return t.identify({
@@ -202,30 +202,30 @@ const Z = async (e, r, o, a, f, b, h) => {
202
202
  o.user.email,
203
203
  o.user.number,
204
204
  o.hashedUserId,
205
- S,
205
+ y,
206
206
  W,
207
207
  e.client
208
208
  ]), L = m(
209
209
  async (t, s) => {
210
210
  const n = await u.rest.getNotifications(t, s);
211
- C(n.oldestReceived), U(n.couldLoadMore), S(n.notifications);
211
+ C(n.oldestReceived), U(n.couldLoadMore), y(n.notifications);
212
212
  },
213
- [S, u.rest]
213
+ [y, u.rest]
214
214
  ), E = T(A), R = T(w), $ = T(k);
215
- P(() => {
215
+ S(() => {
216
216
  E.current = A, R.current = w, $.current = k;
217
217
  }, [A, w, k]);
218
218
  const O = m(
219
219
  async (t) => {
220
220
  if (!(!t && (!E.current || R.current))) {
221
- y(!0);
221
+ P(!0);
222
222
  try {
223
223
  await L(
224
224
  t ? (/* @__PURE__ */ new Date()).toISOString() : $.current,
225
225
  t ? o.initialLoadMaxCount : 1e3
226
226
  );
227
227
  } finally {
228
- y(!1);
228
+ P(!1);
229
229
  }
230
230
  }
231
231
  },
@@ -327,17 +327,17 @@ const Z = async (e, r, o, a, f, b, h) => {
327
327
  o.customServiceWorkerPath,
328
328
  l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
329
329
  ]);
330
- P(() => {
331
- f([]), y(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
330
+ S(() => {
331
+ f([]), P(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
332
332
  h(t);
333
333
  });
334
- }, [u, O, M]), P(() => {
334
+ }, [u, O, M]), S(() => {
335
335
  Notification.permission !== "default" && N(!1), v === "AUTOMATIC" && (N(
336
336
  localStorage.getItem("hideWebPushOptInMessage") !== "true"
337
337
  ), u.getUserAccountMetadata().then((t) => {
338
338
  g(t), N(t.userAccountMetadata.hasWebPushEnabled);
339
339
  }));
340
- }, [u, v]), P(() => {
340
+ }, [u, v]), S(() => {
341
341
  x && M();
342
342
  }, [x, M]);
343
343
  const _ = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.35",
4
+ "version": "0.0.36",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",