diff --git a/gui/src/components/History/HistoryTableRow.tsx b/gui/src/components/History/HistoryTableRow.tsx index 7a0d494c9..65c99233c 100644 --- a/gui/src/components/History/HistoryTableRow.tsx +++ b/gui/src/components/History/HistoryTableRow.tsx @@ -65,7 +65,7 @@ export function HistoryTableRow({ onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)} data-testid={`history-row-${index}`} - className="hover:bg-list-hover relative box-border flex w-full cursor-pointer overflow-hidden rounded-lg p-3" + className="border-border relative mb-2 box-border flex w-full cursor-pointer overflow-hidden rounded-lg border border-solid p-3" onClick={async () => { await dispatch(exitEdit({})); if (sessionMetadata.sessionId !== currentSessionId) { @@ -117,7 +117,7 @@ export function HistoryTableRow({ {hovered && !editing && ( -
+
{ diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index b02f7eb5c..b4ce86866 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -21,20 +21,12 @@ import { import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { refreshSessionMetadata } from "../../redux/thunks/session"; import { getFontSize, getPlatform } from "../../util"; +import { cn } from "../../util/cn"; import { ROUTES } from "../../util/navigation"; import ConfirmationDialog from "../dialogs/ConfirmationDialog"; +import { Button } from "../ui"; import { HistoryTableRow } from "./HistoryTableRow"; - -const parseDate = (date: string): Date => { - let dateObj = new Date(date); - if (isNaN(dateObj.getTime())) { - dateObj = new Date(parseInt(date)); - } - return dateObj; -}; - -const HEADER_CLASS = - "flex user-select-none mt-1 opacity-75 text-center font-bold items-center justify-center sticky h-6"; +import { groupSessionsByDate, parseDate } from "./util"; export function History() { const dispatch = useAppDispatch(); @@ -124,10 +116,9 @@ export function History() { ); }, [allSessionMetadata, searchTerm, minisearch]); - const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); - const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7); - const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30); - const earlier = new Date(0); + const sessionGroups = useMemo(() => { + return groupSessionsByDate(filteredAndSortedSessions); + }, [filteredAndSortedSessions]); const showClearSessionsDialog = () => { dispatch( @@ -158,7 +149,7 @@ export function History() { style={{ fontSize: getFontSize() }} className="flex flex-1 flex-col overflow-auto px-1" > -
+
- {filteredAndSortedSessions.map((session, index) => { - const prevDate = - index > 0 - ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) - : earlier; - const date = parseDate(session.dateCreated); - return ( - - {index === 0 && date > yesterday && ( - - Today - + {sessionGroups.map((group, groupIndex) => ( + + lastWeek && - prevDate > yesterday && ( -
- This Week -
- )} - {date < lastWeek && - date > lastMonth && - prevDate > lastWeek && ( -
- This Month -
- )} - {date < lastMonth && prevDate > lastMonth && ( -
- Older -
- )} - - -
- ); - })} + > + {group.label} + + {group.sessions.map((session, sessionIndex) => ( + + ))} +
+ ))}
-
- - Data is saved in{" "} +
+ + + Chat history is saved to{" "} {platform === "windows" ? "%USERPROFILE%/.continue" : "~/.continue/sessions"} - - (Clear session history) -
); diff --git a/gui/src/components/History/util.ts b/gui/src/components/History/util.ts new file mode 100644 index 000000000..c26892033 --- /dev/null +++ b/gui/src/components/History/util.ts @@ -0,0 +1,48 @@ +import { SessionMetadata } from "core"; + +export const parseDate = (date: string): Date => { + let dateObj = new Date(date); + if (isNaN(dateObj.getTime())) { + dateObj = new Date(parseInt(date)); + } + return dateObj; +}; + +export interface SessionGroup { + label: string; + sessions: SessionMetadata[]; +} + +export const groupSessionsByDate = (sessions: SessionMetadata[]): SessionGroup[] => { + const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); + const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7); + const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30); + + const groups: SessionGroup[] = []; + + const todaySessions = sessions.filter( + (session) => parseDate(session.dateCreated) > yesterday, + ); + const weekSessions = sessions.filter((session) => { + const date = parseDate(session.dateCreated); + return date <= yesterday && date > lastWeek; + }); + const monthSessions = sessions.filter((session) => { + const date = parseDate(session.dateCreated); + return date <= lastWeek && date > lastMonth; + }); + const olderSessions = sessions.filter( + (session) => parseDate(session.dateCreated) <= lastMonth, + ); + + if (todaySessions.length > 0) + groups.push({ label: "Today", sessions: todaySessions }); + if (weekSessions.length > 0) + groups.push({ label: "This Week", sessions: weekSessions }); + if (monthSessions.length > 0) + groups.push({ label: "This Month", sessions: monthSessions }); + if (olderSessions.length > 0) + groups.push({ label: "Older", sessions: olderSessions }); + + return groups; +}; \ No newline at end of file