frontPanel/src/stores/quizes.ts

87 lines
2.2 KiB
TypeScript
Raw Normal View History

import { create } from "zustand";
import { persist } from "zustand/middleware";
interface QuizStore {
[key: number]: Quizes;
}
interface Quizes {
id: number,
qid: string,
deleted: boolean,
archived: boolean,
fingerprinting: boolean,
repeatable: boolean,
note_prevented: boolean,
mail_notifications: boolean,
"unique_answers": boolean,
name: string,
description: string,
config: string,
status: string,
limit: number,
due_to: number,
time_of_passing: number,
pausable: boolean,
version: number,
version_comment: string,
created_at: string,
updated_at: string,
question_cnt: number,
passed_count: number,
average_time: number,
super: true,
group_id: number
}
export const quizStore = create<QuizStore>()(
persist(
(set, get) => ({
1: {
"id": 0,
"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
}
}),
{
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({
//
// });
// }