@ttt-productions/notification-core 0.4.7 → 0.4.9
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,8 +1,8 @@
|
|
|
1
1
|
import type { UseUnreadCountOptions } from '../../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Unread-count badge backed by a Firestore `count()` aggregation (a server-side
|
|
4
|
-
* count, not a doc fetch)
|
|
5
|
-
* (`hasMore` → `99+`).
|
|
4
|
+
* count, not a doc fetch), via query-core's `useFirestoreCount`. Polls for cost
|
|
5
|
+
* control; displays capped (`hasMore` → `99+`).
|
|
6
6
|
*
|
|
7
7
|
* - **personal** categories count **unseen** active items (`seenAt == 0`),
|
|
8
8
|
* scoped to the caller (`targetUserId == uid`);
|
|
@@ -44,8 +44,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
44
44
|
isRefetching: boolean;
|
|
45
45
|
isStale: boolean;
|
|
46
46
|
isEnabled: boolean;
|
|
47
|
-
refetch: (options?: import("@tanstack/
|
|
48
|
-
fetchStatus: import("@tanstack/
|
|
47
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
48
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
49
49
|
promise: Promise<number>;
|
|
50
50
|
count: number;
|
|
51
51
|
hasMore: boolean;
|
|
@@ -72,8 +72,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
72
72
|
isRefetching: boolean;
|
|
73
73
|
isStale: boolean;
|
|
74
74
|
isEnabled: boolean;
|
|
75
|
-
refetch: (options?: import("@tanstack/
|
|
76
|
-
fetchStatus: import("@tanstack/
|
|
75
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
76
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
77
77
|
promise: Promise<number>;
|
|
78
78
|
count: number;
|
|
79
79
|
hasMore: boolean;
|
|
@@ -100,8 +100,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
100
100
|
isRefetching: boolean;
|
|
101
101
|
isStale: boolean;
|
|
102
102
|
isEnabled: boolean;
|
|
103
|
-
refetch: (options?: import("@tanstack/
|
|
104
|
-
fetchStatus: import("@tanstack/
|
|
103
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
104
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
105
105
|
promise: Promise<number>;
|
|
106
106
|
count: number;
|
|
107
107
|
hasMore: boolean;
|
|
@@ -128,8 +128,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
128
128
|
isRefetching: boolean;
|
|
129
129
|
isStale: boolean;
|
|
130
130
|
isEnabled: boolean;
|
|
131
|
-
refetch: (options?: import("@tanstack/
|
|
132
|
-
fetchStatus: import("@tanstack/
|
|
131
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
132
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
133
133
|
promise: Promise<number>;
|
|
134
134
|
count: number;
|
|
135
135
|
hasMore: boolean;
|
|
@@ -156,8 +156,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
156
156
|
isRefetching: boolean;
|
|
157
157
|
isStale: boolean;
|
|
158
158
|
isEnabled: boolean;
|
|
159
|
-
refetch: (options?: import("@tanstack/
|
|
160
|
-
fetchStatus: import("@tanstack/
|
|
159
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
160
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
161
161
|
promise: Promise<number>;
|
|
162
162
|
count: number;
|
|
163
163
|
hasMore: boolean;
|
|
@@ -184,8 +184,8 @@ export declare function useUnreadCount({ config, userId, category, enabled, refe
|
|
|
184
184
|
isRefetching: boolean;
|
|
185
185
|
isStale: boolean;
|
|
186
186
|
isEnabled: boolean;
|
|
187
|
-
refetch: (options?: import("@tanstack/
|
|
188
|
-
fetchStatus: import("@tanstack/
|
|
187
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<number, Error>>;
|
|
188
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
189
189
|
promise: Promise<number>;
|
|
190
190
|
count: number;
|
|
191
191
|
hasMore: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnreadCount.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useUnreadCount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnreadCount.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useUnreadCount.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAK5D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,OAAc,EACd,eAA0C,EAC1C,UAAgC,GACjC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BvB"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useFirestoreDb } from '@ttt-productions/query-core/react';
|
|
2
|
+
import { where } from 'firebase/firestore';
|
|
3
|
+
import { useFirestoreCount } from '@ttt-productions/query-core/react';
|
|
5
4
|
const DEFAULT_REFETCH_INTERVAL = 30_000;
|
|
6
5
|
const DEFAULT_COUNT_LIMIT = 99;
|
|
7
6
|
/**
|
|
8
7
|
* Unread-count badge backed by a Firestore `count()` aggregation (a server-side
|
|
9
|
-
* count, not a doc fetch)
|
|
10
|
-
* (`hasMore` → `99+`).
|
|
8
|
+
* count, not a doc fetch), via query-core's `useFirestoreCount`. Polls for cost
|
|
9
|
+
* control; displays capped (`hasMore` → `99+`).
|
|
11
10
|
*
|
|
12
11
|
* - **personal** categories count **unseen** active items (`seenAt == 0`),
|
|
13
12
|
* scoped to the caller (`targetUserId == uid`);
|
|
@@ -27,24 +26,19 @@ const DEFAULT_COUNT_LIMIT = 99;
|
|
|
27
26
|
* ```
|
|
28
27
|
*/
|
|
29
28
|
export function useUnreadCount({ config, userId, category, enabled = true, refetchInterval = DEFAULT_REFETCH_INTERVAL, countLimit = DEFAULT_COUNT_LIMIT, }) {
|
|
30
|
-
const db = useFirestoreDb();
|
|
31
29
|
const categoryConfig = config.categories[category];
|
|
32
30
|
if (!categoryConfig) {
|
|
33
31
|
throw new Error(`[notification-core] Unknown category: ${category}`);
|
|
34
32
|
}
|
|
35
33
|
const collectionPath = categoryConfig.activePath;
|
|
36
34
|
const isPersonal = categoryConfig.audienceType === 'personal';
|
|
37
|
-
const
|
|
35
|
+
const constraints = isPersonal && userId
|
|
36
|
+
? [where('targetUserId', '==', userId), where('seenAt', '==', 0)]
|
|
37
|
+
: [];
|
|
38
|
+
const { data, ...rest } = useFirestoreCount({
|
|
39
|
+
collectionPath,
|
|
38
40
|
queryKey: ['notifications', 'unread-count', category, userId],
|
|
39
|
-
|
|
40
|
-
const collectionRef = collection(db, collectionPath);
|
|
41
|
-
const constraints = isPersonal
|
|
42
|
-
? [where('targetUserId', '==', userId), where('seenAt', '==', 0)]
|
|
43
|
-
: [];
|
|
44
|
-
const q = constraints.length > 0 ? query(collectionRef, ...constraints) : collectionRef;
|
|
45
|
-
const snapshot = await getCountFromServer(q);
|
|
46
|
-
return snapshot.data().count;
|
|
47
|
-
},
|
|
41
|
+
constraints,
|
|
48
42
|
enabled: enabled && !!userId,
|
|
49
43
|
staleTime: refetchInterval,
|
|
50
44
|
refetchInterval,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnreadCount.js","sourceRoot":"","sources":["../../../src/react/hooks/useUnreadCount.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useUnreadCount.js","sourceRoot":"","sources":["../../../src/react/hooks/useUnreadCount.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,KAAK,EAAwB,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,eAAe,GAAG,wBAAwB,EAC1C,UAAU,GAAG,mBAAmB,GACV;IACtB,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC;IACjD,MAAM,UAAU,GAAG,cAAc,CAAC,YAAY,KAAK,UAAU,CAAC;IAE9D,MAAM,WAAW,GACf,UAAU,IAAI,MAAM;QAClB,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,EAAE,CAAC;IAET,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,iBAAiB,CAAC;QAC1C,cAAc;QACd,QAAQ,EAAE,CAAC,eAAe,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC;QAC7D,WAAW;QACX,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC,MAAM;QAC5B,SAAS,EAAE,eAAe;QAC1B,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC;IAExB,OAAO;QACL,KAAK;QACL,OAAO,EAAE,KAAK,GAAG,UAAU;QAC3B,GAAG,IAAI;KACR,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttt-productions/notification-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Shared notification system for TTT Productions apps — active/history two-tier architecture with dedup, batch processing, and themed UI components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@tanstack/react-query": ">=5.0.0",
|
|
42
|
-
"@ttt-productions/query-core": "^0.8.
|
|
43
|
-
"@ttt-productions/ui-core": "^0.6.
|
|
42
|
+
"@ttt-productions/query-core": "^0.8.6",
|
|
43
|
+
"@ttt-productions/ui-core": "^0.6.4",
|
|
44
44
|
"firebase": ">=10.0.0",
|
|
45
45
|
"react": ">=18.0.0",
|
|
46
46
|
"react-dom": ">=18.0.0"
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@tanstack/react-query": "^5.0.0",
|
|
70
|
-
"@ttt-productions/query-core": "0.8.
|
|
71
|
-
"@ttt-productions/ui-core": "0.6.
|
|
70
|
+
"@ttt-productions/query-core": "^0.8.6",
|
|
71
|
+
"@ttt-productions/ui-core": "^0.6.4",
|
|
72
72
|
"@types/react": "^19.0.0",
|
|
73
73
|
"@types/react-dom": "^19.0.0",
|
|
74
74
|
"firebase": "^11.0.0",
|