diff --git a/src/Model/Utility/utility.ts b/src/Model/Utility/utility.ts index 3fa99275..2cc93fdb 100644 --- a/src/Model/Utility/utility.ts +++ b/src/Model/Utility/utility.ts @@ -18,6 +18,11 @@ export function createTimestamp(): string { return new Date().toISOString(); } +export function formatTime(date: Date): string { + const time = [date.getHours(), date.getMinutes()]; + return time.join(":"); +} + // filters export type StringEntryObject = { [key: string]: Stringifiable | undefined }; @@ -29,11 +34,11 @@ export function filterObjectsByStringEntries( const matches: Set = new Set(); for (const object of objects) { - const doesMatch: boolean = checkDoesObjectMatchReference( - reference, - converter(object), - ); - if (doesMatch) matches.add(object); + const doesMatch: boolean = checkDoesObjectMatchReference( + reference, + converter(object), + ); + if (doesMatch) matches.add(object); } return matches; @@ -47,12 +52,12 @@ export function filterObjectsByWords( const matches: Set = new Set(); for (const object of objects) { - const doesMatch: boolean = checkDoesObjectMatchSearch( - query, - getStringsOfObject, - object, - ); - if (doesMatch) matches.add(object); + const doesMatch: boolean = checkDoesObjectMatchSearch( + query, + getStringsOfObject, + object, + ); + if (doesMatch) matches.add(object); } return matches; @@ -68,30 +73,30 @@ export function checkDoesObjectMatchSearch( const stringsInObject: string[] = getStringsOfObject(object); const wordsInObject: string[] = []; for (const string of stringsInObject) { - const lowercaseWordsInString = string - .toString() - .toLowerCase() - .split(" ") - .filter((word) => word != ""); - wordsInObject.push(...lowercaseWordsInString); + const lowercaseWordsInString = string + .toString() + .toLowerCase() + .split(" ") + .filter((word) => word != ""); + wordsInObject.push(...lowercaseWordsInString); } const lowercaseWordsInQuery = query - .toLowerCase() - .split(" ") - .filter((word) => word != ""); + .toLowerCase() + .split(" ") + .filter((word) => word != ""); for (const queryWord of lowercaseWordsInQuery) { - if (queryWord[0] == "-") { - // exclusion - const wordContent = queryWord.substring(1); - if (wordsInObject.includes(wordContent)) { - return false; - } - } else { - if (wordsInObject.includes(queryWord) == false) { - return false; - } - } + if (queryWord[0] == "-") { + // exclusion + const wordContent = queryWord.substring(1); + if (wordsInObject.includes(wordContent)) { + return false; + } + } else { + if (wordsInObject.includes(queryWord) == false) { + return false; + } + } } return true; @@ -104,14 +109,14 @@ export default function implementFilter( itemToString: (item: T) => string, ) { function update() { - matches.clear(); - allItems.value.forEach((item: T) => { - if (!itemToString(item).toLowerCase().includes(query.value.toLowerCase())) return; - matches.add(item); - allItems.handleRemoval(item, () => { - matches.remove(item); - }); - }); + matches.clear(); + allItems.value.forEach((item: T) => { + if (!itemToString(item).toLowerCase().includes(query.value.toLowerCase())) return; + matches.add(item); + allItems.handleRemoval(item, () => { + matches.remove(item); + }); + }); } query.subscribe(update); allItems.handleAddition(update); @@ -125,16 +130,16 @@ export class HandlerManager { // manage setHandler = (id: string, handler: Handler): void => { - this.handlers.set(id, handler); + this.handlers.set(id, handler); }; deleteHandler = (id: string): void => { - this.handlers.delete(id); + this.handlers.delete(id); }; // trigger trigger = (item: T): void => { - [...this.handlers.values()].forEach((handler) => handler(item)); + [...this.handlers.values()].forEach((handler) => handler(item)); }; } @@ -146,26 +151,26 @@ export class IndexManager { // methods update = (items: T[]): void => { - this.sortedStrings = []; + this.sortedStrings = []; - let strings: string[] = []; - for (const item of items) { - const string: string = this.itemToString(item); - strings.push(string); - } + let strings: string[] = []; + for (const item of items) { + const string: string = this.itemToString(item); + strings.push(string); + } - this.sortedStrings = strings.sort(localeCompare); + this.sortedStrings = strings.sort(localeCompare); }; getIndex = (item: T): number => { - const string: string = this.itemToString(item); - const index: number = this.sortedStrings.indexOf(string); - return index; + const string: string = this.itemToString(item); + const index: number = this.sortedStrings.indexOf(string); + return index; }; // init constructor(itemToString: (item: T) => string) { - this.itemToString = itemToString; + this.itemToString = itemToString; } } @@ -192,9 +197,9 @@ export function padZero(string: string | undefined, length: number): string { export function parse(string: string): any { try { - return JSON.parse(string); + return JSON.parse(string); } catch { - return {}; + return {}; } } @@ -203,8 +208,8 @@ export function parseValidObject(string: string, reference: T): T | null { if (checkIsValidObject(parsed) == false) return null; const doesMatchReference: boolean = checkMatchesObjectStructure( - parsed, - reference, + parsed, + reference, ); if (doesMatchReference == false) return null; @@ -213,9 +218,9 @@ export function parseValidObject(string: string, reference: T): T | null { export function parseOrFallback(inputString: string): any { try { - return JSON.parse(inputString); + return JSON.parse(inputString); } catch { - return inputString; + return inputString; } } diff --git a/src/ViewModel/Global/.settingsViewModel.ts.swp b/src/ViewModel/Global/.settingsViewModel.ts.swp deleted file mode 100644 index a515b1c5..00000000 Binary files a/src/ViewModel/Global/.settingsViewModel.ts.swp and /dev/null differ diff --git a/src/ViewModel/Global/coreViewModel.ts b/src/ViewModel/Global/coreViewModel.ts index 4dc87a6c..df12dc57 100644 --- a/src/ViewModel/Global/coreViewModel.ts +++ b/src/ViewModel/Global/coreViewModel.ts @@ -1,7 +1,7 @@ import { v4 } from "uuid"; import * as React from "../../react"; import { allTranslations, Translations } from "../../View/translations"; -import { HandlerManager } from "../../Model/Utility/utility"; +import { formatTime, HandlerManager } from "../../Model/Utility/utility"; import StorageModel from "../../Model/Global/storageModel"; import SettingsModel from "../../Model/Global/settingsModel"; import FileTransferModel from "../../Model/Global/fileTransferModel"; @@ -73,19 +73,24 @@ export default class CoreViewModel { // CHRON chronHandlerManager = new HandlerManager(); todayDate = new React.State(new Date()); - get unwrappedTodayDate() { + time = new React.State<[number, number]>([0, 0]); + get unwrappedTodayDate(): Date { return new Date(this.todayDate.value); } + get timeString(): string { + return this.time.value.join(":"); + } startChron = (): void => { setInterval(this.chronHandlerManager.trigger, 2000); }; handleChron = (): void => { - const newDate = new Date(); - if (this.unwrappedTodayDate.toDateString() == newDate.toDateString()) - return; - this.todayDate.value = new Date(); + const newDate = new Date(); + if (this.unwrappedTodayDate.toDateString() != newDate.toDateString()) + this.todayDate.value = new Date(); + if (formatTime(newDate) != this.timeString) + this.time.value = [newDate.getHours(), newDate.getMinutes()]; }; // DRAG & DROP