+
- {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