Functional dactylo prompting screen using random words
This commit is contained in:
parent
bac0c17fc6
commit
f888a553e1
11
package-lock.json
generated
11
package-lock.json
generated
@ -2368,6 +2368,14 @@
|
||||
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
|
||||
"dev": true
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"babel-eslint": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz",
|
||||
@ -5366,8 +5374,7 @@
|
||||
"follow-redirects": {
|
||||
"version": "1.13.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz",
|
||||
"integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA=="
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
|
@ -8,6 +8,7 @@
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"core-js": "^3.6.5",
|
||||
"vue": "^2.6.11"
|
||||
},
|
||||
|
@ -1,17 +1,16 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<img alt="Vue logo" src="./assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
||||
<screen></screen>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
import Screen from './components/Screen.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
HelloWorld
|
||||
Screen
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
89
src/components/Screen.vue
Normal file
89
src/components/Screen.vue
Normal file
@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<div class='container'>
|
||||
<div id="prompt-screen">
|
||||
<span v-for="(letter, index) in letters" :key="index" :class="[isActive(index) ? 'active' : '']">{{ letter }}</span>
|
||||
</div>
|
||||
|
||||
<div id="user-input">
|
||||
<input type="textarea" v-model='userText'>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
name: 'Screen',
|
||||
data() {
|
||||
return {
|
||||
words: [],
|
||||
letters: [],
|
||||
number: 50,
|
||||
userText: "",
|
||||
activeIndex: 0
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
const result = await axios.get("https://random-word-api.herokuapp.com//word?number=" + this.number)
|
||||
this.words = result.data
|
||||
this.splitWords()
|
||||
},
|
||||
methods: {
|
||||
isActive(index) {
|
||||
return index == this.cursor
|
||||
},
|
||||
splitWords() {
|
||||
this.words.forEach((word) => {
|
||||
word.split("").forEach((letter) => {
|
||||
this.letters.push(letter)
|
||||
})
|
||||
this.letters.push(" ")
|
||||
})
|
||||
},
|
||||
compareStrings(a, b) {
|
||||
let count = 0
|
||||
a.split("").forEach((aLetter, index) => {
|
||||
if(b.split("")[index] != aLetter) { return count}
|
||||
count ++
|
||||
})
|
||||
return count
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
cursor() {
|
||||
return this.compareStrings(this.userText, this.letters.join(""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
margin-left: 50px;
|
||||
}
|
||||
|
||||
|
||||
#prompt-screen {
|
||||
display: block;
|
||||
font-size: 2em;
|
||||
width: 50%;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
#user-input {
|
||||
display: block;
|
||||
float: left;
|
||||
}
|
||||
|
||||
span.active {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
#user-input > input {
|
||||
width: 500px;
|
||||
font-size: 2em;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user