Skip to content

Commit

Permalink
Merge pull request #31
Browse files Browse the repository at this point in the history
Feat/new user hints
  • Loading branch information
light-200 authored Jan 24, 2022
2 parents 9a03888 + 0a6f999 commit 3eabca4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
--lb-list-item-bg-color: var(--lb-header-color);
--lb-list-item-color: var(--lb-header-bg-color);
--correct-word: rgb(206, 158, 1);
--infoPopup-border-color: rgb(206, 158, 1);
}

.dark {
Expand All @@ -45,6 +46,7 @@
--lb-list-item-color: var(--lb-header-bg-color);
background-color: var(--background-color);
color: var(--font-color);
--infoPopup-border-color: rgb(206, 158, 1);
}

@media only screen and (max-width: 500px) {
Expand Down
2 changes: 1 addition & 1 deletion docs/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ <h5>THEME</h5>
</div>
</div>
</div>
<div class="infoPopup hide"></div>
<div class="mainBody">
<div class="nav">
<header>type-master</header>
Expand Down
21 changes: 20 additions & 1 deletion docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,25 @@ span {
}

.footer > .links {
color:var(--github-color)
color: var(--github-color);
}

/* floating info */

.infoPopup {
position: absolute;
display: block;
padding: 0.5rem;
font-size: var(--font-size-normal);
color: var(--correct-word);
background-color: var(--background-color);
border: 2px solid;
border-color: var(--infoPopup-border-color);
border-radius: 5px;
z-index: 1;
top: 20vh;
animation: blink 0.7s steps(2) infinite;
transition: opacity 200ms ease-in-out;
}

.container {
Expand Down Expand Up @@ -425,6 +443,7 @@ footer {
place-items: center;
gap: 1rem;
transition: all 200ms ease-in-out;
z-index: 3;
}

.content {
Expand Down
17 changes: 12 additions & 5 deletions src/functions/getText.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import setWords, { spanWrap } from "../ui/uiListeners";
import start from "./start";
import { textContainer } from "../ui/uiElements";
import { getLocalData } from "../storage/localstorage";
import { getLocalData, getUserData } from "../storage/localstorage";
import handlePopup from "./handlePopup";

var text;
let callsCount = 0;

// this function is responsible for fetching the text from api
const getText = async () => {
//call the api here
const user = await getUserData();
if (!user) {
callsCount++;
if (callsCount == 5 || callsCount == 15) {
handlePopup("Login to save data 🙂", 10000);
}
}

const url = "https://api.quotable.io/random";
let data = await fetch(url)
.then((response) => response.json())
Expand All @@ -18,7 +26,6 @@ const getText = async () => {
console.error(error.message);
textContainer.innerText = "check your network connection";
});
// console.log(data,'before');

//for no punctuation mode
let userPreferences = getLocalData();
Expand All @@ -29,7 +36,7 @@ const getText = async () => {
if (userPreferences.smallCaseMode) {
data = data.toLowerCase();
}
// console.log(data,'after');

text = textContainer.innerText = data;
setWords();
spanWrap(textContainer);
Expand Down
23 changes: 23 additions & 0 deletions src/functions/handlePopup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { infoPopup } from "../ui/uiElements";

export default function handlePopup(msg, time) {
infoPopup.classList.toggle("hide");
infoPopup.classList.remove("fadeOut");
infoPopup.innerHTML = msg;

setTimeout(() => {
infoPopup.classList.add("fadeOut");
setTimeout(() => {
infoPopup.classList.add("hide");
}, 200);
}, time);

document.addEventListener("click", () => {
if (!infoPopup.classList.contains("hide")) {
infoPopup.classList.add("fadeOut");
setTimeout(() => {
infoPopup.classList.add("hide");
}, 200);
}
});
}
3 changes: 3 additions & 0 deletions src/ui/uiElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ export const textOptions = document.querySelector(".textOptions");

//next btn
export const nextBtn = document.querySelector(".nextBtn");

//alert popup
export const infoPopup = document.querySelector(".infoPopup");
10 changes: 10 additions & 0 deletions src/ui/uiListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import saveStats from "../functions/saveStats";
import { logout, signIn, signUp, updateUser } from "../firebase/auth";
import { punctuationMode, smallCaseMode } from "../functions/userDefault";
import handlePopup from "../functions/handlePopup";

var totalWords;

Expand Down Expand Up @@ -302,5 +303,14 @@ nextBtn.addEventListener("click", () => {
getText();
});

let firstTime = true;
// for caps lock
document.addEventListener("keypress", (e) => {
if (e.getModifierState("CapsLock")) {
firstTime && handlePopup("CapsLock", 2000);
}
firstTime = false;
});

export default setWords;
export { spanWrap, totalWords, handleStats };

0 comments on commit 3eabca4

Please sign in to comment.