add type annotations, improve ui
This commit is contained in:
@@ -88,7 +88,8 @@ export default class ChatListViewModel {
|
||||
loadChats = (): void => {
|
||||
this.chatViewModels.clear();
|
||||
for (const chatModel of this.coreViewModel.chatListModel.chatModels.values()) {
|
||||
const chatViewModel = this.createChatViewModel(chatModel);
|
||||
const chatViewModel: ChatViewModel =
|
||||
this.createChatViewModel(chatModel);
|
||||
this.trackChat(chatViewModel);
|
||||
}
|
||||
this.updateIndices();
|
||||
|
||||
@@ -138,7 +138,7 @@ export default class ChatMessageViewModel {
|
||||
return;
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
let count: number = 0;
|
||||
switch (content) {
|
||||
case ReactionSymbols.ThumbsUp: {
|
||||
count = this.reactionsThumbsUpCount.value;
|
||||
|
||||
@@ -210,7 +210,9 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
|
||||
);
|
||||
|
||||
// context
|
||||
this.chatListViewModel.selectedChat.subscribeSilent(this.updateContexts);
|
||||
this.chatListViewModel.selectedChat.subscribeSilent(
|
||||
this.updateContexts,
|
||||
);
|
||||
this.selectedPage.subscribeSilent(this.updateContexts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -65,6 +65,8 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
||||
this.color.value,
|
||||
);
|
||||
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
|
||||
|
||||
this.taskPageViewModel.selectBoard(this);
|
||||
};
|
||||
|
||||
applyColor = (): void => {
|
||||
@@ -305,8 +307,10 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
||||
|
||||
// keystrokes
|
||||
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.hideFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.Reset, this.resetFilter);
|
||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.hideFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.Settings, this.showSettings);
|
||||
this.registerKeyStroke(CommonKeys.Apply, this.hideSettings);
|
||||
|
||||
this.taskPageViewModel.registerContext(this.boardInfo.fileId, this);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export default class TaskPageViewModel extends ContextHost<string> {
|
||||
getBasePath = (): string[] => {
|
||||
return [...this.boardsAndTasksModel.getViewPath()];
|
||||
};
|
||||
getBoardViewPath = (boardId): string[] => {
|
||||
getBoardViewPath = (boardId: string): string[] => {
|
||||
return [...this.getBasePath(), boardId];
|
||||
};
|
||||
getLastUsedBoardPath = (): string[] => {
|
||||
|
||||
@@ -18,16 +18,16 @@ export default class TaskViewModel extends Context {
|
||||
// util
|
||||
get sortingString(): string {
|
||||
const splitDate: string[] = this.date.value.split("-");
|
||||
const year = padZero(splitDate[0], 4);
|
||||
const month = padZero(splitDate[1], 2);
|
||||
const date = padZero(splitDate[2], 2);
|
||||
const year: string = padZero(splitDate[0], 4);
|
||||
const month: string = padZero(splitDate[1], 2);
|
||||
const date: string = padZero(splitDate[2], 2);
|
||||
|
||||
const splitTime: string[] = this.time.value.split(":");
|
||||
const hour = padZero(splitTime[0], 2);
|
||||
const minute = padZero(splitTime[1], 2);
|
||||
const hour: string = padZero(splitTime[0], 2);
|
||||
const minute: string = padZero(splitTime[1], 2);
|
||||
|
||||
const priorityNumber = parseInt(this.priority.value);
|
||||
const invertedPriority = 100 - priorityNumber;
|
||||
const priorityNumber: number = parseInt(this.priority.value);
|
||||
const invertedPriority: number = 100 - priorityNumber;
|
||||
|
||||
return (
|
||||
year +
|
||||
@@ -168,7 +168,9 @@ export default class TaskViewModel extends Context {
|
||||
loadVersionIds = (): void => {
|
||||
const versionIds: string[] =
|
||||
this.boardsAndTasksModel.listTaskVersionIds(this.task.fileId);
|
||||
const sortedVersionIds = versionIds.sort(localeCompare).reverse();
|
||||
const sortedVersionIds: string[] = versionIds
|
||||
.sort(localeCompare)
|
||||
.reverse();
|
||||
this.versionIds.clear();
|
||||
this.versionIds.add(...sortedVersionIds);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user