Skip to content

Commit

Permalink
fix initial selected file
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronvg committed Jul 3, 2024
1 parent f80da1e commit 877926b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 0 additions & 6 deletions typescript/fiddle-frontend/app/[project_id]/_atoms/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ export const activeFileNameAtom = atom(
const files = get(currentEditorFilesAtom)
if (files.some((f) => f.path === path)) {
set(activeFileNameAtomRaw, path)
const availableFunctions = get(availableFunctionsAtom)
// Set the default selected function when the current active file is changed
const selectedFunction = availableFunctions.find((f) => f.span.file_path === path)
if (selectedFunction) {
set(selectedFunctionAtom, selectedFunction.name)
}
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { BAML_DIR } from '@/lib/constants'
import type { BAMLProject } from '@/lib/exampleProjects'
import { BAML, theme } from '@baml/codemirror-lang'
import type { ParserDatabase } from '@baml/common'
import { diagnositicsAtom, numErrorsAtom, updateFileAtom } from '@baml/playground-common/baml_wasm_web/EventListener'
import {
availableFunctionsAtom,
diagnositicsAtom,
numErrorsAtom,
selectedFunctionAtom,
updateFileAtom,
} from '@baml/playground-common/baml_wasm_web/EventListener'
import { atomStore } from '@baml/playground-common/baml_wasm_web/JotaiProvider'
import { projectFamilyAtom, runtimeFamilyAtom } from '@baml/playground-common/baml_wasm_web/baseAtoms'
import { Button } from '@baml/playground-common/components/ui/button'
Expand Down Expand Up @@ -142,6 +148,9 @@ export const CodeMirrorEditor = ({ project }: { project: BAMLProject }) => {
const activeFileContent = useAtomValue(activeFileContentAtom)
const updateFile = useSetAtom(updateFileAtom)

const availableFunctions = useAtomValue(availableFunctionsAtom)
const setSelectedFunction = useSetAtom(selectedFunctionAtom)

const ref = useRef<ReactCodeMirrorRef>({})

// force linting on file changes so playground updates
Expand All @@ -154,6 +163,14 @@ export const CodeMirrorEditor = ({ project }: { project: BAMLProject }) => {
}
}, [JSON.stringify(editorFiles)])

useEffect(() => {
const func = availableFunctions.find((f) => f.span.file_path === activeFile)
if (func) {
console.log('setting selected function', func.name)
setSelectedFunction(func.name)
}
}, [JSON.stringify(editorFiles.map((f) => f.path)), activeFile, availableFunctions])

const setUnsavedChanges = useSetAtom(unsavedChangesAtom)

const langExtensions = getLanguage(activeFile)
Expand Down

0 comments on commit 877926b

Please sign in to comment.