Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/services/questionsThunk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { data } from "store/data";
import { setCounter } from "store/reducers/counterOfAnsferSlice";
import {
setCurrentContent,
setCurrentQuestion,
Expand Down Expand Up @@ -30,18 +31,22 @@ export const chooseCurrentQuestion =
dispatch(switchCorrectVisability(false));

const questionsList = getState().questions.list.ru;
let counterQuestions = getState().counter;
const watchedList = questionsList?.filter((question) => !question.watched);
const watchedListLength = watchedList?.length;
counterQuestions += 1;
// dispatch(setCounter(counterQuestions));
console.log(setCounter(counterQuestions));

if (!!watchedListLength && watchedList && questionsList) {
const random = randomNumber(0, watchedListLength - 1);
const randomQuestion = watchedList?.[random];

dispatch(
setQuestions(checkCurrentQuestion(questionsList, randomQuestion))
);
dispatch(setCurrentQuestion(randomQuestion));
dispatch(setCurrentContent("questions"));
// console.log(setCurrentContent("questions"));
localStorage.setItem(
APP_NAME,
JSON.stringify(checkCurrentQuestion(questionsList, randomQuestion))
Expand Down
19 changes: 19 additions & 0 deletions src/store/reducers/counterOfAnsferSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable no-param-reassign */
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { IStore } from "types/model";

const initialState: IStore["counter"] = 1;

export const counterSlice = createSlice({
name: "counter",
initialState,
reducers: {
setCounter: (state, action: PayloadAction<number>) => {
state = action.payload;
},
},
});

export const { setCounter } = counterSlice.actions;

export default counterSlice.reducer;
5 changes: 3 additions & 2 deletions src/store/reducers/routingSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-param-reassign */
import { createSlice } from "@reduxjs/toolkit";
import { IStore } from "types/model";

import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { DynamicContentTypes, IQuestionItem, IStore } from "types/model";

const initialState: IStore["routing"] = {
currentPage: "quiz",
Expand Down
2 changes: 2 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { combineReducers, configureStore } from "@reduxjs/toolkit";
import questionsSlice from "./reducers/questionsSlice";
import routingSlice from "./reducers/routingSlice";
import userSlice from "./reducers/userSlice";
import counterOfAnsferSlice from "./reducers/counterOfAnsferSlice";

export const rootReducer = combineReducers({
user: userSlice,
routing: routingSlice,
questions: questionsSlice,
counter: counterOfAnsferSlice,
});

export const setupStore = () => {
Expand Down
6 changes: 6 additions & 0 deletions src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export enum CodeLanguagesList {
javascript = "javascript",
react = "react",
}
export enum counterList {
counter = "counter",
}

export type OneOfQuestionModelType = keyof typeof QuestionModel;

Expand All @@ -24,6 +27,8 @@ export type OneOfLanguageListType = keyof typeof LanguageList;
export type OneOfPagesListType = keyof typeof PagesList;

export type CodeLanguagesListType = keyof typeof CodeLanguagesList;

// export type counterListType = keyof typeof counterList;
interface ITestVariant {
id: string;
text: string;
Expand Down Expand Up @@ -63,6 +68,7 @@ export interface IStore {
openResetModal: boolean;
isCorrectVisible: boolean;
};
counter: number;
}

export type DynamicContentTypes = "questions" | "answers" | "explanation";