Skip to content

Commit e1833e6

Browse files
committed
fix: remove redundant code
1 parent 9e2d2a6 commit e1833e6

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/components/HistorySidebar.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback, useEffect, useRef } from "react"
1+
import React, { useState, useCallback, useEffect, useRef, useMemo } from "react"
22
import { useNavigate, useLocation } from "react-router-dom"
33
import { useAtom, useAtomValue, useSetAtom } from "jotai"
44
import { 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

Comments
 (0)