From 3df0230c7038d172268705a5c7879f92151b1f19 Mon Sep 17 00:00:00 2001 From: Pranav Sinha Date: Wed, 25 Aug 2021 19:16:37 +0530 Subject: [PATCH] Added a delimiter switch (#1754) by pran01 * Added a delimiter switch * Added delimiter to wordfilter * Delimiter Switch to Delimiter Checkbox * fixed random input fields styling * regenerated lockfile to version 2 * brought back example.evn * removed console logs Co-authored-by: Jack --- .github/pull_request_template.md | 1 - backend/example.env | 2 +- package-lock.json | 3 -- src/js/popups/custom-text-popup.js | 47 ++++++++++++++++++++++++++++-- src/js/popups/word-filter-popup.js | 3 +- src/js/test/custom-text.js | 5 ++++ src/js/test/test-logic.js | 38 ++++++++++++++++++++++-- src/sass/style.scss | 5 ++-- static/index.html | 19 ++++++++++++ static/languages/_groups.json | 2 +- static/quotes/arabic.json | 26 +++++------------ static/quotes/english.json | 6 ++-- 12 files changed, 121 insertions(+), 36 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 5baccfca4..bef0663ab 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,7 +10,6 @@ If your change is visual (mainly themes) it would be extra awesome if you could - Closes # diff --git a/backend/example.env b/backend/example.env index 838a5523e..aafe4e753 100644 --- a/backend/example.env +++ b/backend/example.env @@ -1,2 +1,2 @@ DB_URI=mongodb://localhost:27017 -DB_NAME=monkeytype +DB_NAME=monkeytype \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 57c7ae07d..e0ca5049c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10314,9 +10314,6 @@ }, "bin": { "nopt": "bin/nopt.js" - }, - "engines": { - "node": "*" } }, "node_modules/normalize-package-data": { diff --git a/src/js/popups/custom-text-popup.js b/src/js/popups/custom-text-popup.js index ed17b8612..342d33c9d 100644 --- a/src/js/popups/custom-text-popup.js +++ b/src/js/popups/custom-text-popup.js @@ -21,7 +21,7 @@ export function show() { .css("opacity", 0) .removeClass("hidden") .animate({ opacity: 1 }, 100, () => { - let newtext = CustomText.text.join(" "); + let newtext = CustomText.text.join(CustomText.delimiter); newtext = newtext.replace(/\n /g, "\n"); $(`${popup} textarea`).val(newtext); $(`${popup} .wordcount input`).val(CustomText.word); @@ -34,6 +34,49 @@ export function show() { }, 150); } +$(`${popup} .delimiter.switch .buttons .delimiter.button`).click((e) => { + $(`${popup} .delimiter.switch .buttons .delimiter.button.active`).removeClass( + "active" + ); + let target = $(e.currentTarget); + let delimiter = target.attr("delimiter"); + target.addClass("active"); + CustomText.setDelimiter(delimiter); + $(wrapper).animate({ opacity: 1 }, 100, () => { + let newtext = CustomText.text.join(CustomText.delimiter); + newtext = newtext.replace(/\n /g, "\n"); + $(`${popup} textarea`).val(newtext); + }); +}); + +$(`${popup} .delimiterCheck input`).change(() => { + let delimiter; + if ($(`${popup} .delimiterCheck input`).prop("checked")) { + delimiter = "|"; + } else { + delimiter = " "; + } + if ( + $(`${popup} textarea`).val() != CustomText.text.join(CustomText.delimiter) + ) { + let currentText = $(`${popup} textarea`).val(); + let currentTextSplit = currentText.split(CustomText.delimiter); + let newtext = currentTextSplit.join(delimiter); + newtext = newtext.replace(/\n /g, "\n"); + $(`${popup} textarea`).val(newtext); + } else { + let newtext = CustomText.text.join(delimiter); + newtext = newtext.replace(/\n /g, "\n"); + $(`${popup} textarea`).val(newtext); + } + CustomText.setDelimiter(delimiter); + // $(wrapper).animate({ opacity: 1 }, 100, () => { + // let newtext = CustomText.text.join(CustomText.delimiter); + // newtext = newtext.replace(/\n /g, "\n"); + // $(`${popup} textarea`).val(newtext); + // }); +}); + export function hide() { if (!$(wrapper).hasClass("hidden")) { $(wrapper) @@ -101,7 +144,7 @@ $("#customTextPopup .apply").click(() => { } // text = Misc.remove_non_ascii(text); text = text.replace(/[\u2060]/g, ""); - text = text.split(" "); + text = text.split(CustomText.delimiter); CustomText.setText(text); CustomText.setWord(parseInt($("#customTextPopup .wordcount input").val())); CustomText.setTime(parseInt($("#customTextPopup .time input").val())); diff --git a/src/js/popups/word-filter-popup.js b/src/js/popups/word-filter-popup.js index cc1bc9f6c..501c97b85 100644 --- a/src/js/popups/word-filter-popup.js +++ b/src/js/popups/word-filter-popup.js @@ -1,4 +1,5 @@ import * as Misc from "./misc"; +import * as CustomText from "./custom-text"; let initialised = false; @@ -68,7 +69,7 @@ async function filter(language) { async function apply(set) { let language = $("#wordFilterPopup .languageInput").val(); let filteredWords = await filter(language); - let customText = filteredWords.join(" "); + let customText = filteredWords.join(CustomText.delimiter); $("#customTextPopup textarea").val( (index, val) => (set ? "" : val + " ") + customText diff --git a/src/js/test/custom-text.js b/src/js/test/custom-text.js index 2ad86b05f..0f010d534 100644 --- a/src/js/test/custom-text.js +++ b/src/js/test/custom-text.js @@ -3,6 +3,7 @@ export let isWordRandom = false; export let isTimeRandom = false; export let word = ""; export let time = ""; +export let delimiter = " "; export function setText(txt) { text = txt; @@ -23,3 +24,7 @@ export function setTime(val) { export function setWord(val) { word = val; } + +export function setDelimiter(val) { + delimiter = val; +} diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index e0aba56bd..0006c3e2d 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -89,6 +89,18 @@ class Words { increaseCurrentIndex() { this.currentIndex++; } + clean() { + for (let s of this.list) { + if (/ +/.test(s)) { + let id = this.list.indexOf(s); + let tempList = s.split(" "); + this.list.splice(id, 1); + for (let i = 0; i < tempList.length; i++) { + this.list.splice(id + i, 0, tempList[i]); + } + } + } + } } class Input { @@ -546,8 +558,7 @@ export async function init() { regenarationCount < 100 && (randomWord == previousWord || randomWord == previousWord2 || - (!Config.punctuation && randomWord == "I") || - randomWord.indexOf(" ") > -1) + (!Config.punctuation && randomWord == "I")) ) { regenarationCount++; randomWord = wordset.randomWord(); @@ -605,8 +616,29 @@ export async function init() { if (/\t/g.test(randomWord)) { setHasTab(true); } + randomWord = randomWord.trim(); + randomWord = randomWord.replace(/\\\\t/g, "\t"); + randomWord = randomWord.replace(/\\\\n/g, "\n"); + randomWord = randomWord.replace(/\\t/g, "\t"); + randomWord = randomWord.replace(/\\n/g, "\n"); + randomWord = randomWord.replace(/ +/g, " "); + randomWord = randomWord.replace(/( *(\r\n|\r|\n) *)/g, "\n "); + randomWord = randomWord.replace(/[\u2060]/g, " "); + console.log(`randomwordLast=${randomWord}`); + if (/ +/.test(randomWord)) { + let randomList = randomWord.split(" "); + let id = 0; + while (id < randomList.length) { + words.push(randomList[id]); + id++; - words.push(randomWord); + if (words.length == wordsBound) break; + } + i = words.length - 1; + } else { + words.push(randomWord); + } + console.log(`words=${words.list} i=${i}`); } } } else if (Config.mode == "quote") { diff --git a/src/sass/style.scss b/src/sass/style.scss index e95795030..353b64c96 100644 --- a/src/sass/style.scss +++ b/src/sass/style.scss @@ -580,7 +580,6 @@ a:hover { display: grid; gap: 1rem; width: 60vw; - .wordfilter { width: 33%; justify-self: right; @@ -613,9 +612,11 @@ a:hover { .randomInputFields { display: grid; - grid-template-columns: 1fr 1fr 1fr; + grid-template-columns: 1fr auto 1fr; text-align: center; align-items: center; + width: 100%; + gap: 1rem; } } } diff --git a/static/index.html b/static/index.html index 954f150e5..db0d121d1 100644 --- a/static/index.html +++ b/static/index.html @@ -90,6 +90,7 @@ >
+ @@ -150,10 +151,19 @@