Skip to content

Commit

Permalink
refactor: improve design
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdenecker committed Aug 7, 2023
1 parent 054610a commit df2bd39
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 51 deletions.
1 change: 0 additions & 1 deletion components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
>
Source</v-btn
>

</div>
<div id="editorArea" style="height: 90%" ref="codeValue"></div>
</template>
Expand Down
8 changes: 5 additions & 3 deletions components/content/Quiz.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<div v-if="type == 'multiple'">
<v-checkbox
hide-details="true"
v-for="(c, k) in choices"
:key="k"
:label="c.value"
Expand All @@ -20,8 +21,9 @@
v-model="checkedNames"
></v-checkbox>
</div>
<v-btn @click="submit">Submit</v-btn>

<div class="text-right">
<v-btn @click="submit">Submit</v-btn>
</div>
<p>{{ message }}</p>
</v-card>
</template>
Expand All @@ -39,7 +41,7 @@ export default {
},
setup(props) {
var id = new Date().valueOf();
id = "editorArea" + id
id = "editorArea" + id;
return { id };
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { resolve } = createResolver(import.meta.url)
export default defineNuxtConfig({
target: 'static',
buildModules: [
'@nuxt/image',
'@nuxt/image'
],
modules: [
'@pinia/nuxt',
Expand Down
111 changes: 94 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"@vueuse/core": "^10.3.0",
"ace-builds": "^1.23.4",
"ace-code": "^1.23.4",
"buffer": "^6.0.3",
"gh-pages": "^5.0.0",
"markdown-it": "^13.0.1",
"nuxt-content-assets": "^1.3.2",
"pyodide": "^0.23.4",
"quickjs-emscripten": "^0.23.0",
"sass": "^1.64.1",
"vite-plugin-vuetify": "^1.0.2",
"vue-markdown-render": "^2.0.1",
Expand Down
70 changes: 44 additions & 26 deletions pages/[lang]/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import { Console } from "@r-wasm/webr";
import { useCommandStore } from "@/stores/useCommandStore";
import { storeToRefs } from "pinia";
import { getQuickJS } from "quickjs-emscripten";
export default {
data() {
Expand Down Expand Up @@ -118,13 +119,16 @@ export default {
);
},
});
} else {
} else if (lang == "js") {
const QuickJS = await getQuickJS();
webConsole = QuickJS.newContext();
} else if (lang == "python") {
webConsole = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.23.4/full/",
stdout: (line) => document.getElementById("out").append(line + "\n"),
stderr: (line) => document.getElementById("out").append(line + "\n"),
});
}
}
// Get Tuto pages
const tutosList = await queryContent(path).find();
Expand Down Expand Up @@ -181,22 +185,15 @@ print("Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER)
},
async onEnter() {
if (this.lang == "python") {
document.getElementById("out").append(">>>" + this.command + "\n");
try {
let output = this.webConsole.runPython(this.command + "\n\n");
if (output !== undefined) {
document.getElementById("out").append(output + "\n");
}
} catch (err) {
document.getElementById("out").append(err + "\n");
}
this.command = "";
this.runPython();
} else if (this.lang == "r") {
this.webConsole.stdin(this.command);
document.getElementById("out").append(this.command + "\n");
this.command = "";
}
} else if (this.lang == "js") {
this.runJS();
}
this.command = "";
var objDiv = document.getElementById("divConsole");
objDiv.scrollTop = objDiv.scrollHeight;
},
Expand Down Expand Up @@ -229,6 +226,34 @@ print("Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER)
this.test = result;
},
async runJS() {
const result = this.webConsole.evalCode(this.command);
document.getElementById("out").append(">" + this.command + "\n");
if (result.error) {
document
.getElementById("out")
.append(this.webConsole.dump(result.error) + "\n");
this.command = "";
result.error.dispose();
} else {
document
.getElementById("out")
.append(this.webConsole.dump(result.value) + "\n");
this.command = "";
result.value.dispose();
}
},
runPython() {
document.getElementById("out").append(">>>" + this.store.command + "\n");
try {
let output = this.webConsole.runPython(this.store.command + "\n\n");
if (output !== undefined) {
document.getElementById("out").append(output + "\n");
}
} catch (err) {
document.getElementById("out").append(err + "\n");
}
},
},
watch: {
async command(new_val) {
Expand All @@ -239,18 +264,11 @@ print("Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER)
document.getElementById("out").append(element + "\n");
}
} else if (this.lang == "python") {
document
.getElementById("out")
.append(">>>" + this.store.command + "\n");
try {
let output = this.webConsole.runPython(this.store.command + "\n\n");
if (output !== undefined) {
document.getElementById("out").append(output + "\n");
}
} catch (err) {
document.getElementById("out").append(err + "\n");
}
}
this.runPython();
} else if (this.lang == "js") {
this.runJS();
}
this.store.reset();
var objDiv = document.getElementById("divConsole");
objDiv.scrollTop = objDiv.scrollHeight;
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
>
<v-btn
class="mx-3"
href="https://github.com/IFB-ElixirFr/Wasm4Learn/discussions"
href="https://github.com/IFB-ElixirFr/R_WASM/discussions"
target="_blank"
>
<v-icon class="me-3">mdi-forum</v-icon>
Expand Down
Loading

0 comments on commit df2bd39

Please sign in to comment.