Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable run button when running #38

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ansiConverter = new Convert({ colors: { 1: '#CE9178', 4: '#569CFF', 5: '#F

export default function () {
const [status, setStatus] = createSignal<string | null>(null)
const [running, setRunning] = createSignal(false)
const [installed, setInstalled] = createSignal('')
const [outputHtml, setOutputHtml] = createSignal('')
const [versions, setVersions] = createSignal<Versions | null>(null)
Expand All @@ -34,6 +35,8 @@ export default function () {
terminalOutput += data.message
} else if (data.kind == 'installed') {
setInstalled(data.message.length > 0 ? `Installed dependencies: ${data.message}` : '')
} else if (data.kind == 'end') {
setRunning(false)
} else {
setVersions(data as Versions)
}
Expand All @@ -54,6 +57,7 @@ export default function () {
})

async function runCode(files: CodeFile[]) {
setRunning(true)
setStatus('Starting Python...')
setInstalled('')
setOutputHtml('')
Expand All @@ -75,7 +79,7 @@ export default function () {
</aside>
</header>
<section>
<Editor runCode={runCode} />
<Editor runCode={runCode} running={running()} />
<div class="col">
<div class="status my-5">{status() || <>&nbsp;</>}</div>
<div class="installed">{installed()}</div>
Expand Down
12 changes: 9 additions & 3 deletions src/frontend/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type { Editor } from './monacoEditor'

interface EditorProps {
runCode: (files: CodeFile[]) => void
running: boolean
}

export default function ({ runCode }: EditorProps) {
export default function (props: EditorProps) {
const [saveActive, setSaveActive] = createSignal(false)
const [saveStatus, setSaveStatus] = createSignal('Changes not saved')
const [showSave, setShowSave] = createSignal(false)
Expand Down Expand Up @@ -93,7 +94,7 @@ export default function ({ runCode }: EditorProps) {

function run() {
const files = updateFiles(editor!.getValue())
runCode(files)
props.runCode(files)
save(files)
}

Expand Down Expand Up @@ -187,7 +188,12 @@ export default function ({ runCode }: EditorProps) {
</div>
)}
<div>
<button class="green" onClick={run} title="Run code in your browser and display the output">
<button
class="green"
onClick={run}
disabled={props.running}
title="Run code in your browser and display the output"
>
Run
</button>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ button {
&:hover {
background: color.adjust($btn-green, $lightness: -10%);
}
&:disabled {
background: color.adjust($btn-green, $lightness: 20%);
opacity: 0.6;
cursor: default;
}
}
&.blue {
background: $btn-blue;
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ export interface Versions {
python: string
pyodide: string
}
export interface EndRun {
kind: 'end'
}

export type WorkerResponse = Print | Message | Versions
export type WorkerResponse = Print | Message | Versions | EndRun
2 changes: 2 additions & 0 deletions src/frontend/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ self.onmessage = async ({ data }: { data: RunCode }) => {
sys.stderr.flush()
postPrint()
post({ kind: 'status', message: `${msg}ran code in ${asMs(execTime)}` })
post({ kind: 'end' })
} catch (err) {
console.warn(err)
post({ kind: 'status', message: `${msg}Error occurred` })
post({ kind: 'error', message: formatError(err) })
post({ kind: 'end' })
}
}

Expand Down