Skip to content

Commit 412d93e

Browse files
committed
fix(tui): choose project or temp folder for session exports
1 parent 88f4677 commit 412d93e

3 files changed

Lines changed: 55 additions & 6 deletions

File tree

‎packages/tui/src/routes/session/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type Accessor,
1414
} from "solid-js"
1515
import path from "node:path"
16-
import { EOL } from "node:os"
16+
import { EOL, tmpdir } from "node:os"
1717
import { mkdir, writeFile } from "node:fs/promises"
1818
import { useRoute, useRouteData } from "../../context/route"
1919
import { createStore } from "solid-js/store"
@@ -1376,7 +1376,7 @@ export function Session(props: {
13761376
}
13771377

13781378
const filepath = path.join(
1379-
paths.cwd,
1379+
options.location === "project" ? paths.cwd : tmpdir(),
13801380
`session-${crypto.randomUUID()}.${options.format === "markdown" ? "md" : "json"}`,
13811381
)
13821382
await writeExport(filepath, content)

‎packages/tui/src/ui/dialog-export-options.tsx‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ import { createStore } from "solid-js/store"
77
import { createMemo, createSignal, For, Show } from "solid-js"
88

99
export type ExportFormat = "markdown" | "json"
10+
export type ExportLocation = "project" | "temp"
1011

1112
export type DialogExportOptionsProps = {
1213
defaultThinking: boolean
1314
onConfirm?: (options: {
1415
action: "copy" | "export"
1516
format: ExportFormat
17+
location: ExportLocation
1618
thinking: boolean
1719
tools: boolean
1820
sanitize: boolean
1921
}) => void
2022
onCancel?: () => void
2123
}
2224

23-
type Active = ExportFormat | "thinking" | "tools" | "sanitize" | "copy" | "export"
25+
type Active = ExportFormat | ExportLocation | "thinking" | "tools" | "sanitize" | "copy" | "export"
2426

2527
export function DialogExportOptions(props: DialogExportOptionsProps) {
2628
const newDesigns = useNewDesigns()
@@ -31,12 +33,13 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
3133
)
3234
}
3335

34-
type Row = "format" | "thinking" | "tools" | "sanitize"
36+
type Row = "format" | "location" | "thinking" | "tools" | "sanitize"
3537

