diff --git a/src/index.tsx b/src/index.tsx index bf27322b..78665016 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -26,7 +26,7 @@ const routeslink: {path: string; page: JSX.Element; header: boolean; sidebar: bo {path: "/list-empty", page: , header: false, sidebar: false}, {path: "/list-full", page: , header: false, sidebar: false}, {path: "/list-short", page: , header: false, sidebar: false}, - {path: "/create", page: , header: true, sidebar: true}, + {path: "/create-quize/:quizId", page: , header: true, sidebar: true}, {path: "/questions", page: , header: true, sidebar: true}, {path: "/contacts", page: , header: true, sidebar: true}, {path: "/result", page: , header: true, sidebar: true}, diff --git a/src/pages/createQuize/FirstQuiz.tsx b/src/pages/createQuize/FirstQuiz.tsx index 59f979e5..3bb14d02 100755 --- a/src/pages/createQuize/FirstQuiz.tsx +++ b/src/pages/createQuize/FirstQuiz.tsx @@ -2,6 +2,7 @@ import {Button, Typography, useTheme} from "@mui/material"; import ComplexNavText from "./ComplexNavText"; import SectionWrapper from "@ui_kit/SectionWrapper"; import {quizStore} from "@root/quizes"; +import {Link, useNavigate} from "react-router-dom"; function getRandom(min: number, max:number) { min = Math.ceil(min); @@ -10,7 +11,8 @@ function getRandom(min: number, max:number) { } export default function FirstQuiz() { - const {listQuizes, updateQuizesList, removeQuiz} = quizStore() + const {listQuizes, updateQuizesList, removeQuiz, createBlank} = quizStore() + const navigate = useNavigate() return ( { - updateQuizesList({ - "id": getRandom(10000, 100000), - "qid": "string", - "deleted": false, - "archived": true, - "fingerprinting": true, - "repeatable": true, - "note_prevented": true, - "mail_notifications": true, - "unique_answers": true, - "name": "string", - "description": "string", - "config": "string", - "status": "string", - "limit": 0, - "due_to": 0, - "time_of_passing": 0, - "pausable": true, - "version": 0, - "version_comment": "string", - "created_at": "string", - "updated_at": "string", - "question_cnt": 0, - "passed_count": 0, - "average_time": 0, - "super": true, - "group_id": 0 - }) + navigate(`/create-quize/${createBlank()}`); }} > Создать + diff --git a/src/pages/createQuize/MyQuizzesFull.tsx b/src/pages/createQuize/MyQuizzesFull.tsx index 631b3a54..cba20260 100644 --- a/src/pages/createQuize/MyQuizzesFull.tsx +++ b/src/pages/createQuize/MyQuizzesFull.tsx @@ -5,21 +5,17 @@ import SectionWrapper from "@ui_kit/SectionWrapper"; import React from "react"; import {quizStore} from "@root/quizes"; import FirstQuiz from "./FirstQuiz"; +import {useNavigate} from "react-router-dom"; interface Props { outerContainerSx?: SxProps; children?: React.ReactNode; } -function getRandom(min: number, max:number) { - min = Math.ceil(min); - max = Math.floor(max); - return Math.floor(Math.random() * (max - min)) + min; -} - - export default function MyQuizzesFull({outerContainerSx: sx, children}: Props) { - const {listQuizes, updateQuizesList, removeQuiz} = quizStore() + const {listQuizes, updateQuizesList, removeQuiz, createBlank} = quizStore() + const navigate = useNavigate() + return ( <> {Object.keys(listQuizes).length === 0 ? @@ -44,34 +40,7 @@ export default function MyQuizzesFull({outerContainerSx: sx, children}: Props) { variant="contained" sx={{padding: "10px 47px"}} onClick={() => { - updateQuizesList({ - "id": getRandom(10000, 100000), - "qid": "string", - "deleted": false, - "archived": true, - "fingerprinting": true, - "repeatable": true, - "note_prevented": true, - "mail_notifications": true, - "unique_answers": true, - "name": "string", - "description": "string", - "config": "string", - "status": "string", - "limit": 0, - "due_to": 0, - "time_of_passing": 0, - "pausable": true, - "version": 0, - "version_comment": "string", - "created_at": "string", - "updated_at": "string", - "question_cnt": 0, - "passed_count": 0, - "average_time": 0, - "super": true, - "group_id": 0 - }) + navigate(`/create-quize/${createBlank()}`); }} >Создать + diff --git a/src/pages/startPage/stepOne.tsx b/src/pages/startPage/stepOne.tsx index e981192e..52ed8f87 100755 --- a/src/pages/startPage/stepOne.tsx +++ b/src/pages/startPage/stepOne.tsx @@ -2,6 +2,8 @@ import { Box, Button, Typography, useTheme } from "@mui/material"; import CreationCard from "@ui_kit/CreationCard"; import quizCreationImage1 from "../../assets/quiz-creation-1.png"; import quizCreationImage2 from "../../assets/quiz-creation-2.png"; +import {useParams} from "react-router-dom"; +import {quizStore} from "@root/quizes"; interface HandleNext { handleNext: () => void; @@ -9,6 +11,10 @@ interface HandleNext { export default function StepOne({ handleNext }: HandleNext) { const theme = useTheme(); + const params = Number(useParams().quizId); + console.log(params) + const {listQuizes, updateQuizesList, removeQuiz, createBlank} = quizStore() + console.log(listQuizes) return ( <> - - diff --git a/src/stores/quizes.ts b/src/stores/quizes.ts index 453e8bf2..e639e26c 100644 --- a/src/stores/quizes.ts +++ b/src/stores/quizes.ts @@ -3,8 +3,9 @@ import { persist } from "zustand/middleware"; interface QuizStore { listQuizes: {[key: number]: Quizes}; - updateQuizesList: (newQuiz: Quizes) => void; + updateQuizesList: (id: number, values: unknown) => void; removeQuiz:(id: number) => void; + createBlank: () => void; } interface Quizes { @@ -69,13 +70,13 @@ export const quizStore = create()( // "group_id": 0 // } }, - updateQuizesList: (newQuiz) => { + updateQuizesList: (id: number, values: any) => { const state = get()["listQuizes"] || {}; - const newState = { - ...state, - [newQuiz["id"]]: newQuiz + state[id] = { + ...state[id], + ...values }; - set({listQuizes:newState}); + set({listQuizes:state}); }, removeQuiz: (id) => { const state = get()["listQuizes"] || {}; @@ -87,7 +88,41 @@ export const quizStore = create()( return accumulator; }, {}); set({listQuizes:newState}); - } + }, + createBlank: () => { + const id = getRandom(1000000, 10000000) + const newListQuizes = get()["listQuizes"] || {}; + newListQuizes[id] = { + "id": id, + "qid": "", + "deleted": false, + "archived": true, + "fingerprinting": true, + "repeatable": true, + "note_prevented": true, + "mail_notifications": true, + "unique_answers": true, + "name": "", + "description": "", + "config": "", + "status": "", + "limit": 0, + "due_to": 0, + "time_of_passing": 0, + "pausable": true, + "version": 0, + "version_comment": "", + "created_at": "", + "updated_at": "", + "question_cnt": 0, + "passed_count": 0, + "average_time": 0, + "super": true, + "group_id": 0 + }; + set({listQuizes:newListQuizes}); + return id; + }, }), { name: "quizes", @@ -95,3 +130,8 @@ export const quizStore = create()( ) ); +function getRandom(min: number, max:number) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; +} \ No newline at end of file diff --git a/src/ui_kit/CreationCard.tsx b/src/ui_kit/CreationCard.tsx index 951f857e..a5f39eba 100755 --- a/src/ui_kit/CreationCard.tsx +++ b/src/ui_kit/CreationCard.tsx @@ -5,15 +5,17 @@ interface Props { header: string; text: string; image: any; + border?: string } -export default function CreationCard({ header, text, image }: Props) { +export default function CreationCard({ header, text, image, border}: Props) { return (