go to laast session

This commit is contained in:
2026-01-21 00:52:19 -05:00
parent a2e10688bf
commit 0b2d5cdd81
5 changed files with 74 additions and 2 deletions
+34 -1
View File
@@ -24,6 +24,7 @@
let autoScroll = true;
let tmuxAlive = false;
let isMobile = false;
let lastSessionId: string | null = null;
// Load auto-scroll preference from localStorage and detect mobile
onMount(() => {
@@ -32,6 +33,8 @@
if (stored !== null) {
autoScroll = stored === 'true';
}
// Load last session from localStorage
lastSessionId = localStorage.getItem('spiceflow-last-session');
// Detect mobile (screen width < 640px or height < 450px)
const checkMobile = () => {
isMobile = window.innerWidth < 640 || window.innerHeight < 450;
@@ -42,11 +45,28 @@
}
});
// Track session history when navigating to a new session
let previousSessionId: string | null = null;
$: if (browser && sessionId && sessionId !== previousSessionId) {
// Save the previous session as "last session" before switching
if (previousSessionId) {
localStorage.setItem('spiceflow-last-session', previousSessionId);
lastSessionId = previousSessionId;
}
previousSessionId = sessionId;
}
// Load session when sessionId changes (handles client-side navigation)
$: if (sessionId) {
activeSession.load(sessionId);
}
function goToLastSession() {
if (lastSessionId) {
goto(`/session/${lastSessionId}`);
}
}
function handleToggleAutoScroll(event: CustomEvent<boolean>) {
autoScroll = event.detail;
if (browser) {
@@ -236,6 +256,7 @@
<SessionSettings
{autoAcceptEdits}
{autoScroll}
{lastSessionId}
provider={session.provider}
showBigMode={isTmuxSession && isMobile}
on:toggleAutoAccept={handleToggleAutoAccept}
@@ -244,6 +265,7 @@
on:refresh={handleRefresh}
on:eject={handleEject}
on:bigMode={handleBigMode}
on:goToLastSession={goToLastSession}
/>
<!-- Refresh button - desktop only -->
@@ -326,6 +348,17 @@
</svg>
Refresh
</button>
{#if lastSessionId}
<button
on:click={() => { menuOpen = false; goToLastSession(); }}
class="w-full px-3 py-2 text-left text-sm hover:bg-zinc-700 flex items-center gap-2 transition-colors"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
</svg>
Last session
</button>
{/if}
{#if !isTmuxSession}
<button
on:click={() => { menuOpen = false; messageList?.condenseAll(); }}
@@ -385,7 +418,7 @@
</div>
{:else if isTmuxSession}
<!-- Terminal view for tmux sessions -->
<TerminalView bind:this={terminalView} sessionId={sessionId || ''} {autoScroll} on:aliveChange={handleTmuxAliveChange} />
<TerminalView bind:this={terminalView} sessionId={sessionId || ''} {autoScroll} {lastSessionId} on:aliveChange={handleTmuxAliveChange} on:goToLastSession={goToLastSession} />
{:else}
<MessageList bind:this={messageList} messages={$activeSession.messages} streamingContent={$activeSession.streamingContent} isThinking={$activeSession.isThinking} provider={session?.provider} {autoScroll} />