Skip to content

Commit

Permalink
[Obs AI Assistant] Refactor (elastic#204087)
Browse files Browse the repository at this point in the history
  • Loading branch information
viduni94 committed Jan 30, 2025
1 parent 19437f4 commit f8f23ae
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,7 @@ export function NavControl({ isServerless }: { isServerless?: boolean }) {
const [isOpen, setIsOpen] = useState(flyoutSettings.isOpen);
const [hasBeenOpened, setHasBeenOpened] = useState(isOpen);
const keyRef = useRef(v4());

const openFlyout = useCallback(() => {
if (!isOpen) {
keyRef.current = v4();
setHasBeenOpened(true);
setFlyoutSettings((prev) => ({ ...prev, isOpen: true }));
setIsOpen(true);
}
}, [isOpen, setFlyoutSettings]);
const theme = useTheme();

const chatService = useAbortableAsync(
({ signal }) => {
Expand All @@ -115,6 +107,15 @@ export function NavControl({ isServerless }: { isServerless?: boolean }) {
[service, hasBeenOpened, notifications.toasts]
);

const openFlyout = useCallback(() => {
if (!isOpen) {
keyRef.current = v4();
setHasBeenOpened(true);
setFlyoutSettings((prev) => ({ ...prev, isOpen: true }));
setIsOpen(true);
}
}, [isOpen, setFlyoutSettings]);

useEffect(() => {
const conversationSubscription = service.conversations.predefinedConversation$.subscribe(() => {
openFlyout();
Expand All @@ -133,8 +134,6 @@ export function NavControl({ isServerless }: { isServerless?: boolean }) {
hideConversationList: false,
};

const theme = useTheme();

const buttonCss = css`
padding: 0px 8px;
Expand Down

0 comments on commit f8f23ae

Please sign in to comment.