add type annotations, improve ui

This commit is contained in:
marlon-erler
2026-04-13 11:23:17 +00:00
parent 537592fae9
commit 6dff4a74eb
21 changed files with 100 additions and 57 deletions
+20 -8
View File
@@ -34,9 +34,14 @@ export default class CoreViewModel {
this.logContexts();
}
closeContext = (contextId: string): void => {
if (!this.contexts.map(context=>context.contextId).includes(contextId)) return;
if (
!this.contexts
.map((context) => context.contextId)
.includes(contextId)
)
return;
while (this.contexts.length > 0) {
const currentContext = this.context;
const currentContext: Context = this.context;
this.contextStack.delete(currentContext.contextId);
if (currentContext.contextId == contextId) break;
}
@@ -44,9 +49,10 @@ export default class CoreViewModel {
};
handleKeyDown = (e: KeyboardEvent): void => {
const contexts = this.contexts;
if (CoreViewModel.checkIsKeystroke(e) == false) return;
const contexts: Context[] = this.contexts;
while (contexts.length > 0) {
const currentContext = contexts.pop();
const currentContext: Context | undefined = contexts.pop();
if (!currentContext) contexts;
const isHandled: boolean = currentContext.handleKeystroke(e);
if (isHandled == true) break;
@@ -90,7 +96,9 @@ export class Context {
keystrokes = new Map<string, () => void>();
handleKeystroke = (e: KeyboardEvent): boolean => {
const fn = this.keystrokes.get(e.key.toLowerCase());
const fn: (() => void) | undefined = this.keystrokes.get(
e.key.toLowerCase(),
);
if (!fn) return false;
e.preventDefault();
fn();
@@ -122,7 +130,9 @@ export class ContextHost<T> extends Context {
closeContext = (): void => {
if (this.currentContext.value) {
this.coreViewModel.closeContext(this.currentContext.value.contextId);
this.coreViewModel.closeContext(
this.currentContext.value.contextId,
);
}
this.currentContext.value = undefined;
};
@@ -130,11 +140,13 @@ export class ContextHost<T> extends Context {
updateContexts = (): void => {
if (this.isOpen == false) return;
const selectedContext = this.contexts.get(this.contextSelection);
const selectedContext: Context | undefined = this.contexts.get(
this.contextSelection,
);
if (!selectedContext) return;
if (selectedContext != this.currentContext.value) {
this.closeContext();
};
}
this.coreViewModel.logContexts();
@@ -13,7 +13,8 @@ export default class NotificationViewModel {
// main
showNotification = (message: ChatMessage): void => {
const notification = NotificationViewModel.createNotification(message);
const notification: Notification =
NotificationViewModel.createNotification(message);
if (this.seenMessageIds.has(message.id)) return;
const currentChat =
@@ -32,7 +33,7 @@ export default class NotificationViewModel {
};
openNotification = () => {
const notification = this.marquee.value;
const notification: Notification = this.marquee.value;
if (notification == undefined) return;
const chat = [
@@ -51,7 +52,7 @@ export default class NotificationViewModel {
return this.stopLoop();
}
const notification = this.messagesInMarquee.shift();
const notification: Notification = this.messagesInMarquee.shift();
this.seenMessageIds.delete(notification.messageId);
this.marquee.value = notification;
};
+5 -2
View File
@@ -64,7 +64,7 @@ export default class SettingsViewModel extends Context {
// view
applyTheme = (): void => {
let theme = this.theme.value;
let theme: string = this.theme.value;
if (theme == ThemeSettings.System) {
theme = SettingsViewModel.getSystemTheme();
}
@@ -100,7 +100,10 @@ export default class SettingsViewModel extends Context {
);
// keystrokes
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.hideSettingsModal);
this.registerKeyStroke(
CommonKeys.CloseOrCancel,
this.hideSettingsModal,
);
}
static generateThemeMedia(): MediaQueryList {
+4 -3
View File
@@ -24,10 +24,11 @@ export default class StorageViewModel extends Context {
// methods
getSelectedItemContent = (): string => {
const path = StorageModel.stringToPathComponents(
const path: string[] = StorageModel.stringToPathComponents(
this.selectedPath.value,
);
const content = this.coreViewModel.storageModel.read(path);
const content: string | undefined =
this.coreViewModel.storageModel.read(path);
return (
(content ?? this.coreViewModel.translations.storage.notAFile) ||
this.coreViewModel.translations.storage.contentEmpty
@@ -35,7 +36,7 @@ export default class StorageViewModel extends Context {
};
deleteSelectedItem = (): void => {
const path = StorageModel.stringToPathComponents(
const path: string[] = StorageModel.stringToPathComponents(
this.selectedPath.value,
);
this.lastDeletedItemPath.value = this.selectedPath.value;