стор квизов и его HC функции
This commit is contained in:
parent
e2863bfee8
commit
d6570ccae9
@ -10,8 +10,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function MyQuizzesFull({outerContainerSx: sx, children}: Props) {
|
||||
const store = quizStore.getState()
|
||||
console.log(Object.values(store))
|
||||
const {listQuizes, updateQuizesList, removeQuiz} = quizStore()
|
||||
|
||||
return (
|
||||
<SectionWrapper
|
||||
maxWidth="lg"
|
||||
@ -20,6 +20,43 @@ export default function MyQuizzesFull({outerContainerSx: sx, children}: Props) {
|
||||
mb: "70px",
|
||||
}}
|
||||
>
|
||||
<Button onClick={() => {
|
||||
removeQuiz(2)
|
||||
console.log(Object.values(listQuizes))
|
||||
}}>УДАЛИ МЕНЯ</Button>
|
||||
<Button onClick={() => {
|
||||
console.log(Object.values(listQuizes))
|
||||
}}>Узнай МЕНЯ</Button>
|
||||
<Button onClick={() => {
|
||||
updateQuizesList({
|
||||
"id": 2,
|
||||
"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
|
||||
})
|
||||
}}>добавь МЕНЯ</Button>
|
||||
<ComplexNavText text1="Кабинет квизов"/>
|
||||
<Box
|
||||
sx={{
|
||||
@ -44,7 +81,7 @@ export default function MyQuizzesFull({outerContainerSx: sx, children}: Props) {
|
||||
mb: "60px",
|
||||
}}
|
||||
>
|
||||
{Object.values(store).map((e, i) =>(
|
||||
{Object.values(listQuizes).map((e, i) =>(
|
||||
<QuizCard name={e.name} openCount={0} applicationCount={0} conversionPercent={0}/>
|
||||
)
|
||||
)}
|
||||
|
@ -2,8 +2,9 @@ import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
|
||||
interface QuizStore {
|
||||
[key: number]: Quizes;
|
||||
|
||||
listQuizes: {[key: number]: Quizes};
|
||||
updateQuizesList: (newQuiz: Quizes) => void;
|
||||
removeQuiz:(id: number) => void;
|
||||
}
|
||||
|
||||
interface Quizes {
|
||||
@ -15,7 +16,7 @@ interface Quizes {
|
||||
repeatable: boolean,
|
||||
note_prevented: boolean,
|
||||
mail_notifications: boolean,
|
||||
"unique_answers": boolean,
|
||||
unique_answers: boolean,
|
||||
name: string,
|
||||
description: string,
|
||||
config: string,
|
||||
@ -38,6 +39,7 @@ interface Quizes {
|
||||
export const quizStore = create<QuizStore>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
listQuizes: {
|
||||
1: {
|
||||
"id": 0,
|
||||
"qid": "string",
|
||||
@ -66,22 +68,29 @@ export const quizStore = create<QuizStore>()(
|
||||
"super": true,
|
||||
"group_id": 0
|
||||
}
|
||||
},
|
||||
updateQuizesList: (newQuiz) => {
|
||||
const state = get()["listQuizes"] || {};
|
||||
const newState = {
|
||||
...state,
|
||||
[newQuiz["id"]]: newQuiz
|
||||
};
|
||||
set({listQuizes:newState});
|
||||
},
|
||||
removeQuiz: (id) => {
|
||||
const state = get()["listQuizes"] || {};
|
||||
|
||||
const newState = Object.entries(state).reduce<any>((accumulator, [key, value], index, array) => {
|
||||
if (key !== id.toString()) {
|
||||
accumulator[key] = value;
|
||||
}
|
||||
return accumulator;
|
||||
}, {});
|
||||
set({listQuizes:newState});
|
||||
}
|
||||
}),
|
||||
{
|
||||
name: "quizes",
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// export const Update = (newQuiz: Quizes) => {
|
||||
//
|
||||
// const state = quizStore.getState();
|
||||
// if (typeof state[newQuiz.id] !== "undefined") {
|
||||
// //ключ есть
|
||||
// }else{
|
||||
// quizStore.setState(state => {newQuiz.id: newQuiz})
|
||||
// }
|
||||
// quizStore.setState({
|
||||
//
|
||||
// });
|
||||
// }
|
Loading…
Reference in New Issue
Block a user