Skip to content

Commit 0b4ded6

Browse files
committed
fix: remove unnecessary selector
1 parent 3788509 commit 0b4ded6

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

package/src/components/Poll/components/PollOption.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,14 @@ import { ScrollViewProps, StyleSheet, Text, View } from 'react-native';
44

55
import { ScrollView } from 'react-native-gesture-handler';
66

7-
import { PollOption as PollOptionClass, PollState, PollVote } from 'stream-chat';
7+
import { PollOption as PollOptionClass, PollVote } from 'stream-chat';
88

99
import { VoteButton } from './Button';
1010

1111
import { PollContextProvider, PollContextValue, useTheme } from '../../../contexts';
1212

13-
import { DefaultStreamChatGenerics } from '../../../types/types';
1413
import { Avatar } from '../../Avatar/Avatar';
1514
import { usePollState } from '../hooks/usePollState';
16-
import { usePollStateStore } from '../hooks/usePollStateStore';
17-
18-
type PollOptionSelectorReturnValue = {
19-
latest_votes_by_option: Record<string, PollVote[]>;
20-
maxVotedOptionIds: string[];
21-
};
22-
23-
const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
24-
nextValue: PollState<StreamChatGenerics>,
25-
): PollOptionSelectorReturnValue => ({
26-
latest_votes_by_option: nextValue.latest_votes_by_option,
27-
maxVotedOptionIds: nextValue.maxVotedOptionIds,
28-
});
2915

3016
export type PollOptionProps = {
3117
option: PollOptionClass;
@@ -87,9 +73,8 @@ export const PollAllOptions = ({
8773
);
8874

8975
export const PollOption = ({ option, showProgressBar = true }: PollOptionProps) => {
90-
const { is_closed, vote_counts_by_option } = usePollState();
91-
92-
const { latest_votes_by_option, maxVotedOptionIds } = usePollStateStore(selector);
76+
const { is_closed, latest_votes_by_option, maxVotedOptionIds, vote_counts_by_option } =
77+
usePollState();
9378

9479
const relevantVotes = useMemo(
9580
() => latest_votes_by_option?.[option.id]?.slice(0, 2) || [],

package/src/components/Poll/hooks/usePollState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type UsePollStateSelectorReturnType = {
2727
is_closed: boolean | undefined;
2828
latest_votes_by_option: Record<string, PollVote[]>;
2929
max_votes_allowed: number;
30+
maxVotedOptionIds: string[];
3031
name: string;
3132
options: PollOption[];
3233
ownAnswer: PollAnswer | undefined;
@@ -56,6 +57,7 @@ const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
5657
is_closed: nextValue.is_closed,
5758
latest_votes_by_option: nextValue.latest_votes_by_option,
5859
max_votes_allowed: nextValue.max_votes_allowed,
60+
maxVotedOptionIds: nextValue.maxVotedOptionIds,
5961
name: nextValue.name,
6062
options: nextValue.options,
6163
ownAnswer: nextValue.ownAnswer,
@@ -75,6 +77,7 @@ export const usePollState = (): UsePollStateReturnType => {
7577
is_closed,
7678
latest_votes_by_option,
7779
max_votes_allowed,
80+
maxVotedOptionIds,
7881
name,
7982
options,
8083
ownAnswer,
@@ -108,6 +111,7 @@ export const usePollState = (): UsePollStateReturnType => {
108111
is_closed,
109112
latest_votes_by_option,
110113
max_votes_allowed,
114+
maxVotedOptionIds,
111115
name,
112116
options,
113117
ownAnswer,

0 commit comments

Comments
 (0)