2020-11-21 04:02:38 +01:00
|
|
|
import { courseStartTimeToEventRow } from '../constants/index';
|
|
|
|
import { SchedulerEvent } from '../types';
|
|
|
|
|
2020-12-29 01:06:39 +01:00
|
|
|
|
2020-11-21 04:02:38 +01:00
|
|
|
|
|
|
|
export const selectGroupsToShow = (schedulerEvents: Array<SchedulerEvent>, index: number) => {
|
2020-12-29 01:06:39 +01:00
|
|
|
return schedulerEvents.filter((schedulerEvent) => courseStartTimeToEventRow[schedulerEvent.time] === index);
|
2020-11-21 04:02:38 +01:00
|
|
|
};
|
|
|
|
|
2020-12-12 17:54:13 +01:00
|
|
|
//debounce declaration and implementation
|
2020-11-21 04:02:38 +01:00
|
|
|
type Procedure = (...args: any[]) => any;
|
|
|
|
|
|
|
|
interface Debounce {
|
|
|
|
(...args: any[]): any;
|
|
|
|
clear: () => void;
|
|
|
|
flush: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const debounce = (func: Procedure, wait: number, immediate: boolean = false) => {
|
|
|
|
let timeout: number | null;
|
|
|
|
let args: any;
|
|
|
|
let context: any;
|
|
|
|
let result: any;
|
|
|
|
|
|
|
|
const later = () => {
|
|
|
|
timeout = null;
|
|
|
|
if (!immediate) {
|
|
|
|
result = func.apply(context, args);
|
|
|
|
context = args = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const debouncedFunc: Procedure = function (this: any) {
|
|
|
|
context = this;
|
|
|
|
args = arguments;
|
|
|
|
const callNow = immediate && !timeout;
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
timeout = window.setTimeout(later, wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callNow) {
|
|
|
|
result = func.apply(context, args);
|
|
|
|
context = args = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
const clear = () => {
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const flush = () => {
|
|
|
|
if (timeout) {
|
|
|
|
result = func.apply(context, args);
|
|
|
|
context = args = null;
|
|
|
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const debounced: Debounce = (() => {
|
|
|
|
const f: any = debouncedFunc;
|
|
|
|
f.clear = clear;
|
|
|
|
f.flush = flush;
|
|
|
|
return f;
|
|
|
|
})();
|
|
|
|
|
|
|
|
return debounced;
|
|
|
|
};
|