docs: add jsdoc

This commit is contained in:
2026-08-28 17:06:07 +03:00
parent 26fd295692
commit 648b106fca
3 changed files with 75 additions and 21 deletions
+7
View File
@@ -24,7 +24,11 @@ import { useAtom } from "jotai";
import { API_BASE_URL } from "../App";
import { copyDXLink, ifstyle } from "../trash/helpers";
import { useWebHaptics } from "web-haptics/react";
import { DengiCaching } from "../trash/dengiCashingSystem";
/**
* @param {{classIDAtom,adminAtom,setsetRoute,routeAtom,pickmeModeAtom,dengi_cash: DengiCaching}} param0
*/
export function DX4App({
classIDAtom,
adminAtom,
@@ -154,6 +158,9 @@ export function DX4App({
})();
}, [classId, adminId]);
/**
* @param {KeyboardEvent} event
*/
const handleKeyPress = (event) => {
switch (event.key) {
case "a":
+42 -12
View File
@@ -29,6 +29,9 @@ export const dateTagsList = {
afterTomorrow: "послезавтра",
};
/**
* @param {Date} date
*/
export function getDateTags(date) {
const x = new Date();
x.setHours(0, 0, 0, 0);
@@ -38,18 +41,23 @@ export function getDateTags(date) {
return diff === 0
? dateTagsList["today"]
: diff === -1
? dateTagsList["yesterday"]
: diff === 1
? dateTagsList["tomorrow"]
: diff === 2
? dateTagsList["afterTomorrow"]
: "";
? dateTagsList["yesterday"]
: diff === 1
? dateTagsList["tomorrow"]
: diff === 2
? dateTagsList["afterTomorrow"]
: "";
}
/**
* Converts day of the week with 0 - sunday, to 0 - monday
* @param {number} usDay
*/
export function usToRussianDay(usDay) {
return (usDay + 6) % 7;
}
/**
* @param {Date} date
*/
export function formatDate(date) {
return `${
dayOfWeeksNames[usToRussianDay(date.getDay())]
@@ -59,6 +67,9 @@ export function formatDate(date) {
: ""
}`;
}
/**
* @param {Date} date
*/
export function apiFormatDate(date) {
return (
("0" + date.getDate()).slice(-2) +
@@ -68,6 +79,9 @@ export function apiFormatDate(date) {
String(date.getFullYear()).slice(-2)
);
}
/**
* @param {string} s
*/
export const parseApiDate = (s) => {
const [d, m, y] = s.split("-").map(Number);
const yy = 2000 + y;
@@ -83,6 +97,11 @@ export const apiToEditorVocabluary = {
"t-end": "time2",
};
/**
* Converts api schedule data to editor format
* @param {{num: string|number; cabinet: string|number, subject: string, "t-begin": string, "t-end": string}[]} arr
* @returns {{position: string|number; room: string|number; subject: string, time1: string, time2: string}[]}
*/
export function convertApiToEditor(arr) {
let uuid = Math.floor(Math.random() * 10000);
return arr.map((item) => {
@@ -98,12 +117,17 @@ export function convertApiToEditor(arr) {
});
}
/**
* Converts editor schedule data to api format
* @param {{position: string|number; room: string|number; subject: string, time1: string, time2: string}[]} arr
* @returns {{num: string|number; cabinet: string|number, subject: string, "t-begin": string, "t-end": string}[]}
*/
export function convertEditorToApi(arr) {
const editorToApi = Object.fromEntries(
Object.entries(apiToEditorVocabluary).map(([apiKey, editorKey]) => [
editorKey,
apiKey,
])
]),
);
return arr.reduce((acc, item) => {
@@ -130,7 +154,10 @@ export function convertEditorToApi(arr) {
return acc;
}, []);
}
/**
* Checks if time string (HH:MM) before now
* @param {string} timeStr
*/
export function isTimeBeforeNow(timeStr) {
const [h, m] = timeStr.split(":").map(Number);
if (!Number.isFinite(h) || !Number.isFinite(m)) return false;
@@ -142,7 +169,7 @@ export function isTimeBeforeNow(timeStr) {
h,
m,
0,
0
0,
);
return t.getTime() < now.getTime();
}
@@ -161,4 +188,7 @@ export const AvailableSymbols = (() => {
return (a + n + A + s).split("");
})();
export const AvailableAdminSymbols = [...AvailableSymbols, ..."$()*^%@!+=.".split("")];
export const AvailableAdminSymbols = [
...AvailableSymbols,
..."$()*^%@!+=.".split(""),
];
+26 -9
View File
@@ -1,13 +1,8 @@
export class DengiCaching {
vals = [
/*
{
name:"unique-id-name",
value:"somevalue",
expires=Date
}
*/
];
/**
* @type {{name: string, value: any, expires: Date}[]}
*/
vals = [];
constructor() {}
tick() {
this.vals.map((element, index) => {
@@ -18,6 +13,10 @@ export class DengiCaching {
}
});
}
/**
* @param {string} name
* @param {()=>any} ifNotFound - function, would be called if value not found, returned value vould be stored
*/
withCache(name, ifNotFound) {
this.tick();
let a = this.get(name);
@@ -29,6 +28,10 @@ export class DengiCaching {
return a;
}
}
/**
* @param {string} name
* @param {()=>any} ifNotFound - function, would be called if value not found, returned value vould be stored
*/
async withCacheAsync(name, ifNotFound) {
this.tick();
let a = this.get(name);
@@ -40,6 +43,10 @@ export class DengiCaching {
return a;
}
}
/**
*
* @param {...string} names
*/
delete(...names) {
names.forEach((name) => {
var index = this.vals.findIndex((a) => a.name == name);
@@ -52,15 +59,25 @@ export class DengiCaching {
fullClear() {
this.vals = [];
}
/**
* @param {string} name
*/
wasCached(name) {
this.tick();
return this.vals.find((a) => a.name == name) !== undefined;
}
/**
* @param {string} name
*/
get(name) {
this.tick();
const item = this.vals.find((a) => a.name === name);
return item ? item.value : undefined;
}
/**
* @param {string} name
* @param {any} val
*/
cache(name, val) {
this.tick();
this.vals.push({