1- import React , { useState , useCallback , useEffect , useRef } from "react"
1+ import React , { useState , useCallback , useEffect , useRef , useMemo } from "react"
22import { useNavigate , useLocation } from "react-router-dom"
33import { useAtom , useAtomValue , useSetAtom } from "jotai"
44import { sidebarVisibleAtom } from "../atoms/sidebarState"
@@ -277,22 +277,13 @@ const HistorySidebar = ({ onNewChat }: Props) => {
277277 openUrl ( `${ OAP_ROOT_URL } /u/dashboard` )
278278 }
279279
280- const onBlur = ( e : React . FocusEvent < HTMLDivElement > ) => {
281- const target = e . relatedTarget as HTMLElement
282- const menuItem = target ?. closest ( ".history-sidebar-side-menu-item" )
283- const menuLabel = target ?. closest ( ".history-sidebar-side-menu-trigger" )
284-
285- if ( containerRef . current &&
286- ! containerRef . current . contains ( e . relatedTarget as Node ) &&
287- ! menuItem &&
288- ! menuLabel ) {
289- // setVisible(false)
290- }
291- }
280+ const sortedHistories = useMemo ( ( ) => {
281+ return histories . sort ( ( a , b ) => a . type === "starred" ? - 1 : 1 )
282+ } , [ histories ] )
292283
293284 return (
294285 < >
295- < div className = { `history-sidebar ${ isVisible ? "visible" : "" } ` } tabIndex = { 0 } onBlur = { onBlur } ref = { containerRef } >
286+ < div className = { `history-sidebar ${ isVisible ? "visible" : "" } ` } tabIndex = { 0 } ref = { containerRef } >
296287 < Header />
297288 < div className = "history-header" >
298289 < Tooltip
@@ -310,7 +301,7 @@ const HistorySidebar = ({ onNewChat }: Props) => {
310301 </ Tooltip >
311302 </ div >
312303 < div className = "history-list" >
313- { histories . sort ( ( a , b ) => a . type === "starred" ? - 1 : 1 ) . map ( ( chat : ChatHistory ) => (
304+ { sortedHistories . map ( ( chat : ChatHistory ) => (
314305 < div
315306 key = { chat . id }
316307 className = { `history-item ${ chat . id === currentChatId ? "active" : "" } ` }
0 commit comments