Skip to content

Commit 239befe

Browse files
authored
Fix mobile comment preview (#13898)
1 parent ce8ca27 commit 239befe

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

packages/mobile/src/components/comments/CommentPreview.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { useCallback, useEffect } from 'react'
33
import { useComment } from '@audius/common/api'
44
import {
55
CommentSectionProvider,
6-
useCurrentCommentSection
6+
useCurrentCommentSection,
7+
usePostComment
78
} from '@audius/common/context'
89
import { commentsMessages as messages } from '@audius/common/messages'
910
import type { ID } from '@audius/common/models'
10-
import { trackPageSelectors } from '@audius/common/store'
11+
import { playerSelectors, trackPageSelectors } from '@audius/common/store'
12+
import type { CommentMention } from '@audius/sdk'
1113
import { OptionalHashId } from '@audius/sdk'
1214
import { TouchableOpacity, TouchableWithoutFeedback, View } from 'react-native'
15+
import TrackPlayer from 'react-native-track-player'
1316
import { useSelector } from 'react-redux'
1417
import { tracksActions } from '~/store/pages/track/lineup/actions'
1518

@@ -88,8 +91,11 @@ const CommentPreviewContent = (props: CommentPreviewContentProps) => {
8891
const {
8992
commentSectionLoading: isLoading,
9093
commentIds,
91-
isEntityOwner
94+
isEntityOwner,
95+
entityId
9296
} = useCurrentCommentSection()
97+
const [postComment] = usePostComment()
98+
const playerTrackId = useSelector(playerSelectors.getTrackId)
9399

94100
const handlePress = useCallback(() => {
95101
openCommentDrawer()
@@ -99,6 +105,20 @@ const CommentPreviewContent = (props: CommentPreviewContentProps) => {
99105
openCommentDrawer({ autoFocusInput: true })
100106
}, [openCommentDrawer])
101107

108+
const handleSubmitPreview = useCallback(
109+
async (message: string, mentions?: CommentMention[]) => {
110+
const { position: currentPosition } = await TrackPlayer.getProgress()
111+
const trackTimestampS =
112+
playerTrackId !== null &&
113+
currentPosition !== undefined &&
114+
playerTrackId === entityId
115+
? Math.floor(currentPosition)
116+
: undefined
117+
postComment(message, undefined, trackTimestampS, mentions)
118+
},
119+
[postComment, entityId, playerTrackId]
120+
)
121+
102122
// Loading state
103123
if (isLoading) {
104124
return (
@@ -123,8 +143,8 @@ const CommentPreviewContent = (props: CommentPreviewContentProps) => {
123143
</Text>
124144
<TouchableWithoutFeedback onPress={handleFormPress}>
125145
<View>
126-
<View pointerEvents='none'>
127-
<CommentForm isPreview />
146+
<View>
147+
<CommentForm isPreview onSubmit={handleSubmitPreview} />
128148
</View>
129149
</View>
130150
</TouchableWithoutFeedback>

0 commit comments

Comments
 (0)