1- import React , { useRef } from 'react' ;
1+ import React , { useEffect , useRef , useCallback , useState } from 'react' ;
22import { Box , useComponentOverrides } from '@embeddedchat/ui-elements' ;
33import styles from './ChatLayout.styles' ;
44import {
@@ -36,9 +36,15 @@ import useUiKitStore from '../../store/uiKitStore';
3636const ChatLayout = ( ) => {
3737 const messageListRef = useRef ( null ) ;
3838 const { classNames, styleOverrides } = useComponentOverrides ( 'ChatBody' ) ;
39- const { ECOptions } = useRCContext ( ) ;
39+ const { RCInstance , ECOptions } = useRCContext ( ) ;
4040 const anonymousMode = ECOptions ?. anonymousMode ;
4141 const showRoles = ECOptions ?. anonymousMode ;
42+ const setStarredMessages = useStarredMessageStore (
43+ ( state ) => state . setStarredMessages
44+ ) ;
45+ const starredMessages = useStarredMessageStore (
46+ ( state ) => state . starredMessages
47+ ) ;
4248 const showSidebar = useSidebarStore ( ( state ) => state . showSidebar ) ;
4349 const showMentions = useMentionsStore ( ( state ) => state . showMentions ) ;
4450 const showAllFiles = useFileStore ( ( state ) => state . showAllFiles ) ;
@@ -57,6 +63,9 @@ const ChatLayout = () => {
5763 const attachmentWindowOpen = useAttachmentWindowStore (
5864 ( state ) => state . attachmentWindowOpen
5965 ) ;
66+ const isUserAuthenticated = useUserStore (
67+ ( state ) => state . isUserAuthenticated
68+ ) ;
6069 const { data, handleDrag, handleDragDrop } = useDropBox ( ) ;
6170 const { uiKitContextualBarOpen, uiKitContextualBarData } = useUiKitStore (
6271 ( state ) => ( {
@@ -72,7 +81,22 @@ const ChatLayout = () => {
7281 } ) ;
7382 }
7483 } ;
75-
84+ const getStarredMessages = useCallback ( async ( ) => {
85+ if ( isUserAuthenticated ) {
86+ try {
87+ if ( ! isUserAuthenticated && ! anonymousMode ) {
88+ return ;
89+ }
90+ const { messages } = await RCInstance . getStarredMessages ( ) ;
91+ setStarredMessages ( messages ) ;
92+ } catch ( e ) {
93+ console . error ( e ) ;
94+ }
95+ }
96+ } , [ isUserAuthenticated , anonymousMode , RCInstance ] ) ;
97+ useEffect ( ( ) => {
98+ getStarredMessages ( ) ;
99+ } , [ showSidebar ] ) ;
76100 return (
77101 < Box
78102 css = { styles . layout }
0 commit comments