Skip to content

Commit 0907f29

Browse files
committed
fix: solve final cyclical dep
1 parent 1fd1b69 commit 0907f29

File tree

3 files changed

+72
-58
lines changed

3 files changed

+72
-58
lines changed

package/src/components/Poll/components/PollResults/PollOptionFullResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FlatList, type FlatListProps, StyleSheet, Text, View } from 'react-nati
33

44
import { PollOption, PollVote as PollVoteClass } from 'stream-chat';
55

6-
import { PollVote } from './PollResultItem';
6+
import { PollVote } from './PollVote';
77

88
import {
99
PollContextProvider,

package/src/components/Poll/components/PollResults/PollResultItem.tsx

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useCallback, useMemo, useState } from 'react';
1+
import React, { useCallback, useState } from 'react';
22
import { Modal, SafeAreaView, StyleSheet, Text, View } from 'react-native';
33

4-
import { Poll, PollOption, PollVote as PollVoteClass, VotingVisibility } from 'stream-chat';
4+
import { Poll, PollOption, PollVote as PollVoteClass } from 'stream-chat';
55

66
import { PollOptionFullResults } from './PollOptionFullResults';
7+
import { PollVote } from './PollVote';
78

89
import {
910
useOwnCapabilitiesContext,
@@ -12,8 +13,6 @@ import {
1213
useTranslationContext,
1314
} from '../../../../contexts';
1415
import type { DefaultStreamChatGenerics } from '../../../../types/types';
15-
import { getDateString } from '../../../../utils/i18n/getDateString';
16-
import { Avatar } from '../../../Avatar/Avatar';
1716
import { MessageType } from '../../../MessageList/hooks/useMessageList';
1817
import { usePollState } from '../../hooks/usePollState';
1918
import { GenericPollButton } from '../Button';
@@ -86,51 +85,6 @@ export type PollResultItemProps<
8685
option: PollOption<StreamChatGenerics>;
8786
};
8887

89-
export const PollVote = ({ vote }: { vote: PollVoteClass }) => {
90-
const { t, tDateTimeParser } = useTranslationContext();
91-
const { votingVisibility } = usePollState();
92-
const {
93-
theme: {
94-
colors: { black, text_low_emphasis },
95-
poll: {
96-
results: {
97-
vote: { container, dateText, userName },
98-
},
99-
},
100-
},
101-
} = useTheme();
102-
103-
const dateString = useMemo(
104-
() =>
105-
getDateString({
106-
date: vote.created_at,
107-
t,
108-
tDateTimeParser,
109-
timestampTranslationKey: 'timestamp/PollVote',
110-
}),
111-
[vote.created_at, t, tDateTimeParser],
112-
);
113-
114-
const isAnonymous = useMemo(
115-
() => votingVisibility === VotingVisibility.anonymous,
116-
[votingVisibility],
117-
);
118-
119-
return (
120-
<View style={[styles.voteContainer, container]}>
121-
<View style={{ flexDirection: 'row' }}>
122-
{!isAnonymous && vote.user?.image ? (
123-
<Avatar image={vote.user.image as string} key={vote.id} size={20} />
124-
) : null}
125-
<Text style={[styles.voteUserName, { color: black }, userName]}>
126-
{isAnonymous ? t<string>('Anonymous') : vote.user?.name}
127-
</Text>
128-
</View>
129-
<Text style={[styles.voteDate, { color: text_low_emphasis }, dateText]}>{dateString}</Text>
130-
</View>
131-
);
132-
};
133-
13488
const PollResultsVoteItem = (vote: PollVoteClass) => (
13589
<PollVote key={`results_vote_${vote.id}`} vote={vote} />
13690
);
@@ -177,13 +131,5 @@ const styles = StyleSheet.create({
177131
},
178132
headerContainer: { flexDirection: 'row', justifyContent: 'space-between' },
179133
title: { flex: 1, fontSize: 16, fontWeight: '500' },
180-
voteContainer: {
181-
flexDirection: 'row',
182-
justifyContent: 'space-between',
183-
marginBottom: 8,
184-
paddingVertical: 8,
185-
},
186134
voteCount: { fontSize: 16, marginLeft: 16 },
187-
voteDate: { fontSize: 14 },
188-
voteUserName: { fontSize: 14, marginLeft: 2 },
189135
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { useMemo } from 'react';
2+
3+
import { StyleSheet, Text, View } from 'react-native';
4+
5+
import { PollVote as PollVoteClass, VotingVisibility } from 'stream-chat';
6+
7+
import { useTheme, useTranslationContext } from '../../../../contexts';
8+
import { getDateString } from '../../../../utils/i18n/getDateString';
9+
10+
import { Avatar } from '../../../Avatar/Avatar';
11+
import { usePollState } from '../../hooks/usePollState';
12+
13+
export const PollVote = ({ vote }: { vote: PollVoteClass }) => {
14+
const { t, tDateTimeParser } = useTranslationContext();
15+
const { votingVisibility } = usePollState();
16+
const {
17+
theme: {
18+
colors: { black, text_low_emphasis },
19+
poll: {
20+
results: {
21+
vote: { container, dateText, userName },
22+
},
23+
},
24+
},
25+
} = useTheme();
26+
27+
const dateString = useMemo(
28+
() =>
29+
getDateString({
30+
date: vote.created_at,
31+
t,
32+
tDateTimeParser,
33+
timestampTranslationKey: 'timestamp/PollVote',
34+
}),
35+
[vote.created_at, t, tDateTimeParser],
36+
);
37+
38+
const isAnonymous = useMemo(
39+
() => votingVisibility === VotingVisibility.anonymous,
40+
[votingVisibility],
41+
);
42+
43+
return (
44+
<View style={[styles.voteContainer, container]}>
45+
<View style={{ flexDirection: 'row' }}>
46+
{!isAnonymous && vote.user?.image ? (
47+
<Avatar image={vote.user.image as string} key={vote.id} size={20} />
48+
) : null}
49+
<Text style={[styles.voteUserName, { color: black }, userName]}>
50+
{isAnonymous ? t<string>('Anonymous') : vote.user?.name}
51+
</Text>
52+
</View>
53+
<Text style={[styles.voteDate, { color: text_low_emphasis }, dateText]}>{dateString}</Text>
54+
</View>
55+
);
56+
};
57+
58+
const styles = StyleSheet.create({
59+
voteContainer: {
60+
flexDirection: 'row',
61+
justifyContent: 'space-between',
62+
marginBottom: 8,
63+
paddingVertical: 8,
64+
},
65+
voteCount: { fontSize: 16, marginLeft: 16 },
66+
voteDate: { fontSize: 14 },
67+
voteUserName: { fontSize: 14, marginLeft: 2 },
68+
});

0 commit comments

Comments
 (0)