mirror of
https://github.com/Xevion/power-math.git
synced 2025-12-07 11:15:54 -06:00
stylize input field, add input checking/client side question generation, functional question answering
This commit is contained in:
@@ -1,17 +1,46 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div id="expression" v-katex="expression"></div>
|
<div id="expression" v-katex="expression"></div>
|
||||||
<button v-on:click="fetchQuestion">
|
<div class="container">
|
||||||
Fetch Question
|
<div class="columns is-centered">
|
||||||
</button>
|
<div class="column is-three-fifths">
|
||||||
|
<b-field id="input" @keyup.native.enter="checkAnswer()">
|
||||||
|
<b-input v-model="answer"></b-input>
|
||||||
|
</b-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
html, body {
|
html, body, #app {
|
||||||
|
height: 100%;
|
||||||
|
min-height: 100%;
|
||||||
background: hsl(0, 0%, 6%)
|
background: hsl(0, 0%, 6%)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#input {
|
||||||
|
input {
|
||||||
|
text-align: center;
|
||||||
|
background-color: transparent;
|
||||||
|
border-color: hsl(0, 0%, 20%);
|
||||||
|
border-left-width: 0;
|
||||||
|
border-right-width: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
color: hsl(0, 0%, 80%);
|
||||||
|
font-family: 'KaTeX_Main', serif;
|
||||||
|
padding: 0;
|
||||||
|
height: 1.3em;
|
||||||
|
line-height: 0;
|
||||||
|
font-size: 8em;
|
||||||
|
|
||||||
|
&:active, &:focus {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
a, p, span {
|
a, p, span {
|
||||||
color: hsl(0, 0%, 91%);
|
color: hsl(0, 0%, 91%);
|
||||||
text-shadow: hsl(0, 0%, 5%) 5px 5px;
|
text-shadow: hsl(0, 0%, 5%) 5px 5px;
|
||||||
@@ -24,6 +53,7 @@ a, p, span {
|
|||||||
#expression {
|
#expression {
|
||||||
width: 75%;
|
width: 75%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
padding-bottom: 2em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
.katex {
|
.katex {
|
||||||
@@ -35,33 +65,66 @@ a, p, span {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from "axios";
|
import arithmetic from './arithmetic.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentQuestion: null
|
answer: null,
|
||||||
|
currentQuestion: null,
|
||||||
|
correctTimeout: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
expression() {
|
expression() {
|
||||||
return this.currentQuestion != null ? this.currentQuestion.question : "loading";
|
return this.currentQuestion != null ? this.currentQuestion.text : "error";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
window.addEventListener('keyup', (e) => {
|
||||||
|
if (e.keyCode === 39) {
|
||||||
|
this.nextQuestion();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.fetchQuestion();
|
this.nextQuestion();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchQuestion() {
|
nextQuestion() {
|
||||||
// Fetch the next question, display with KaTeX
|
this.currentQuestion = arithmetic.methods.getProblem();
|
||||||
axios.put(`${process.env.VUE_APP_API_URL}/api/question/`)
|
|
||||||
.then((res) => {
|
|
||||||
this.currentQuestion = res.data
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
checkAnswer() {
|
||||||
|
// Check answer
|
||||||
|
let correct;
|
||||||
|
// Number parsing if the answer is a specific number
|
||||||
|
if (typeof this.currentQuestion.answer === "number")
|
||||||
|
correct = this.currentQuestion.answer === Number.parseInt(this.answer)
|
||||||
|
else
|
||||||
|
// String based answer (like a fraction)
|
||||||
|
correct = this.currentQuestion.answer === this.answer
|
||||||
|
|
||||||
|
if (correct) {
|
||||||
|
// Correct answer toast, new question & reset answer box
|
||||||
|
this.$buefy.toast.open({
|
||||||
|
message: 'Correct!',
|
||||||
|
type: 'is-success',
|
||||||
|
duration: 6000
|
||||||
|
})
|
||||||
|
this.nextQuestion();
|
||||||
|
this.answer = "";
|
||||||
|
} else {
|
||||||
|
// Incorrect answer toast
|
||||||
|
this.$buefy.toast.open({
|
||||||
|
message: 'Incorrect.',
|
||||||
|
type: 'is-danger',
|
||||||
|
duration: 5000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import VueKatex from 'vue-katex';
|
import VueKatex from 'vue-katex';
|
||||||
|
import Buefy from 'buefy';
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import 'katex/dist/katex.min.css';
|
import 'katex/dist/katex.min.css';
|
||||||
|
import 'buefy/dist/buefy.css';
|
||||||
|
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
Vue.use(Buefy)
|
||||||
Vue.use(VueKatex)
|
Vue.use(VueKatex)
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
|
|||||||
Reference in New Issue
Block a user