Skip to content

Commit f357e70

Browse files
authored
fix(app): register archive session command in both layouts (anomalyco#41741)
1 parent a9cac91 commit f357e70

4 files changed

Lines changed: 88 additions & 65 deletions

File tree

‎packages/app/src/pages/layout.tsx‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -972,17 +972,6 @@ export default function LegacyLayout(props: ParentProps) {
972972
keybind: "shift+alt+arrowdown",
973973
onSelect: () => navigateSessionByUnseen(1),
974974
},
975-
{
976-
id: "session.archive",
977-
title: language.t("command.session.archive"),
978-
category: language.t("command.category.session"),
979-
keybind: "mod+shift+backspace",
980-
disabled: !params.dir || !params.id,
981-
onSelect: () => {
982-
const session = currentSessions().find((s) => s.id === params.id)
983-
if (session) void archiveSession(session)
984-
},
985-
},
986975
{
987976
id: "workspace.new",
988977
title: language.t("workspace.new"),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { useNavigate } from "@solidjs/router"
2+
import { produce } from "solid-js/store"
3+
import { notifySessionTabsRemoved } from "@/components/titlebar-session-events"
4+
import { useLanguage } from "@/context/language"
5+
import { useSDK } from "@/context/sdk"
6+
import { useSync } from "@/context/sync"
7+
import { useTabs } from "@/context/tabs"
8+
import { errorMessage } from "@/pages/layout/helpers"
9+
import { useSessionKey } from "@/pages/session/session-layout"
10+
import { legacySessionHref, requireServerKey, sessionHref } from "@/utils/session-route"
11+
import { showToast } from "@/utils/toast"
12+
13+
export function useSessionArchive() {
14+
const language = useLanguage()
15+
const navigate = useNavigate()
16+
const sdk = useSDK()
17+
const sync = useSync()
18+
const tabs = useTabs()
19+
const { params } = useSessionKey()
20+
21+
const navigateAfterRemoval = (sessionID: string, parentID?: string, nextSessionID?: string) => {
22+
if (params.id !== sessionID) return
23+
const href = (id: string) =>
24+
params.serverKey ? sessionHref(requireServerKey(params.serverKey), id) : legacySessionHref(sdk().directory, id)
25+
if (parentID) {
26+
navigate(href(parentID))
27+
return
28+
}
29+
if (nextSessionID) {
30+
navigate(href(nextSessionID))
31+
return
32+
}
33+
if (params.serverKey) {
34+
tabs.newDraft({ server: requireServerKey(params.serverKey), directory: sdk().directory })
35+
return
36+
}
37+
navigate(`/${params.dir}/session`)
38+
}
39+
40+
const archive = async (sessionID: string) => {
41+
const session = sync().session.get(sessionID)
42+
if (!session) return
43+
if ((await sdk().protocol) !== "v1") return
44+
45+
const sessions = sync().data.session ?? []
46+
const index = sessions.findIndex((s) => s.id === sessionID)
47+
const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1])
48+
49+
await sdk()
50+
.client.session.update({ sessionID, directory: sdk().directory, time: { archived: Date.now() } })
51+
.then(() => {
52+
sync().set(
53+
produce((draft) => {
54+
const index = draft.session.findIndex((s) => s.id === sessionID)
55+
if (index !== -1) draft.session.splice(index, 1)
56+
}),
57+
)
58+
sync().session.evict(sessionID)
59+
navigateAfterRemoval(sessionID, session.parentID, nextSession?.id)
60+
notifySessionTabsRemoved({ directory: sdk().directory, sessionIDs: [sessionID] })
61+
})
62+
.catch((err) => {
63+
showToast({
64+
title: language.t("common.requestFailed"),
65+
description: errorMessage(err, language.t("common.requestFailed")),
66+
})
67+
})
68+
}
69+
70+
return { archive, navigateAfterRemoval }
71+
}

