Skip to content

Commit e973bbf

Browse files
authored
fix(app): default file tree to closed with minimum width (anomalyco#19426)
1 parent d36b38e commit e973bbf

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

packages/app/src/context/layout.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { createScrollPersistence, type SessionScroll } from "./layout-scroll"
1313
import { createPathHelpers } from "./file/path"
1414

1515
const AVATAR_COLOR_KEYS = ["pink", "mint", "orange", "purple", "cyan", "lime"] as const
16-
const DEFAULT_PANEL_WIDTH = 344
16+
const DEFAULT_SIDEBAR_WIDTH = 344
17+
const DEFAULT_FILE_TREE_WIDTH = 200
1718
const DEFAULT_SESSION_WIDTH = 600
1819
const DEFAULT_TERMINAL_HEIGHT = 280
1920
export type AvatarColorKey = (typeof AVATAR_COLOR_KEYS)[number]
@@ -161,11 +162,11 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
161162
if (!isRecord(fileTree)) return fileTree
162163
if (fileTree.tab === "changes" || fileTree.tab === "all") return fileTree
163164

164-
const width = typeof fileTree.width === "number" ? fileTree.width : DEFAULT_PANEL_WIDTH
165+
const width = typeof fileTree.width === "number" ? fileTree.width : DEFAULT_FILE_TREE_WIDTH
165166
return {
166167
...fileTree,
167168
opened: true,
168-
width: width === 260 ? DEFAULT_PANEL_WIDTH : width,
169+
width: width === 260 ? DEFAULT_FILE_TREE_WIDTH : width,
169170
tab: "changes",
170171
}
171172
})()
@@ -230,7 +231,7 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
230231
createStore({
231232
sidebar: {
232233
opened: false,
233-
width: DEFAULT_PANEL_WIDTH,
234+
width: DEFAULT_SIDEBAR_WIDTH,
234235
workspaces: {} as Record<string, boolean>,
235236
workspacesDefault: false,
236237
},
@@ -243,8 +244,8 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
243244
panelOpened: true,
244245
},
245246
fileTree: {
246-
opened: true,
247-
width: DEFAULT_PANEL_WIDTH,
247+
opened: false,
248+
width: DEFAULT_FILE_TREE_WIDTH,
248249
tab: "changes" as "changes" | "all",
249250
},
250251
session: {
@@ -628,32 +629,32 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
628629
},
629630
fileTree: {
630631
opened: createMemo(() => store.fileTree?.opened ?? true),
631-
width: createMemo(() => store.fileTree?.width ?? DEFAULT_PANEL_WIDTH),
632+
width: createMemo(() => store.fileTree?.width ?? DEFAULT_FILE_TREE_WIDTH),
632633
tab: createMemo(() => store.fileTree?.tab ?? "changes"),
633634
setTab(tab: "changes" | "all") {
634635
if (!store.fileTree) {
635-
setStore("fileTree", { opened: true, width: DEFAULT_PANEL_WIDTH, tab })
636+
setStore("fileTree", { opened: true, width: DEFAULT_FILE_TREE_WIDTH, tab })
636637
return
637638
}
638639
setStore("fileTree", "tab", tab)
639640
},
640641
open() {
641642
if (!store.fileTree) {
642-
setStore("fileTree", { opened: true, width: DEFAULT_PANEL_WIDTH, tab: "changes" })
643+
setStore("fileTree", { opened: true, width: DEFAULT_FILE_TREE_WIDTH, tab: "changes" })
643644
return
644645
}
645646
setStore("fileTree", "opened", true)
646647
},
647648
close() {
648649
if (!store.fileTree) {
649-
setStore("fileTree", { opened: false, width: DEFAULT_PANEL_WIDTH, tab: "changes" })
650+
setStore("fileTree", { opened: false, width: DEFAULT_FILE_TREE_WIDTH, tab: "changes" })
650651
return
651652
}
652653
setStore("fileTree", "opened", false)
653654
},
654655
toggle() {
655656
if (!store.fileTree) {
656-
setStore("fileTree", { opened: true, width: DEFAULT_PANEL_WIDTH, tab: "changes" })
657+
setStore("fileTree", { opened: true, width: DEFAULT_FILE_TREE_WIDTH, tab: "changes" })
657658
return
658659
}
659660
setStore("fileTree", "opened", (x) => !x)

packages/app/src/pages/session.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,15 @@ export default function Page() {
16401640
consumePendingMessage: layout.pendingMessage.consume,
16411641
})
16421642

1643+
createEffect(
1644+
on(
1645+
() => params.id,
1646+
(id) => {
1647+
if (!id) requestAnimationFrame(() => inputRef?.focus())
1648+
},
1649+
),
1650+
)
1651+
16431652
onMount(() => {
16441653
document.addEventListener("keydown", handleKeyDown)
16451654
})

0 commit comments

Comments
 (0)