Skip to content

Commit

Permalink
show recent ones always
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale authored and Kvadratni committed Dec 4, 2024
1 parent 78f8b79 commit c4e6d4c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ui/desktop/src/LauncherWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare global {
electron: {
getConfig(): object;
getSession(sessionId: string): object;
listSessions(dir: string): Array<object>;
listSessions(dir?: string): Array<object>;
logInfo(info: string): object;
saveSession(sessionData: { name: string; messages: Array<object>; directory: string }): object;
hideWindow: () => void;
Expand Down
68 changes: 55 additions & 13 deletions ui/desktop/src/components/SessionPIlls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,81 @@ import React, { useEffect, useState } from "react"

export default function SessionPills() {
const [sessions, setSessions] = useState([]);
const [latestSessions, setLatestSessions] = useState([]);

const dir = window.appConfig.get("GOOSE_WORKING_DIR");
const workingDir = window.appConfig.get("GOOSE_WORKING_DIR");

useEffect(() => {
async function loadSessions() {

window.electron.logInfo(`_------______________ Looking for sessions related to ${dir}`);
const sessions = await window.electron.listSessions(dir);
window.electron.logInfo(`_------______________ Looking for sessions related to ${workingDir}`);
const sessions = await window.electron.listSessions(workingDir);

window.electron.logInfo(`_------______________ Found ${sessions.length} sessions in ${dir}`);
window.electron.logInfo(`_------______________ Found ${sessions.length} sessions in ${workingDir}`);
window.electron.logInfo(`Sessions: ${JSON.stringify(sessions)}`);
setSessions(sessions);
};
loadSessions();
}, []);

if (sessions.length === 0) {
useEffect(() => {
async function loadSessions() {
const sessions = await window.electron.listSessions();
setLatestSessions(sessions);
};
loadSessions();
}, []);

if (sessions.length === 0 && latestSessions.length === 0) {
return null;
}

// Create a combined list of sessions, prioritizing latest ones and removing duplicates
const combinedSessions = [];
const seenNames = new Set();

// Add at least one latest session if available
if (latestSessions.length > 0) {
const latest = latestSessions[0];
combinedSessions.push({ ...latest, isLatest: true });
seenNames.add(latest.name);
}

// Add remaining latest sessions (up to 5 total)
for (let i = 1; i < latestSessions.length && combinedSessions.length < 5; i++) {
const session = latestSessions[i];
if (!seenNames.has(session.name)) {
combinedSessions.push({ ...session, isLatest: true });
seenNames.add(session.name);
}
}

// Fill remaining slots with regular sessions (up to 5 total)
for (const session of sessions) {
if (combinedSessions.length >= 5) break;
if (!seenNames.has(session.name)) {
combinedSessions.push({ ...session, isLatest: false });
seenNames.add(session.name);
}
}

return (
<div className="grid grid-cols-1 gap-4">

<div className="grid grid-cols-1 gap-4 mb-[8px]">
<div className="text-splash-pills-text text-center text-11">Previous gooses:</div>
{sessions.map((session) => (
{combinedSessions.map((session) => (
<div
key={session.directory + session.name}
className="w-[312px] px-16 py-4 text-14 text-center text-splash-pills-text whitespace-nowrap cursor-pointer bg-prev-goose-gradient text-prev-goose-text rounded-[14px] inline-block hover:scale-[1.02] transition-all duration-150"
onClick={async () => {
window.electron.createChatWindow(undefined, dir, session);
}}>
{session}
window.electron.createChatWindow(undefined, session.directory, session.name);
}}
title={session.directory}>

{`${session.name.slice(0, 50)}`}
{session.isLatest && !(session.directory === workingDir) && (
<span className="ml-2 text-10 opacity-70">(recent)</span>
)}
</div>
))}
))}
</div>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ app.whenReady().then(async () => {
if (dir) {
console.log("server: looking for sessions that match directory", dir);
const results = sessions
.map(session => session.name);
.map(session => ({ name: session.name, directory: session.directory }));
console.log("server: found sessions:", results);
return results;
} else {
return sessions.map(session => session.name);
return sessions.map(session => ({ name: session.name, directory: session.directory }));
}
} catch (error) {
console.error('Failed to load sessions:', error);
Expand Down

0 comments on commit c4e6d4c

Please sign in to comment.