Skip to content

Commit

Permalink
chore: update config vars names to reflect that they are constants
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusddd committed Jun 7, 2024
1 parent 3b03603 commit 334727d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const apiUrl = 'https://poetrydb.org/author,title/Shakespeare;Sonnet'
export const specialKeys = [
export const API_URL = 'https://poetrydb.org/author,title/Shakespeare;Sonnet'
export const SPECIAL_KEYS = [
'Control', 'Shift', 'Meta', 'Alt', 'ArrowUp', 'ArrowDown', 'ArrowLeft',
'ArrowRight', '§', 'Tab',
]
export const timerTime = 60 // in seconds
export const extraLimit = 5 // the limit of incorrect letters at the end of word
export const TIMER_TIME = 60 // in seconds
export const EXTRA_LIMIT = 5 // the limit of incorrect letters at the end of word
8 changes: 4 additions & 4 deletions src/display.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {apiUrl, timerTime} from './config.js'
import {API_URL, TIMER_TIME} from './config.js'
import {appMsg, getApiJson} from './utils.js'

let CURRENT_API_URL = '';
Expand Down Expand Up @@ -28,15 +28,15 @@ export default class Display {
* @param {string=} url - api url from where the text is taken from
*/
async create(url = null) {
if (!url) url = this.constructUrl(apiUrl, 154)
if (!url) url = this.constructUrl(API_URL, 154)

const apiJson = await getApiJson(url, this.msgElement)
if (!apiJson) return

const words = this.convertJsonToWords(apiJson)

this.buildWords(words)
this.updateTimerElement(timerTime)
this.updateTimerElement(TIMER_TIME)

appMsg(this.msgElement).start()

Expand Down Expand Up @@ -148,7 +148,7 @@ export default class Display {
* @param {Element} appElement - root app element.
*/
timer(appElement) {
let timer = timerTime
let timer = TIMER_TIME
let timeElapsed = 0

const timerInterval = setInterval(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Cursor from './cursor.js'
import Display from './display.js'
import Key from './key.js'
import Stats from './stats.js'
import {specialKeys} from './config.js'
import {SPECIAL_KEYS} from './config.js'
import {appMsg} from './utils.js'

document.addEventListener('DOMContentLoaded', () => {
Expand Down Expand Up @@ -72,7 +72,7 @@ function touchTyping(appElement) {
function type(key, evt) {
if (evt.key === ' ') {
if (!key.isFirstWordLetter()) key.nextWord()
} else if (specialKeys.some(item => evt.key === item)) {
} else if (SPECIAL_KEYS.some(item => evt.key === item)) {
return
} else if (evt.key === 'Backspace') {
key.prev()
Expand Down
4 changes: 2 additions & 2 deletions src/key.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getBBox} from './utils.js'
import {extraLimit} from './config.js'
import {EXTRA_LIMIT} from './config.js'

/**
* Checks if user input matches letters and goes back and forth the words.
Expand Down Expand Up @@ -162,7 +162,7 @@ export default class Key {
)

if (cursorX > (displayBBox.x + displayBBox.width)) return
if (this.activeWord.querySelectorAll('.extra').length === extraLimit) return
if (this.activeWord.querySelectorAll('.extra').length === EXTRA_LIMIT) return

const div = document.createElement('div')
div.classList.add('letter', 'incorrect', 'extra')
Expand Down

0 comments on commit 334727d

Please sign in to comment.