Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/API/userWordAPI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { host, path } from '../constants';
import { ExtendUserWord, UserWord } from '../Interfaces';

Expand Down
2 changes: 0 additions & 2 deletions src/pages/eBook/controller/musicController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const playSound = () => {
audioArray = Object.values(audioObj) as Array<string>;
}
onStart();
// eslint-disable-next-line no-console
console.log(audioArray);
}
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/pages/games/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const renderSprint = (group: number, page: number) => {
if (userWord.status === 404) {
wordBase.optional.attemp = 1;
wordBase.optional.isNewWord = true;
wordBase.optional.sprintNew = true;
createUserWord({
userId,
wordId,
Expand Down Expand Up @@ -170,7 +171,7 @@ export const renderSprint = (group: number, page: number) => {
&& !flag
) {
flag = true;
count = 1;
// count = 1;
} else if (
allResultsArray[i].classList.contains(
'sprint-container__view-element-false',
Expand All @@ -182,6 +183,7 @@ export const renderSprint = (group: number, page: number) => {
}

if (localStorage.getItem('user_id')) {
localStorage.setItem('bestScore', bestScore.toString());
const userId = <string>localStorage.getItem('user_id');
const token = <string>localStorage.getItem('token');
getUserStatistics({ userId, token }).then((response) => {
Expand Down
66 changes: 32 additions & 34 deletions src/pages/statistics/statisticsController.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Chart, registerables } from 'chart.js';
import { getUserStatistics } from '../../API/userStatustics';
// import { getUserStatistics } from '../../API/userStatustics';
import { getAllUserWords } from '../../API/userWordAPI';
import strings, { statsStrings } from '../../constants';
import createElement, { removeAllChildNodes } from '../../helpers';
import { ExtendUserWord } from '../../Interfaces';

const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

const userId = String(localStorage.getItem('user_id'));
const token = String(localStorage.getItem('token'));
const userId = localStorage.getItem('user_id');
const token = localStorage.getItem('token');

const filterWordsByDate = (
date: string,
Expand Down Expand Up @@ -57,31 +57,21 @@ const updateGameStatistics = (userWords: ExtendUserWord[]) => {
const gameRightWords = game.querySelector('[data-id="right-words"]') as HTMLElement;
let gameRightWordsNumber = 0;

try {
gameRightWordsNumber = await getUserStatistics({ userId, token });
} catch {
gameRightWordsNumber = 0;
}
// try {
// gameRightWordsNumber = await getUserStatistics({ userId, token });
// } catch {
// gameRightWordsNumber = 0;
// }

const now = Date.now();
const dayBefore = now - 24 * 60 * 60 * 1000;

if ((game as HTMLElement).dataset.game === 'Спринт') {
userWords.forEach((word) => {
if (word.optional.sprintNew) {
const { dateSprintNew } = word.optional;
if (dayBefore <= Number(dateSprintNew)) {
gameNewWordsNumber += 1;
}

if (word.optional.sprintLearned) {
const { dateSprintLearned } = word.optional;
if (dayBefore <= Number(dateSprintLearned)) {
gameLearnedWordsNumber += 1;
}
}
}
});
gameNewWordsNumber = userWords.filter((gameWord) => gameWord.optional.sprintNew && filterWordsByDate(gameWord.optional.dateSprintNew)).length;
gameLearnedWordsNumber = userWords.filter((gameWord) => gameWord.optional.sprintLearned && filterWordsByDate(gameWord.optional.dateSprintLearned)).length;
if (localStorage.getItem('bestScore')) {
gameRightWordsNumber = Number(localStorage.getItem('bestScore') as string);
}
}

if ((game as HTMLElement).dataset.game === 'Аудиовызов') {
Expand Down Expand Up @@ -172,20 +162,28 @@ const updateAllTimeStatistics = (userWords: ExtendUserWord[]) => {
}
};

const showErrorMessage = () => {
const errorMessage = createElement('div', 'stats__error-message');
errorMessage.textContent = strings.needLogin;
const allStatsContainer = document.querySelector('.canvas-container') as HTMLElement;
removeAllChildNodes(allStatsContainer);
allStatsContainer?.append(errorMessage);
};

const updateStatistics = async () => {
let userWords: ExtendUserWord[] = [];
try {
userWords = await getAllUserWords({ userId, token });
} catch (error) {
const errorMessage = createElement('div', 'stats__error-message');
errorMessage.textContent = strings.needLogin;
const allStatsContainer = document.querySelector('.canvas-container') as HTMLElement;
removeAllChildNodes(allStatsContainer);
allStatsContainer?.append(errorMessage);
if (userId && token) {
try {
userWords = await getAllUserWords({ userId, token });
updateWordsStatistics(userWords);
updateGameStatistics(userWords);
updateAllTimeStatistics(userWords);
} catch {
showErrorMessage();
}
} else {
showErrorMessage();
}
updateWordsStatistics(userWords);
updateGameStatistics(userWords);
updateAllTimeStatistics(userWords);
};

export default updateStatistics;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "es2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand Down