stream-chat-react-native-core 5.40.0 → 5.41.0
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/README.md +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +10 -10
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/commonjs/components/Poll/Poll.js +8 -8
- package/lib/commonjs/components/Poll/Poll.js.map +1 -1
- package/lib/commonjs/components/Poll/components/Button.js +16 -16
- package/lib/commonjs/components/Poll/components/Button.js.map +1 -1
- package/lib/commonjs/components/Poll/components/PollAnswersList.js +3 -3
- package/lib/commonjs/components/Poll/components/PollAnswersList.js.map +1 -1
- package/lib/commonjs/components/Poll/components/PollOption.js +11 -11
- package/lib/commonjs/components/Poll/components/PollOption.js.map +1 -1
- package/lib/commonjs/components/Poll/components/PollResults/PollOptionFullResults.js +7 -5
- package/lib/commonjs/components/Poll/components/PollResults/PollOptionFullResults.js.map +1 -1
- package/lib/commonjs/components/Poll/components/PollResults/PollResultItem.js +19 -13
- package/lib/commonjs/components/Poll/components/PollResults/PollResultItem.js.map +1 -1
- package/lib/commonjs/components/Poll/components/PollResults/PollResults.js +4 -4
- package/lib/commonjs/components/Poll/components/PollResults/PollResults.js.map +1 -1
- package/lib/commonjs/components/Poll/hooks/usePollState.js +30 -30
- package/lib/commonjs/components/Poll/hooks/usePollState.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +10 -10
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/module/components/Poll/Poll.js +8 -8
- package/lib/module/components/Poll/Poll.js.map +1 -1
- package/lib/module/components/Poll/components/Button.js +16 -16
- package/lib/module/components/Poll/components/Button.js.map +1 -1
- package/lib/module/components/Poll/components/PollAnswersList.js +3 -3
- package/lib/module/components/Poll/components/PollAnswersList.js.map +1 -1
- package/lib/module/components/Poll/components/PollOption.js +11 -11
- package/lib/module/components/Poll/components/PollOption.js.map +1 -1
- package/lib/module/components/Poll/components/PollResults/PollOptionFullResults.js +7 -5
- package/lib/module/components/Poll/components/PollResults/PollOptionFullResults.js.map +1 -1
- package/lib/module/components/Poll/components/PollResults/PollResultItem.js +19 -13
- package/lib/module/components/Poll/components/PollResults/PollResultItem.js.map +1 -1
- package/lib/module/components/Poll/components/PollResults/PollResults.js +4 -4
- package/lib/module/components/Poll/components/PollResults/PollResults.js.map +1 -1
- package/lib/module/components/Poll/hooks/usePollState.js +30 -30
- package/lib/module/components/Poll/hooks/usePollState.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts +2 -2
- package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts.map +1 -1
- package/lib/typescript/components/Poll/components/PollOption.d.ts.map +1 -1
- package/lib/typescript/components/Poll/components/PollResults/PollResultItem.d.ts +3 -1
- package/lib/typescript/components/Poll/components/PollResults/PollResultItem.d.ts.map +1 -1
- package/lib/typescript/components/Poll/hooks/usePollOptionVotesPagination.d.ts +1 -1
- package/lib/typescript/components/Poll/hooks/usePollState.d.ts +10 -10
- package/lib/typescript/components/Poll/hooks/usePollState.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +10 -17
- package/src/components/Poll/Poll.tsx +5 -5
- package/src/components/Poll/components/Button.tsx +14 -14
- package/src/components/Poll/components/PollAnswersList.tsx +3 -3
- package/src/components/Poll/components/PollOption.tsx +8 -13
- package/src/components/Poll/components/PollResults/PollOptionFullResults.tsx +4 -4
- package/src/components/Poll/components/PollResults/PollResultItem.tsx +13 -9
- package/src/components/Poll/components/PollResults/PollResults.tsx +3 -3
- package/src/components/Poll/hooks/usePollOptionVotesPagination.ts +1 -1
- package/src/components/Poll/hooks/usePollState.ts +40 -40
- package/src/version.json +1 -1
|
@@ -16,9 +16,9 @@ export type PollResultItemProps<
|
|
|
16
16
|
option: PollOption<StreamChatGenerics>;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const PollVote = (vote: PollVoteClass) => {
|
|
19
|
+
export const PollVote = ({ vote }: { vote: PollVoteClass }) => {
|
|
20
20
|
const { t, tDateTimeParser } = useTranslationContext();
|
|
21
|
-
const {
|
|
21
|
+
const { votingVisibility } = usePollState();
|
|
22
22
|
const {
|
|
23
23
|
theme: {
|
|
24
24
|
colors: { black, text_low_emphasis },
|
|
@@ -42,12 +42,12 @@ export const PollVote = (vote: PollVoteClass) => {
|
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
const isAnonymous = useMemo(
|
|
45
|
-
() =>
|
|
46
|
-
[
|
|
45
|
+
() => votingVisibility === VotingVisibility.anonymous,
|
|
46
|
+
[votingVisibility],
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
|
-
<View
|
|
50
|
+
<View style={[styles.voteContainer, container]}>
|
|
51
51
|
<View style={{ flexDirection: 'row' }}>
|
|
52
52
|
{!isAnonymous && vote.user?.image ? (
|
|
53
53
|
<Avatar image={vote.user.image as string} key={vote.id} size={20} />
|
|
@@ -61,9 +61,13 @@ export const PollVote = (vote: PollVoteClass) => {
|
|
|
61
61
|
);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
const PollResultsVoteItem = (vote: PollVoteClass) => (
|
|
65
|
+
<PollVote key={`results_vote_${vote.id}`} vote={vote} />
|
|
66
|
+
);
|
|
67
|
+
|
|
64
68
|
export const PollResultsItem = ({ option }: PollResultItemProps) => {
|
|
65
69
|
const { t } = useTranslationContext();
|
|
66
|
-
const {
|
|
70
|
+
const { latestVotesByOption, voteCountsByOption } = usePollState();
|
|
67
71
|
|
|
68
72
|
const {
|
|
69
73
|
theme: {
|
|
@@ -81,12 +85,12 @@ export const PollResultsItem = ({ option }: PollResultItemProps) => {
|
|
|
81
85
|
<View style={[styles.headerContainer, headerContainer]}>
|
|
82
86
|
<Text style={[styles.title, { color: black }, title]}>{option.text}</Text>
|
|
83
87
|
<Text style={[styles.voteCount, { color: black }, voteCount]}>
|
|
84
|
-
{t<string>('{{count}} votes', { count:
|
|
88
|
+
{t<string>('{{count}} votes', { count: voteCountsByOption[option.id] ?? 0 })}
|
|
85
89
|
</Text>
|
|
86
90
|
</View>
|
|
87
|
-
{
|
|
91
|
+
{latestVotesByOption?.[option.id]?.length > 0 ? (
|
|
88
92
|
<View style={{ marginTop: 16 }}>
|
|
89
|
-
{(
|
|
93
|
+
{(latestVotesByOption?.[option.id] ?? []).slice(0, 5).map(PollResultsVoteItem)}
|
|
90
94
|
</View>
|
|
91
95
|
) : null}
|
|
92
96
|
<ShowAllVotesButton option={option} />
|
|
@@ -16,14 +16,14 @@ export type PollResultsProps = PollContextValue & {
|
|
|
16
16
|
export const PollResultsContent = ({
|
|
17
17
|
additionalScrollViewProps,
|
|
18
18
|
}: Pick<PollResultsProps, 'additionalScrollViewProps'>) => {
|
|
19
|
-
const { name, options,
|
|
19
|
+
const { name, options, voteCountsByOption } = usePollState();
|
|
20
20
|
|
|
21
21
|
const sortedOptions = useMemo(
|
|
22
22
|
() =>
|
|
23
23
|
[...options].sort(
|
|
24
|
-
(a, b) => (
|
|
24
|
+
(a, b) => (voteCountsByOption[b.id] ?? 0) - (voteCountsByOption[a.id] ?? 0),
|
|
25
25
|
),
|
|
26
|
-
[
|
|
26
|
+
[voteCountsByOption, options],
|
|
27
27
|
);
|
|
28
28
|
|
|
29
29
|
const {
|
|
@@ -22,7 +22,7 @@ export type UsePollVotesReturnType = {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* A hook that queries votes for a given Poll and returns them in a paginated fashion.
|
|
25
|
-
* Should be used instead of the
|
|
25
|
+
* Should be used instead of the latestVotesByOption property within the reactive state in the
|
|
26
26
|
* event that we need more than the top 10 votes for an option. The returned property votes will
|
|
27
27
|
* automatically be updated and trigger a state change when paginating further. Querying for votes
|
|
28
28
|
* can only be done on an option by option basis.
|
|
@@ -19,21 +19,21 @@ import { usePollContext } from '../../../contexts';
|
|
|
19
19
|
import { DefaultStreamChatGenerics } from '../../../types/types';
|
|
20
20
|
|
|
21
21
|
export type UsePollStateSelectorReturnType = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
max_votes_allowed: number;
|
|
22
|
+
allowAnswers: boolean | undefined;
|
|
23
|
+
allowUserSuggestedOptions: boolean | undefined;
|
|
24
|
+
answersCount: number;
|
|
25
|
+
createdBy: UserResponse | null;
|
|
26
|
+
enforceUniqueVote: boolean;
|
|
27
|
+
isClosed: boolean | undefined;
|
|
28
|
+
latestVotesByOption: Record<string, PollVote[]>;
|
|
30
29
|
maxVotedOptionIds: string[];
|
|
30
|
+
maxVotesAllowed: number;
|
|
31
31
|
name: string;
|
|
32
32
|
options: PollOption[];
|
|
33
33
|
ownAnswer: PollAnswer | undefined;
|
|
34
34
|
ownVotesByOptionId: Record<string, PollVote>;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
voteCountsByOption: Record<string, number>;
|
|
36
|
+
votingVisibility: VotingVisibility | undefined;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export type UsePollStateReturnType<
|
|
@@ -49,41 +49,41 @@ export type UsePollStateReturnType<
|
|
|
49
49
|
const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
|
|
50
50
|
nextValue: PollState<StreamChatGenerics>,
|
|
51
51
|
): UsePollStateSelectorReturnType => ({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
max_votes_allowed: nextValue.max_votes_allowed,
|
|
52
|
+
allowAnswers: nextValue.allow_answers,
|
|
53
|
+
allowUserSuggestedOptions: nextValue.allow_user_suggested_options,
|
|
54
|
+
answersCount: nextValue.answers_count,
|
|
55
|
+
createdBy: nextValue.created_by,
|
|
56
|
+
enforceUniqueVote: nextValue.enforce_unique_vote,
|
|
57
|
+
isClosed: nextValue.is_closed,
|
|
58
|
+
latestVotesByOption: nextValue.latest_votes_by_option,
|
|
60
59
|
maxVotedOptionIds: nextValue.maxVotedOptionIds,
|
|
60
|
+
maxVotesAllowed: nextValue.max_votes_allowed,
|
|
61
61
|
name: nextValue.name,
|
|
62
62
|
options: nextValue.options,
|
|
63
63
|
ownAnswer: nextValue.ownAnswer,
|
|
64
64
|
ownVotesByOptionId: nextValue.ownVotesByOptionId,
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
voteCountsByOption: nextValue.vote_counts_by_option,
|
|
66
|
+
votingVisibility: nextValue.voting_visibility,
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
export const usePollState = (): UsePollStateReturnType => {
|
|
70
70
|
const { message, poll } = usePollContext();
|
|
71
71
|
const {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
max_votes_allowed,
|
|
72
|
+
allowAnswers,
|
|
73
|
+
allowUserSuggestedOptions,
|
|
74
|
+
answersCount,
|
|
75
|
+
createdBy,
|
|
76
|
+
enforceUniqueVote,
|
|
77
|
+
isClosed,
|
|
78
|
+
latestVotesByOption,
|
|
80
79
|
maxVotedOptionIds,
|
|
80
|
+
maxVotesAllowed,
|
|
81
81
|
name,
|
|
82
82
|
options,
|
|
83
83
|
ownAnswer,
|
|
84
84
|
ownVotesByOptionId,
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
voteCountsByOption,
|
|
86
|
+
votingVisibility,
|
|
87
87
|
} = usePollStateStore(selector);
|
|
88
88
|
|
|
89
89
|
const addOption = useCallback(
|
|
@@ -102,21 +102,21 @@ export const usePollState = (): UsePollStateReturnType => {
|
|
|
102
102
|
return {
|
|
103
103
|
addComment,
|
|
104
104
|
addOption,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
allowAnswers,
|
|
106
|
+
allowUserSuggestedOptions,
|
|
107
|
+
answersCount,
|
|
108
|
+
createdBy,
|
|
109
109
|
endVote,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
max_votes_allowed,
|
|
110
|
+
enforceUniqueVote,
|
|
111
|
+
isClosed,
|
|
112
|
+
latestVotesByOption,
|
|
114
113
|
maxVotedOptionIds,
|
|
114
|
+
maxVotesAllowed,
|
|
115
115
|
name,
|
|
116
116
|
options,
|
|
117
117
|
ownAnswer,
|
|
118
118
|
ownVotesByOptionId,
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
voteCountsByOption,
|
|
120
|
+
votingVisibility,
|
|
121
121
|
};
|
|
122
122
|
};
|
package/src/version.json
CHANGED