mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-07 16:17:25 +03:00
feat(tui): choose where to save exports in the new export dialog
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
type Accessor,
|
||||
} from "solid-js"
|
||||
import path from "node:path"
|
||||
import { EOL } from "node:os"
|
||||
import { EOL, tmpdir } from "node:os"
|
||||
import { mkdir, writeFile } from "node:fs/promises"
|
||||
import { useRoute, useRouteData } from "../../context/route"
|
||||
import { createStore } from "solid-js/store"
|
||||
@@ -1376,7 +1376,7 @@ export function Session(props: {
|
||||
}
|
||||
|
||||
const filepath = path.join(
|
||||
paths.cwd,
|
||||
options.location === "temp" ? tmpdir() : paths.cwd,
|
||||
`session-${crypto.randomUUID()}.${options.format === "markdown" ? "md" : "json"}`,
|
||||
)
|
||||
await writeExport(filepath, content)
|
||||
|
||||
@@ -7,12 +7,14 @@ import { createStore } from "solid-js/store"
|
||||
import { createMemo, createSignal, For, Show } from "solid-js"
|
||||
|
||||
export type ExportFormat = "markdown" | "json"
|
||||
export type ExportLocation = "project" | "temp"
|
||||
|
||||
export type DialogExportOptionsProps = {
|
||||
defaultThinking: boolean
|
||||
onConfirm?: (options: {
|
||||
action: "copy" | "export"
|
||||
format: ExportFormat
|
||||
location?: ExportLocation
|
||||
thinking: boolean
|
||||
tools: boolean
|
||||
sanitize: boolean
|
||||
@@ -31,12 +33,13 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
|
||||
)
|
||||
}
|
||||
|
||||
type Row = "format" | "thinking" | "tools" | "sanitize"
|
||||
type Row = "format" | "location" | "thinking" | "tools" | "sanitize"
|
||||
|
||||
/** Export options as a list of values, under the "new-designs" experiment: ↑/↓ moves, ←/→ or space changes. */
|
||||
function DialogExportOptionsList(props: DialogExportOptionsProps) {
|
||||
const [store, setStore] = createStore({
|
||||
format: "markdown" as ExportFormat,
|
||||
location: "project" as ExportLocation,
|
||||
thinking: props.defaultThinking,
|
||||
tools: true,
|
||||
sanitize: false,
|
||||
@@ -47,6 +50,7 @@ function DialogExportOptionsList(props: DialogExportOptionsProps) {
|
||||
props.onConfirm?.({
|
||||
action,
|
||||
format: store.format,
|
||||
location: store.location,
|
||||
thinking: store.thinking,
|
||||
tools: store.tools,
|
||||
sanitize: store.sanitize,
|
||||
@@ -54,6 +58,7 @@ function DialogExportOptionsList(props: DialogExportOptionsProps) {
|
||||
|
||||
const change = (row: Row) => {
|
||||
if (row === "format") return setStore("format", store.format === "markdown" ? "json" : "markdown")
|
||||
if (row === "location") return setStore("location", store.location === "project" ? "temp" : "project")
|
||||
setStore(row, !store[row])
|
||||
}
|
||||
|
||||
@@ -66,6 +71,13 @@ function DialogExportOptionsList(props: DialogExportOptionsProps) {
|
||||
footerOverhang: 2,
|
||||
footer: <DialogSelectChoice value={store.format} active={selected() === "format"} />,
|
||||
},
|
||||
{
|
||||
title: "Location",
|
||||
value: "location" as Row,
|
||||
onSelect: () => change("location"),
|
||||
footerOverhang: 2,
|
||||
footer: <DialogSelectChoice value={store.location} active={selected() === "location"} />,
|
||||
},
|
||||
...(store.format === "markdown"
|
||||
? [
|
||||
{
|
||||
@@ -286,6 +298,7 @@ DialogExportOptions.show = (dialog: DialogContext, defaultThinking: boolean) =>
|
||||
return new Promise<{
|
||||
action: "copy" | "export"
|
||||
format: ExportFormat
|
||||
location?: ExportLocation
|
||||
thinking: boolean
|
||||
tools: boolean
|
||||
sanitize: boolean
|
||||
|
||||
Reference in New Issue
Block a user