Skip to content

Commit

Permalink
change contentFromUrl into codeFromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Aug 22, 2024
1 parent 9d1b7fe commit 51f6295
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function App() {
const [code, setCode] = useState<string>('')
const [project, setProject] = useState<string>('mathlib-demo')
const [url, setUrl] = useState<string|null>(null)
const [contentFromUrl, setContentFromUrl] = useState<string>('')
const [codeFromUrl, setCodeFromUrl] = useState<string>('')
const { width } = useWindowDimensions()

// Lean4monaco options
Expand Down Expand Up @@ -306,25 +306,25 @@ function App() {
console.debug(`[Lean4web] Loading from ${url}`)
let txt = "Loading…"
setContent(txt)
setContentFromUrl(txt)
setCodeFromUrl(txt)
fetch(url)
.then((response) => response.text())
.then((code) => {
setContent(code)
setContentFromUrl(code)
setCodeFromUrl(code)
})
.catch( err => {
let errorTxt = `ERROR: ${err.toString()}`
setContent(errorTxt)
setContentFromUrl(errorTxt)
setCodeFromUrl(errorTxt)
})
}, [editor, url])

// keep url updated on changes
useEffect(() => {
if (!editor) { return }
let _project = (project == 'mathlib-demo' ? null : project)
if (code === contentFromUrl) {
if (code === codeFromUrl) {
if (url !== null) {
let args = {project: _project, url: encodeURIComponent(url), code: null, codez: null}
history.replaceState(undefined, undefined!, formatArgs(args))
Expand All @@ -351,7 +351,7 @@ function App() {
let args = {project: _project, url: null, code: fixedEncodeURIComponent(code), codez: null}
history.replaceState(undefined, undefined!, formatArgs(args))
}
}, [editor, project, code, contentFromUrl])
}, [editor, project, code, codeFromUrl])

return (
<PreferencesContext.Provider value={{preferences, setPreferences}}>
Expand All @@ -364,7 +364,7 @@ function App() {
project={project}
setProject={setProject}
setUrl={setUrl}
contentFromUrl={contentFromUrl}
codeFromUrl={codeFromUrl}
restart={restart}
codeMirror={codeMirror}
setCodeMirror={setCodeMirror}
Expand Down
6 changes: 3 additions & 3 deletions client/src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ export const Menu: FC <{
project: string,
setProject: Dispatch<SetStateAction<string>>,
setUrl: Dispatch<SetStateAction<string | null>>,
contentFromUrl: string,
codeFromUrl: string,
restart: () => void,
codeMirror: boolean,
setCodeMirror: Dispatch<SetStateAction<boolean>>,
}> = ({code, setContent, project, setProject, setUrl, contentFromUrl, restart, codeMirror, setCodeMirror}) => {
}> = ({code, setContent, project, setProject, setUrl, codeFromUrl, restart, codeMirror, setCodeMirror}) => {
// state for handling the dropdown menus
const [openNav, setOpenNav] = useState(false)
const [openExample, setOpenExample] = useState(false)
Expand All @@ -162,7 +162,7 @@ export const Menu: FC <{
console.debug('load code from url')
setUrl((oldUrl: string|null) => {
if (oldUrl === url) {
setContent(contentFromUrl)
setContent(codeFromUrl)
}
return url
})
Expand Down

0 comments on commit 51f6295

Please sign in to comment.