3638
/** Export options as a list of values, under the "new-designs" experiment: ↑/↓ moves, ←/→ or space changes. */
3739
function DialogExportOptionsList(props: DialogExportOptionsProps) {
3840
const [store, setStore] = createStore({
3941
format: "markdown" as ExportFormat,
42+
location: "project" as ExportLocation,
4043
thinking: props.defaultThinking,
4144
tools: true,
4245
sanitize: false,
@@ -47,13 +50,15 @@ function DialogExportOptionsList(props: DialogExportOptionsProps) {
4750
props.onConfirm?.({
4851
action,
4952
format: store.format,
53+
location: store.location,
5054
thinking: store.thinking,
5155
tools: store.tools,
5256
sanitize: store.sanitize,
5357
})
5458

5559
const change = (row: Row) => {
5660
if (row === "format") return setStore("format", store.format === "markdown" ? "json" : "markdown")
61+
if (row === "location") return setStore("location", store.location === "project" ? "temp" : "project")
5762
setStore(row, !store[row])
5863
}
5964

@@ -66,6 +71,13 @@ function DialogExportOptionsList(props: DialogExportOptionsProps) {
6671
footerOverhang: 2,
6772
footer: <DialogSelectChoice value={store.format} active={selected() === "format"} />,
6873
},
74+
{
75+
title: "Location",
76+
value: "location" as Row,
77+
onSelect: () => change("location"),
78+
footerOverhang: 2,
79+
footer: <DialogSelectChoice value={store.location} active={selected() === "location"} />,
80+
},
6981
...(store.format === "markdown"
7082
? [
7183
{
@@ -134,6 +146,7 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
134146
const labelColor = (active: boolean) => (active ? theme.text.formfield.focused : theme.text.formfield.base)
135147
const [store, setStore] = createStore({
136148
format: "markdown" as ExportFormat,
149+
location: "project" as ExportLocation,
137150
thinking: props.defaultThinking,
138151
tools: true,
139152
sanitize: false,
@@ -144,6 +157,7 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
144157
props.onConfirm?.({
145158
action,
146159
format: store.format,
160+
location: store.location,
147161
thinking: store.thinking,
148162
tools: store.tools,
149163
sanitize: store.sanitize,
@@ -154,6 +168,10 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
154168
setStore("format", store.active)
155169
return
156170
}
171+
if (store.active === "project" || store.active === "temp") {
172+
setStore("location", store.active)
173+
return
174+
}
157175
if (store.active === "thinking") setStore("thinking", !store.thinking)
158176
if (store.active === "tools") setStore("tools", !store.tools)
159177
if (store.active === "sanitize") setStore("sanitize", !store.sanitize)
@@ -162,7 +180,9 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
162180

163181
const move = (offset: number) => {
164182
const options: Active[] =
165-
store.format === "markdown" ? ["markdown", "json", "thinking", "tools"] : ["markdown", "json", "sanitize"]
183+
store.format === "markdown"
184+
? ["markdown", "json", "project", "temp", "thinking", "tools"]
185+
: ["markdown", "json", "project", "temp", "sanitize"]
166186
const order: Active[] = [...options, "copy", "export"]
167187
setStore("active", order[(order.indexOf(store.active) + offset + order.length) % order.length])
168188
}
@@ -186,6 +206,11 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
186206
setStore("active", format)
187207
}
188208

209+
const selectLocation = (location: ExportLocation) => {
210+
setStore("location", location)
211+
setStore("active", location)
212+
}
213+
189214
return (
190215
<DialogLayout
191216
header={<DialogHeader title="Export session" />}
@@ -240,6 +265,29 @@ function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
240265
</For>
241266
</box>
242267
</box>
268+
<box flexDirection="row" gap={1}>
269+
<text fg={theme.text.base} width={10}>
270+
Save to:
271+
</text>
272+
<box flexDirection="row" gap={1}>
273+
<For each={["project", "temp"] as const}>
274+
{(location) => (
275+
<box
276+
flexDirection="row"
277+
gap={1}
278+
paddingLeft={1}
279+
paddingRight={1}
280+
onMouseUp={() => selectLocation(location)}
281+
>
282+
<text fg={markColor(store.active === location, store.location === location)}>
283+
{store.location === location ? "◉" : "○"}
284+
</text>
285+
<text fg={labelColor(store.active === location)}>{location === "project" ? "Project" : "Temp"}</text>
286+
</box>
287+
)}
288+
</For>
289+
</box>
290+
</box>
243291
<Show when={store.format === "markdown"}>
244292
<box
245293
flexDirection="row"
@@ -286,6 +334,7 @@ DialogExportOptions.show = (dialog: DialogContext, defaultThinking: boolean) =>
286334
return new Promise<{
287335
action: "copy" | "export"
288336
format: ExportFormat
337+
location: ExportLocation
289338
thinking: boolean
290339
tools: boolean
291340
sanitize: boolean

‎packages/tui/test/component/dialog-export-options.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test("tab and shift+tab move a visible focus through the export options", async
5555
expect(span("Include thinking")?.fg.equals(field())).toBe(true)
5656
expect(span("Copy")?.bg.equals(focusedButton())).toBe(false)
5757

58-
for (const _ of [1, 2, 3, 4]) app.mockInput.pressTab()
58+
for (const _ of [1, 2, 3, 4, 5, 6]) app.mockInput.pressTab()
5959
await app.waitForFrame(() => span("Copy")?.bg.equals(focusedButton()) === true)
6060
expect(span("Include tools")?.fg.equals(field())).toBe(true)
6161

0 commit comments

Comments
 (0)