‎packages/app/src/pages/session/timeline/message-timeline.tsx‎

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ import { SessionContextUsage } from "@/components/session-context-usage"
6363
import { useDialog } from "@opencode-ai/ui/context/dialog"
6464
import { useLanguage } from "@/context/language"
6565
import { useSessionKey } from "@/pages/session/session-layout"
66+
import { useSessionArchive } from "@/pages/session/session-archive"
6667
import { useServerSDK } from "@/context/server-sdk"
6768
import { usePlatform } from "@/context/platform"
6869
import { useSettings } from "@/context/settings"
69-
import { useTabs } from "@/context/tabs"
7070
import { legacySessionHref, requireServerKey, sessionHref } from "@/utils/session-route"
7171
import { useSDK } from "@/context/sdk"
7272
import { useSync } from "@/context/sync"
@@ -263,8 +263,8 @@ export function MessageTimeline(props: {
263263
const sdk = useSDK()
264264
const sync = useSync()
265265
const settings = useSettings()
266-
const tabs = useTabs()
267266
const dialog = useDialog()
267+
const sessionArchive = useSessionArchive()
268268
const language = useLanguage()
269269
const { params, sessionKey } = useSessionKey()
270270
const ownerSessionKey = sessionKey()
@@ -790,25 +790,6 @@ export function MessageTimeline(props: {
790790
titleMutation.mutate({ id, title: next })
791791
}
792792

793-
const navigateAfterSessionRemoval = (sessionID: string, parentID?: string, nextSessionID?: string) => {
794-
if (params.id !== sessionID) return
795-
const href = (id: string) =>
796-
params.serverKey ? sessionHref(requireServerKey(params.serverKey), id) : legacySessionHref(sdk().directory, id)
797-
if (parentID) {
798-
navigate(href(parentID))
799-
return
800-
}
801-
if (nextSessionID) {
802-
navigate(href(nextSessionID))
803-
return
804-
}
805-
if (params.serverKey) {
806-
tabs.newDraft({ server: requireServerKey(params.serverKey), directory: sdk().directory })
807-
return
808-
}
809-
navigate(`/${params.dir}/session`)
810-
}
811-
812793
const exportSession = async (sessionID: string) => {
813794
try {
814795
const data = await fetchSessionExport({
@@ -832,36 +813,6 @@ export function MessageTimeline(props: {
832813
}
833814
}
834815

835-
const archiveSession = async (sessionID: string) => {
836-
const session = sync().session.get(sessionID)
837-
if (!session) return
838-
if ((await sdk().protocol) !== "v1") return
839-
840-
const sessions = sync().data.session ?? []
841-
const index = sessions.findIndex((s) => s.id === sessionID)
842-
const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1])
843-
844-
await sdk()
845-
.client.session.update({ sessionID, directory: sdk().directory, time: { archived: Date.now() } })
846-
.then(() => {
847-
sync().set(
848-
produce((draft) => {
849-
const index = draft.session.findIndex((s) => s.id === sessionID)
850-
if (index !== -1) draft.session.splice(index, 1)
851-
}),
852-
)
853-
sync().session.evict(sessionID)
854-
navigateAfterSessionRemoval(sessionID, session.parentID, nextSession?.id)
855-
notifySessionTabsRemoved({ directory: sdk().directory, sessionIDs: [sessionID] })
856-
})
857-
.catch((err) => {
858-
showToast({
859-
title: language.t("common.requestFailed"),
860-
description: errorMessage(err),
861-
})
862-
})
863-
}
864-
865816
const deleteSession = async (sessionID: string) => {
866817
const session = sync().session.get(sessionID)
867818
if (!session) return false
@@ -911,7 +862,7 @@ export function MessageTimeline(props: {
911862
}
912863
}
913864

914-
navigateAfterSessionRemoval(sessionID, session.parentID, nextSession?.id)
865+
sessionArchive.navigateAfterRemoval(sessionID, session.parentID, nextSession?.id)
915866

916867
sync().set(
917868
produce((draft) => {
@@ -1593,7 +1544,7 @@ export function MessageTimeline(props: {
15931544
<DropdownMenu.Item onSelect={() => exportSession(id)}>
15941545
<DropdownMenu.ItemLabel>{language.t("common.export")}</DropdownMenu.ItemLabel>
15951546
</DropdownMenu.Item>
1596-
<DropdownMenu.Item onSelect={() => void archiveSession(id)}>
1547+
<DropdownMenu.Item onSelect={() => void sessionArchive.archive(id)}>
15971548
<DropdownMenu.ItemLabel>{language.t("common.archive")}</DropdownMenu.ItemLabel>
15981549
</DropdownMenu.Item>
15991550
<DropdownMenu.Separator />
@@ -1667,7 +1618,7 @@ export function MessageTimeline(props: {
16671618
<MenuV2.Item onSelect={() => exportSession(id)}>
16681619
{language.t("common.export")}...
16691620
</MenuV2.Item>
1670-
<MenuV2.Item onSelect={() => void archiveSession(id)}>
1621+
<MenuV2.Item onSelect={() => void sessionArchive.archive(id)}>
16711622
{language.t("common.archive")}
16721623
</MenuV2.Item>
16731624
<MenuV2.Separator />

‎packages/app/src/pages/session/use-session-commands.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { createSessionTabs } from "@/pages/session/helpers"
1818
import { extractPromptFromParts } from "@/utils/prompt"
1919
import { Message, Part, UserMessage } from "@opencode-ai/sdk/v2"
2020
import { useSessionLayout } from "@/pages/session/session-layout"
21+
import { useSessionArchive } from "@/pages/session/session-archive"
2122
import { createSessionOwnership } from "./session-ownership"
2223
import { useLocal } from "@/context/local"
2324

@@ -52,6 +53,7 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
5253
const navigate = useNavigate()
5354
const { params, sessionKey, tabs, view } = useSessionLayout()
5455
const sessionOwnership = createSessionOwnership(sessionKey)
56+
const sessionArchive = useSessionArchive()
5557
const openDialog = async <T,>(load: () => Promise<T>, show: (value: T) => void) => {
5658
const owner = sessionOwnership.capture()
5759
const value = await load()
@@ -497,6 +499,16 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
497499
disabled: !params.id,
498500
onSelect: exportSession,
499501
}),
502+
sessionCommand({
503+
id: "session.archive",
504+
title: language.t("command.session.archive"),
505+
keybind: "mod+shift+backspace",
506+
disabled: !params.id,
507+
onSelect: () => {
508+
const id = params.id
509+
if (id) void sessionArchive.archive(id)
510+
},
511+
}),
500512
]
501513

502514
const fileCmds = () => {

0 commit comments

Comments
 (0)