stream-chat-react-native-core 9.10.2-beta.1 → 9.10.2-beta.3
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.
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewPollLabel.js +4 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewPollLabel.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewPollLabel.js +4 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewPollLabel.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/hooks/useTranslatedMessage.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/ChannelPreview/hooks/__tests__/useChannelPreviewPollLabel.test.tsx +86 -0
- package/src/components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts +1 -1
- package/src/version.json +1 -1
|
@@ -22,7 +22,10 @@ var useChannelPreviewPollLabel = ({
|
|
|
22
22
|
var pollState = (_useStateStore = (0, _useStateStore2.useStateStore)(poll == null ? void 0 : poll.state, selector)) != null ? _useStateStore : {};
|
|
23
23
|
var latestVotesByOption = pollState.latest_votes_by_option,
|
|
24
24
|
pollOptions = pollState.options;
|
|
25
|
-
var latestVotes = (0, _react.useMemo)(() => latestVotesByOption ? Object.values(latestVotesByOption).
|
|
25
|
+
var latestVotes = (0, _react.useMemo)(() => latestVotesByOption ? Object.values(latestVotesByOption).flatMap(votes => {
|
|
26
|
+
var _votes$;
|
|
27
|
+
return (_votes$ = votes == null ? void 0 : votes[0]) != null ? _votes$ : [];
|
|
28
|
+
}).sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) : [], [latestVotesByOption]);
|
|
26
29
|
return (0, _react.useMemo)(() => {
|
|
27
30
|
if (!(latestVotes && latestVotes.length && latestVotes[0].user)) return;
|
|
28
31
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_ChatContext","_TranslationContext","_useStateStore2","selector","nextValue","latest_votes_by_option","options","useChannelPreviewPollLabel","pollId","_useStateStore","_client$user2","_useChatContext","useChatContext","client","_useTranslationContex","useTranslationContext","t","poll","polls","fromState","pollState","useStateStore","state","latestVotesByOption","pollOptions","latestVotes","useMemo","Object","values","
|
|
1
|
+
{"version":3,"names":["_react","require","_ChatContext","_TranslationContext","_useStateStore2","selector","nextValue","latest_votes_by_option","options","useChannelPreviewPollLabel","pollId","_useStateStore","_client$user2","_useChatContext","useChatContext","client","_useTranslationContex","useTranslationContext","t","poll","polls","fromState","pollState","useStateStore","state","latestVotesByOption","pollOptions","latestVotes","useMemo","Object","values","flatMap","votes","_votes$","sort","a","b","Date","created_at","getTime","length","user","_client$user","option","find","id","option_id","voteUser","text","name","exports"],"sourceRoot":"../../../../../src","sources":["components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAMA,IAAMI,QAAQ,GAAIC,SAAoB,KAAM;EAC1CC,sBAAsB,EAAED,SAAS,CAACC,sBAAsB;EACxDC,OAAO,EAAEF,SAAS,CAACE;AACrB,CAAC,CAAC;AAOK,IAAMC,0BAA0B,GAAGA,CAAC;EAAEC;AAAwC,CAAC,KAAK;EAAA,IAAAC,cAAA,EAAAC,aAAA;EACzF,IAAAC,eAAA,GAAmB,IAAAC,2BAAc,EAAC,CAAC;IAA3BC,MAAM,GAAAF,eAAA,CAANE,MAAM;EACd,IAAAC,qBAAA,GAAc,IAAAC,yCAAqB,EAAC,CAAC;IAA7BC,CAAC,GAAAF,qBAAA,CAADE,CAAC;EACT,IAAMC,IAAI,GAAGJ,MAAM,CAACK,KAAK,CAACC,SAAS,CAACX,MAAM,CAAC;EAC3C,IAAMY,SAAS,IAAAX,cAAA,GAAG,IAAAY,6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B,MAAM,EAAEA,MAAM,oBAANA,MAAM,CAAEK;QAAK,CAAC,CAAC;MAC/D,CAAC,MAAM;QACL,OAAO9B,CAAC,CAAC,gCAAgC,EAAE;UACzCuB,IAAI,EAAEM,QAAQ,CAACE,IAAI,IAAIF,QAAQ,CAACF,EAAE;UAClCF,MAAM,EAAEA,MAAM,oBAANA,MAAM,CAAEK;QAClB,CAAC,CAAC;MACJ;IACF;EACF,CAAC,EAAE,CAACrB,WAAW,EAAED,WAAW,GAAAd,aAAA,GAAEG,MAAM,CAAC0B,IAAI,qBAAX7B,aAAA,CAAaiC,EAAE,EAAE3B,CAAC,CAAC,CAAC;AACpD,CAAC;AAACgC,OAAA,CAAAzC,0BAAA,GAAAA,0BAAA","ignoreList":[]}
|
|
@@ -22,7 +22,10 @@ var useChannelPreviewPollLabel = ({
|
|
|
22
22
|
var pollState = (_useStateStore = (0, _useStateStore2.useStateStore)(poll == null ? void 0 : poll.state, selector)) != null ? _useStateStore : {};
|
|
23
23
|
var latestVotesByOption = pollState.latest_votes_by_option,
|
|
24
24
|
pollOptions = pollState.options;
|
|
25
|
-
var latestVotes = (0, _react.useMemo)(() => latestVotesByOption ? Object.values(latestVotesByOption).
|
|
25
|
+
var latestVotes = (0, _react.useMemo)(() => latestVotesByOption ? Object.values(latestVotesByOption).flatMap(votes => {
|
|
26
|
+
var _votes$;
|
|
27
|
+
return (_votes$ = votes == null ? void 0 : votes[0]) != null ? _votes$ : [];
|
|
28
|
+
}).sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) : [], [latestVotesByOption]);
|
|
26
29
|
return (0, _react.useMemo)(() => {
|
|
27
30
|
if (!(latestVotes && latestVotes.length && latestVotes[0].user)) return;
|
|
28
31
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_ChatContext","_TranslationContext","_useStateStore2","selector","nextValue","latest_votes_by_option","options","useChannelPreviewPollLabel","pollId","_useStateStore","_client$user2","_useChatContext","useChatContext","client","_useTranslationContex","useTranslationContext","t","poll","polls","fromState","pollState","useStateStore","state","latestVotesByOption","pollOptions","latestVotes","useMemo","Object","values","
|
|
1
|
+
{"version":3,"names":["_react","require","_ChatContext","_TranslationContext","_useStateStore2","selector","nextValue","latest_votes_by_option","options","useChannelPreviewPollLabel","pollId","_useStateStore","_client$user2","_useChatContext","useChatContext","client","_useTranslationContex","useTranslationContext","t","poll","polls","fromState","pollState","useStateStore","state","latestVotesByOption","pollOptions","latestVotes","useMemo","Object","values","flatMap","votes","_votes$","sort","a","b","Date","created_at","getTime","length","user","_client$user","option","find","id","option_id","voteUser","text","name","exports"],"sourceRoot":"../../../../../src","sources":["components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAMA,IAAMI,QAAQ,GAAIC,SAAoB,KAAM;EAC1CC,sBAAsB,EAAED,SAAS,CAACC,sBAAsB;EACxDC,OAAO,EAAEF,SAAS,CAACE;AACrB,CAAC,CAAC;AAOK,IAAMC,0BAA0B,GAAGA,CAAC;EAAEC;AAAwC,CAAC,KAAK;EAAA,IAAAC,cAAA,EAAAC,aAAA;EACzF,IAAAC,eAAA,GAAmB,IAAAC,2BAAc,EAAC,CAAC;IAA3BC,MAAM,GAAAF,eAAA,CAANE,MAAM;EACd,IAAAC,qBAAA,GAAc,IAAAC,yCAAqB,EAAC,CAAC;IAA7BC,CAAC,GAAAF,qBAAA,CAADE,CAAC;EACT,IAAMC,IAAI,GAAGJ,MAAM,CAACK,KAAK,CAACC,SAAS,CAACX,MAAM,CAAC;EAC3C,IAAMY,SAAS,IAAAX,cAAA,GAAG,IAAAY,6BAAa,EAACJ,IAAI,oBAAJA,IAAI,CAAEK,KAAK,EAAEnB,QAAQ,CAAC,YAAAM,cAAA,GAAK,CAAC,CAAe;E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AC,gCAAgC,EAAE;UACzCuB,IAAI,EAAEM,QAAQ,CAACE,IAAI,IAAIF,QAAQ,CAACF,EAAE;UAClCF,MAAM,EAAEA,MAAM,oBAANA,MAAM,CAAEK;QAClB,CAAC,CAAC;MACJ;IACF;EACF,CAAC,EAAE,CAACrB,WAAW,EAAED,WAAW,GAAAd,aAAA,GAAEG,MAAM,CAAC0B,IAAI,qBAAX7B,aAAA,CAAaiC,EAAE,EAAE3B,CAAC,CAAC,CAAC;AACpD,CAAC;AAACgC,OAAA,CAAAzC,0BAAA,GAAAA,0BAAA","ignoreList":[]}
|
package/lib/module/version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslatedMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTranslatedMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAMvF,eAAO,MAAM,oBAAoB,GAAI,UAAU,YAAY,GAAG,eAAe;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useTranslatedMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTranslatedMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAMvF,eAAO,MAAM,oBAAoB,GAAI,UAAU,YAAY,GAAG,eAAe;;;;;;;;;;;;;;;;;;;;;;;YAkB+gpB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAD5lpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "9.10.2-beta.
|
|
4
|
+
"version": "9.10.2-beta.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"react-native-markdown-package": "1.8.2",
|
|
85
85
|
"react-native-url-polyfill": "^2.0.0",
|
|
86
86
|
"react-syntax-highlighter": "^16.1.0",
|
|
87
|
-
"stream-chat": "^9.54.
|
|
87
|
+
"stream-chat": "^9.54.1",
|
|
88
88
|
"use-sync-external-store": "^1.5.0",
|
|
89
89
|
"zod": "^4.1.12"
|
|
90
90
|
},
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
import { act, renderHook } from '@testing-library/react-native';
|
|
4
|
+
import { Poll, PollResponse, PollVote, StreamChat } from 'stream-chat';
|
|
5
|
+
|
|
6
|
+
import { ChatProvider } from '../../../../contexts/chatContext/ChatContext';
|
|
7
|
+
import { useChannelPreviewPollLabel } from '../useChannelPreviewPollLabel';
|
|
8
|
+
|
|
9
|
+
const OWN_USER = { id: 'own-user' };
|
|
10
|
+
const MESSAGE_ID = 'message-id';
|
|
11
|
+
const POLL_ID = 'poll-id';
|
|
12
|
+
|
|
13
|
+
const generateVote = (id: string, optionId: string, createdAt: string): PollVote => ({
|
|
14
|
+
created_at: createdAt,
|
|
15
|
+
id,
|
|
16
|
+
option_id: optionId,
|
|
17
|
+
poll_id: POLL_ID,
|
|
18
|
+
updated_at: createdAt,
|
|
19
|
+
user: OWN_USER,
|
|
20
|
+
user_id: OWN_USER.id,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const setup = (ownVotes: PollVote[]) => {
|
|
24
|
+
const client = {
|
|
25
|
+
removePollVote: jest.fn(() => new Promise(() => {})),
|
|
26
|
+
user: OWN_USER,
|
|
27
|
+
userID: OWN_USER.id,
|
|
28
|
+
} as unknown as StreamChat;
|
|
29
|
+
const latestVotesByOption: Record<string, PollVote[]> = {};
|
|
30
|
+
const voteCountsByOption: Record<string, number> = {};
|
|
31
|
+
ownVotes.forEach((vote) => {
|
|
32
|
+
latestVotesByOption[vote.option_id as string] = [vote];
|
|
33
|
+
voteCountsByOption[vote.option_id as string] = 1;
|
|
34
|
+
});
|
|
35
|
+
const poll = new Poll({
|
|
36
|
+
client,
|
|
37
|
+
poll: {
|
|
38
|
+
enforce_unique_vote: false,
|
|
39
|
+
id: POLL_ID,
|
|
40
|
+
latest_answers: [],
|
|
41
|
+
latest_votes_by_option: latestVotesByOption,
|
|
42
|
+
name: 'Poll',
|
|
43
|
+
options: [
|
|
44
|
+
{ id: 'option-a', text: 'A' },
|
|
45
|
+
{ id: 'option-b', text: 'B' },
|
|
46
|
+
],
|
|
47
|
+
own_votes: ownVotes,
|
|
48
|
+
vote_count: ownVotes.length,
|
|
49
|
+
vote_counts_by_option: voteCountsByOption,
|
|
50
|
+
} as unknown as PollResponse,
|
|
51
|
+
});
|
|
52
|
+
(client as unknown as { polls: unknown }).polls = { fromState: () => poll };
|
|
53
|
+
|
|
54
|
+
const wrapper = ({ children }: PropsWithChildren) => (
|
|
55
|
+
<ChatProvider value={{ client } as never}>{children}</ChatProvider>
|
|
56
|
+
);
|
|
57
|
+
const hook = renderHook(() => useChannelPreviewPollLabel({ pollId: POLL_ID }), { wrapper });
|
|
58
|
+
return { ...hook, poll };
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
describe('useChannelPreviewPollLabel', () => {
|
|
62
|
+
it('returns no label once the only vote is removed', () => {
|
|
63
|
+
const vote = generateVote('vote-a', 'option-a', '2026-10-27T10:00:00.000Z');
|
|
64
|
+
const { poll, result } = setup([vote]);
|
|
65
|
+
expect(result.current).toBe('You voted: {{ option }}');
|
|
66
|
+
|
|
67
|
+
act(() => {
|
|
68
|
+
poll.removeVote(vote.id, MESSAGE_ID);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result.current).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('labels the remaining latest vote once another option loses its only vote', () => {
|
|
75
|
+
const voteA = generateVote('vote-a', 'option-a', '2026-10-27T10:00:00.000Z');
|
|
76
|
+
const voteB = generateVote('vote-b', 'option-b', '2026-10-27T09:00:00.000Z');
|
|
77
|
+
const { poll, result } = setup([voteA, voteB]);
|
|
78
|
+
|
|
79
|
+
act(() => {
|
|
80
|
+
poll.removeVote(voteA.id, MESSAGE_ID);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(poll.data.latest_votes_by_option['option-a']).toEqual([]);
|
|
84
|
+
expect(result.current).toBe('You voted: {{ option }}');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -31,7 +31,7 @@ export const useChannelPreviewPollLabel = ({ pollId }: UseChannelPreviewPollLabe
|
|
|
31
31
|
() =>
|
|
32
32
|
latestVotesByOption
|
|
33
33
|
? Object.values(latestVotesByOption)
|
|
34
|
-
.
|
|
34
|
+
.flatMap((votes) => votes?.[0] ?? [])
|
|
35
35
|
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
|
|
36
36
|
: [],
|
|
37
37
|
[latestVotesByOption],
|
package/src/version.json
CHANGED