Skip to content

Commit 40cc5d5

Browse files
authored
feat(web): navigate to pinned message (#1561)
1 parent b55f801 commit 40cc5d5

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

frontend/src/components/feature/pinned-messages/PinnedMessageModalContent.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Dialog, Flex, IconButton, Text } from '@radix-ui/themes'
1+
import { Dialog, Flex, IconButton, Text, VisuallyHidden } from '@radix-ui/themes'
22
import { useFrappeGetCall } from 'frappe-react-sdk'
3-
import { useParams } from 'react-router-dom'
3+
import { useNavigate, useParams } from 'react-router-dom'
44
import { Message } from '../../../../../types/Messaging/Message'
55
import { ErrorBanner } from '@/components/layout/AlertBanner/ErrorBanner'
66
import { MessageBox } from '../GlobalSearch/MessageBox'
@@ -14,6 +14,29 @@ export const PinnedMessageModalContent = ({ onClose }: { onClose: () => void })
1414
revalidateOnFocus: false
1515
})
1616

17+
const navigate = useNavigate()
18+
19+
const { workspaceID } = useParams()
20+
21+
const handleNavigateToChannel = (channelID: string, workspace?: string, baseMessage?: string) => {
22+
let baseRoute = ''
23+
if (workspace) {
24+
baseRoute = `/${workspace}`
25+
} else {
26+
baseRoute = `/${workspaceID}`
27+
}
28+
29+
navigate({
30+
pathname: `${baseRoute}/${channelID}`,
31+
search: `message_id=${baseMessage}`
32+
})
33+
}
34+
35+
const handleScrollToMessage = (messageName: string, channelID: string, workspace?: string) => {
36+
handleNavigateToChannel(channelID, workspace, messageName)
37+
onClose()
38+
}
39+
1740
return (
1841
<>
1942
<Dialog.Title>
@@ -24,11 +47,16 @@ export const PinnedMessageModalContent = ({ onClose }: { onClose: () => void })
2447
</IconButton>
2548
</Flex>
2649
</Dialog.Title>
50+
<VisuallyHidden>
51+
<Dialog.Description>
52+
Pinned Messages
53+
</Dialog.Description>
54+
</VisuallyHidden>
2755
<ErrorBanner error={error} />
2856
<Flex direction='column' gap='3' justify='start'>
2957
{data?.message?.map((message) => {
3058
return (
31-
<MessageBox key={message.name} message={message} />
59+
<MessageBox key={message.name} message={message} handleScrollToMessage={handleScrollToMessage} />
3260
)
3361
})}
3462
</Flex>

0 commit comments

Comments
 (0)