docs: add jsdoc
This commit is contained in:
@@ -24,7 +24,11 @@ import { useAtom } from "jotai";
|
|||||||
import { API_BASE_URL } from "../App";
|
import { API_BASE_URL } from "../App";
|
||||||
import { copyDXLink, ifstyle } from "../trash/helpers";
|
import { copyDXLink, ifstyle } from "../trash/helpers";
|
||||||
import { useWebHaptics } from "web-haptics/react";
|
import { useWebHaptics } from "web-haptics/react";
|
||||||
|
import { DengiCaching } from "../trash/dengiCashingSystem";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{classIDAtom,adminAtom,setsetRoute,routeAtom,pickmeModeAtom,dengi_cash: DengiCaching}} param0
|
||||||
|
*/
|
||||||
export function DX4App({
|
export function DX4App({
|
||||||
classIDAtom,
|
classIDAtom,
|
||||||
adminAtom,
|
adminAtom,
|
||||||
@@ -154,6 +158,9 @@ export function DX4App({
|
|||||||
})();
|
})();
|
||||||
}, [classId, adminId]);
|
}, [classId, adminId]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
const handleKeyPress = (event) => {
|
const handleKeyPress = (event) => {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "a":
|
case "a":
|
||||||
|
|||||||
+36
-6
@@ -29,6 +29,9 @@ export const dateTagsList = {
|
|||||||
afterTomorrow: "послезавтра",
|
afterTomorrow: "послезавтра",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Date} date
|
||||||
|
*/
|
||||||
export function getDateTags(date) {
|
export function getDateTags(date) {
|
||||||
const x = new Date();
|
const x = new Date();
|
||||||
x.setHours(0, 0, 0, 0);
|
x.setHours(0, 0, 0, 0);
|
||||||
@@ -45,11 +48,16 @@ export function getDateTags(date) {
|
|||||||
? dateTagsList["afterTomorrow"]
|
? dateTagsList["afterTomorrow"]
|
||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Converts day of the week with 0 - sunday, to 0 - monday
|
||||||
|
* @param {number} usDay
|
||||||
|
*/
|
||||||
export function usToRussianDay(usDay) {
|
export function usToRussianDay(usDay) {
|
||||||
return (usDay + 6) % 7;
|
return (usDay + 6) % 7;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {Date} date
|
||||||
|
*/
|
||||||
export function formatDate(date) {
|
export function formatDate(date) {
|
||||||
return `${
|
return `${
|
||||||
dayOfWeeksNames[usToRussianDay(date.getDay())]
|
dayOfWeeksNames[usToRussianDay(date.getDay())]
|
||||||
@@ -59,6 +67,9 @@ export function formatDate(date) {
|
|||||||
: ""
|
: ""
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {Date} date
|
||||||
|
*/
|
||||||
export function apiFormatDate(date) {
|
export function apiFormatDate(date) {
|
||||||
return (
|
return (
|
||||||
("0" + date.getDate()).slice(-2) +
|
("0" + date.getDate()).slice(-2) +
|
||||||
@@ -68,6 +79,9 @@ export function apiFormatDate(date) {
|
|||||||
String(date.getFullYear()).slice(-2)
|
String(date.getFullYear()).slice(-2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {string} s
|
||||||
|
*/
|
||||||
export const parseApiDate = (s) => {
|
export const parseApiDate = (s) => {
|
||||||
const [d, m, y] = s.split("-").map(Number);
|
const [d, m, y] = s.split("-").map(Number);
|
||||||
const yy = 2000 + y;
|
const yy = 2000 + y;
|
||||||
@@ -83,6 +97,11 @@ export const apiToEditorVocabluary = {
|
|||||||
"t-end": "time2",
|
"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) {
|
export function convertApiToEditor(arr) {
|
||||||
let uuid = Math.floor(Math.random() * 10000);
|
let uuid = Math.floor(Math.random() * 10000);
|
||||||
return arr.map((item) => {
|
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) {
|
export function convertEditorToApi(arr) {
|
||||||
const editorToApi = Object.fromEntries(
|
const editorToApi = Object.fromEntries(
|
||||||
Object.entries(apiToEditorVocabluary).map(([apiKey, editorKey]) => [
|
Object.entries(apiToEditorVocabluary).map(([apiKey, editorKey]) => [
|
||||||
editorKey,
|
editorKey,
|
||||||
apiKey,
|
apiKey,
|
||||||
])
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
return arr.reduce((acc, item) => {
|
return arr.reduce((acc, item) => {
|
||||||
@@ -130,7 +154,10 @@ export function convertEditorToApi(arr) {
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Checks if time string (HH:MM) before now
|
||||||
|
* @param {string} timeStr
|
||||||
|
*/
|
||||||
export function isTimeBeforeNow(timeStr) {
|
export function isTimeBeforeNow(timeStr) {
|
||||||
const [h, m] = timeStr.split(":").map(Number);
|
const [h, m] = timeStr.split(":").map(Number);
|
||||||
if (!Number.isFinite(h) || !Number.isFinite(m)) return false;
|
if (!Number.isFinite(h) || !Number.isFinite(m)) return false;
|
||||||
@@ -142,7 +169,7 @@ export function isTimeBeforeNow(timeStr) {
|
|||||||
h,
|
h,
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
0
|
0,
|
||||||
);
|
);
|
||||||
return t.getTime() < now.getTime();
|
return t.getTime() < now.getTime();
|
||||||
}
|
}
|
||||||
@@ -161,4 +188,7 @@ export const AvailableSymbols = (() => {
|
|||||||
return (a + n + A + s).split("");
|
return (a + n + A + s).split("");
|
||||||
})();
|
})();
|
||||||
|
|
||||||
export const AvailableAdminSymbols = [...AvailableSymbols, ..."$()*^%@!+=.".split("")];
|
export const AvailableAdminSymbols = [
|
||||||
|
...AvailableSymbols,
|
||||||
|
..."$()*^%@!+=.".split(""),
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
export class DengiCaching {
|
export class DengiCaching {
|
||||||
vals = [
|
/**
|
||||||
/*
|
* @type {{name: string, value: any, expires: Date}[]}
|
||||||
{
|
|
||||||
name:"unique-id-name",
|
|
||||||
value:"somevalue",
|
|
||||||
expires=Date
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
];
|
vals = [];
|
||||||
constructor() {}
|
constructor() {}
|
||||||
tick() {
|
tick() {
|
||||||
this.vals.map((element, index) => {
|
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) {
|
withCache(name, ifNotFound) {
|
||||||
this.tick();
|
this.tick();
|
||||||
let a = this.get(name);
|
let a = this.get(name);
|
||||||
@@ -29,6 +28,10 @@ export class DengiCaching {
|
|||||||
return a;
|
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) {
|
async withCacheAsync(name, ifNotFound) {
|
||||||
this.tick();
|
this.tick();
|
||||||
let a = this.get(name);
|
let a = this.get(name);
|
||||||
@@ -40,6 +43,10 @@ export class DengiCaching {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {...string} names
|
||||||
|
*/
|
||||||
delete(...names) {
|
delete(...names) {
|
||||||
names.forEach((name) => {
|
names.forEach((name) => {
|
||||||
var index = this.vals.findIndex((a) => a.name == name);
|
var index = this.vals.findIndex((a) => a.name == name);
|
||||||
@@ -52,15 +59,25 @@ export class DengiCaching {
|
|||||||
fullClear() {
|
fullClear() {
|
||||||
this.vals = [];
|
this.vals = [];
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
wasCached(name) {
|
wasCached(name) {
|
||||||
this.tick();
|
this.tick();
|
||||||
return this.vals.find((a) => a.name == name) !== undefined;
|
return this.vals.find((a) => a.name == name) !== undefined;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
get(name) {
|
get(name) {
|
||||||
this.tick();
|
this.tick();
|
||||||
const item = this.vals.find((a) => a.name === name);
|
const item = this.vals.find((a) => a.name === name);
|
||||||
return item ? item.value : undefined;
|
return item ? item.value : undefined;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
* @param {any} val
|
||||||
|
*/
|
||||||
cache(name, val) {
|
cache(name, val) {
|
||||||
this.tick();
|
this.tick();
|
||||||
this.vals.push({
|
this.vals.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user