mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Optimize task history list and add search bar
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
|
import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
|
||||||
import { useExtensionState } from "../context/ExtensionStateContext"
|
import { useExtensionState } from "../context/ExtensionStateContext"
|
||||||
import { vscode } from "../utils/vscode"
|
import { vscode } from "../utils/vscode"
|
||||||
|
import { Virtuoso } from "react-virtuoso"
|
||||||
|
import { useMemo, useState } from "react"
|
||||||
|
|
||||||
type HistoryViewProps = {
|
type HistoryViewProps = {
|
||||||
onDone: () => void
|
onDone: () => void
|
||||||
@@ -8,6 +10,8 @@ type HistoryViewProps = {
|
|||||||
|
|
||||||
const HistoryView = ({ onDone }: HistoryViewProps) => {
|
const HistoryView = ({ onDone }: HistoryViewProps) => {
|
||||||
const { taskHistory } = useExtensionState()
|
const { taskHistory } = useExtensionState()
|
||||||
|
const [searchQuery, setSearchQuery] = useState("")
|
||||||
|
|
||||||
const handleHistorySelect = (id: string) => {
|
const handleHistorySelect = (id: string) => {
|
||||||
vscode.postMessage({ type: "showTaskWithId", text: id })
|
vscode.postMessage({ type: "showTaskWithId", text: id })
|
||||||
}
|
}
|
||||||
@@ -35,6 +39,30 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
.toUpperCase()
|
.toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const presentableTasks = useMemo(() => {
|
||||||
|
return taskHistory.filter((item) => item.ts && item.task)
|
||||||
|
}, [taskHistory])
|
||||||
|
|
||||||
|
const taskHistorySearchResults = useMemo(() => {
|
||||||
|
return presentableTasks.filter((item) => item.task.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||||
|
}, [presentableTasks, searchQuery])
|
||||||
|
|
||||||
|
const highlightText = (text: string, query: string) => {
|
||||||
|
if (!query) return text
|
||||||
|
const parts = text.split(new RegExp(`(${query})`, "gi"))
|
||||||
|
return parts.map((part, index) =>
|
||||||
|
part.toLowerCase() === query.toLowerCase() ? (
|
||||||
|
<mark
|
||||||
|
key={index}
|
||||||
|
style={{ backgroundColor: "var(--vscode-editor-findMatchHighlightBackground)", color: "inherit" }}>
|
||||||
|
{part}
|
||||||
|
</mark>
|
||||||
|
) : (
|
||||||
|
part
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<style>
|
<style>
|
||||||
@@ -73,8 +101,29 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
<h3 style={{ color: "var(--vscode-foreground)", margin: 0 }}>History</h3>
|
<h3 style={{ color: "var(--vscode-foreground)", margin: 0 }}>History</h3>
|
||||||
<VSCodeButton onClick={onDone}>Done</VSCodeButton>
|
<VSCodeButton onClick={onDone}>Done</VSCodeButton>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ padding: "5px 17px" }}>
|
||||||
|
<VSCodeTextField
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
placeholder="Search history..."
|
||||||
|
value={searchQuery}
|
||||||
|
onInput={(e) => setSearchQuery((e.target as HTMLInputElement)?.value)}>
|
||||||
|
<div
|
||||||
|
slot="start"
|
||||||
|
className="codicon codicon-search"
|
||||||
|
style={{ fontSize: 13, marginTop: 2.5, opacity: 0.8 }}></div>
|
||||||
|
{searchQuery && (
|
||||||
|
<VSCodeButton
|
||||||
|
appearance="icon"
|
||||||
|
aria-label="Clear search"
|
||||||
|
onClick={() => setSearchQuery("")}
|
||||||
|
slot="end">
|
||||||
|
<span className="codicon codicon-close"></span>
|
||||||
|
</VSCodeButton>
|
||||||
|
)}
|
||||||
|
</VSCodeTextField>
|
||||||
|
</div>
|
||||||
<div style={{ flexGrow: 1, overflowY: "auto", margin: 0 }}>
|
<div style={{ flexGrow: 1, overflowY: "auto", margin: 0 }}>
|
||||||
{taskHistory.length === 0 && (
|
{presentableTasks.length === 0 && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -97,10 +146,14 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
<Virtuoso
|
||||||
{taskHistory
|
style={{
|
||||||
.filter((item) => item.ts && item.task)
|
flexGrow: 1,
|
||||||
.map((item, index) => (
|
overflowY: "scroll",
|
||||||
|
scrollbarWidth: "none",
|
||||||
|
}}
|
||||||
|
data={taskHistorySearchResults}
|
||||||
|
itemContent={(index, item) => (
|
||||||
<div
|
<div
|
||||||
key={item.id}
|
key={item.id}
|
||||||
className="history-item"
|
className="history-item"
|
||||||
@@ -157,7 +210,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
wordBreak: "break-word",
|
wordBreak: "break-word",
|
||||||
overflowWrap: "anywhere",
|
overflowWrap: "anywhere",
|
||||||
}}>
|
}}>
|
||||||
{item.task}
|
{highlightText(item.task, searchQuery)}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
|
||||||
<div
|
<div
|
||||||
@@ -293,7 +346,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user