add context, rewrite keystrokes
This commit is contained in:
@@ -13,8 +13,11 @@ import StorageModel from "../../Model/Global/storageModel";
|
||||
import TaskContainingPageViewModel from "./taskContainingPageViewModel";
|
||||
import TaskPageViewModel from "./taskPageViewModel";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
|
||||
export default class BoardViewModel extends TaskContainingPageViewModel {
|
||||
contextDebugDescription = "board";
|
||||
|
||||
// state
|
||||
name: React.State<string> = new React.State("");
|
||||
color: React.State<Colors> = new React.State<any>(Colors.Standard);
|
||||
@@ -180,6 +183,10 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
||||
this.isPresentingFilterModal.value = false;
|
||||
};
|
||||
|
||||
resetFilter = (): void => {
|
||||
this.searchViewModel.search("");
|
||||
};
|
||||
|
||||
updateIndex = (): void => {
|
||||
const index: number =
|
||||
this.taskPageViewModel.boardIndexManager.getIndex(this);
|
||||
@@ -295,6 +302,13 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
||||
[this.searchViewModel.appliedQuery],
|
||||
() => this.searchViewModel.appliedQuery.value != "",
|
||||
);
|
||||
|
||||
// keystrokes
|
||||
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.hideFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.Reset, this.resetFilter);
|
||||
|
||||
this.taskPageViewModel.registerContext(this.boardInfo.fileId, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,17 @@ import BoardsAndTasksModel, {
|
||||
} from "../../Model/Files/boardsAndTasksModel";
|
||||
import CalendarModel, { MonthGrid } from "../../Model/Files/calendarModel";
|
||||
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import ChatViewModel, { ChatPageTypes } from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import StorageModel from "../../Model/Global/storageModel";
|
||||
import TaskContainingPageViewModel from "./taskContainingPageViewModel";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
|
||||
export const CALENDAR_EVENT_BOARD_ID = "events";
|
||||
|
||||
export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
contextDebugDescription = "calendar";
|
||||
|
||||
// data
|
||||
get monthString(): string {
|
||||
return CalendarModel.getMonthString(
|
||||
@@ -208,6 +210,13 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
|
||||
// initiate
|
||||
this.showToday();
|
||||
|
||||
// keystrokes
|
||||
this.registerKeyStroke(CommonKeys.Reset, this.showToday);
|
||||
this.registerKeyStroke("p", this.showNextMonth);
|
||||
this.registerKeyStroke("o", this.showPreviousMonth);
|
||||
|
||||
this.chatViewModel.registerContext(ChatPageTypes.Calendar, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
import ConnectionViewModel from "../Global/connectionViewModel";
|
||||
import CoreViewModel, { Context } from "../Global/coreViewModel";
|
||||
import FileTransferViewModel from "../Global/fileTransferViewModel";
|
||||
import SettingsViewModel from "../Global/settingsViewModel";
|
||||
import StorageViewModel from "../Global/storageViewModel";
|
||||
|
||||
export default class HomeViewModel extends Context {
|
||||
contextDebugDescription = "home";
|
||||
|
||||
constructor(
|
||||
public coreViewModel: CoreViewModel,
|
||||
public settingsViewModel: SettingsViewModel,
|
||||
public fileTransferViewModel: FileTransferViewModel,
|
||||
public storageViewModel: StorageViewModel,
|
||||
public connectionViewModel: ConnectionViewModel,
|
||||
) {
|
||||
super();
|
||||
|
||||
this.coreViewModel.context = this;
|
||||
|
||||
this.registerKeyStroke(
|
||||
CommonKeys.Settings,
|
||||
this.settingsViewModel.showSettingsModal,
|
||||
);
|
||||
this.registerKeyStroke(
|
||||
"d",
|
||||
this.fileTransferViewModel.showDirectionSelectionModal,
|
||||
);
|
||||
this.registerKeyStroke("e", this.storageViewModel.showStorageModal);
|
||||
this.registerKeyStroke("x", this.connectionViewModel.disconnect);
|
||||
this.registerKeyStroke("c", this.connectionViewModel.connect);
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,15 @@ import {
|
||||
ReactionSymbols,
|
||||
} from "../../Model/Chat/chatModel";
|
||||
import ChatMessageViewModel from "../Chat/chatMessageViewModel";
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import ChatViewModel, { ChatPageTypes } from "../Chat/chatViewModel";
|
||||
import CoreViewModel, { Context } from "../Global/coreViewModel";
|
||||
import SearchViewModel from "../Utility/searchViewModel";
|
||||
import { v4 } from "uuid";
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
|
||||
export default class MessagePageViewModel extends Context {
|
||||
contextDebugDescription = "message-page";
|
||||
|
||||
export default class MessagePageViewModel {
|
||||
// state
|
||||
chatMessageViewModels: React.MapState<ChatMessageViewModel> =
|
||||
new React.MapState();
|
||||
@@ -89,11 +93,11 @@ export default class MessagePageViewModel {
|
||||
messageViewModel.handleReaction(reaction);
|
||||
};
|
||||
|
||||
openFilterModal = (): void => {
|
||||
showFilterModal = (): void => {
|
||||
this.isFilterModalOpen.value = true;
|
||||
};
|
||||
|
||||
closeFilterModal = (): void => {
|
||||
hideFilterModal = (): void => {
|
||||
this.isFilterModalOpen.value = false;
|
||||
};
|
||||
|
||||
@@ -105,6 +109,11 @@ export default class MessagePageViewModel {
|
||||
this.reactionFilter.value = content;
|
||||
};
|
||||
|
||||
resetFilter = (): void => {
|
||||
this.revokeReactionFilter();
|
||||
this.searchViewModel.search("");
|
||||
};
|
||||
|
||||
// load
|
||||
loadData = (): void => {
|
||||
this.chatMessageViewModels.clear();
|
||||
@@ -121,6 +130,9 @@ export default class MessagePageViewModel {
|
||||
public coreViewModel: CoreViewModel,
|
||||
public chatViewModel: ChatViewModel,
|
||||
) {
|
||||
super();
|
||||
|
||||
// states
|
||||
this.cannotSendMessage = React.createProxyState(
|
||||
[
|
||||
this.chatViewModel.settingsViewModel.username,
|
||||
@@ -144,5 +156,12 @@ export default class MessagePageViewModel {
|
||||
this.searchViewModel.appliedQuery.value != "" ||
|
||||
this.reactionFilter.value != undefined,
|
||||
);
|
||||
|
||||
// keystrokes
|
||||
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.hideFilterModal);
|
||||
this.registerKeyStroke(CommonKeys.Reset, this.resetFilter);
|
||||
|
||||
this.chatViewModel.registerContext(ChatPageTypes.Messages, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import ChatViewModel, { ChatPageTypes } from "../Chat/chatViewModel";
|
||||
import { Colors } from "../../colors";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import CoreViewModel, { Context } from "../Global/coreViewModel";
|
||||
|
||||
export default class SettingsPageViewModel extends Context {
|
||||
contextDebugDescription = "settings";
|
||||
|
||||
export default class SettingsPageViewModel {
|
||||
// state
|
||||
primaryChannel: React.State<string> = new React.State("");
|
||||
primaryChannelInput: React.State<string> = new React.State("");
|
||||
@@ -113,6 +115,8 @@ export default class SettingsPageViewModel {
|
||||
public coreViewModel: CoreViewModel,
|
||||
public chatViewModel: ChatViewModel,
|
||||
) {
|
||||
super();
|
||||
|
||||
this.loadListRelevantData();
|
||||
|
||||
this.cannotSetEncryptionKey = React.createProxyState(
|
||||
@@ -125,5 +129,7 @@ export default class SettingsPageViewModel {
|
||||
this.color.subscribe((newColor) => {
|
||||
this.applyColor(newColor);
|
||||
});
|
||||
|
||||
this.chatViewModel.registerContext(ChatPageTypes.Settings, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import BoardsAndTasksModel, {
|
||||
} from "../../Model/Files/boardsAndTasksModel";
|
||||
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import CoreViewModel, { Context } from "../Global/coreViewModel";
|
||||
import { IndexManager } from "../../Model/Utility/utility";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
|
||||
export default class TaskContainingPageViewModel {
|
||||
export default class TaskContainingPageViewModel extends Context {
|
||||
// state
|
||||
taskIndexManager: IndexManager<TaskViewModel> = new IndexManager(
|
||||
(taskViewModel: TaskViewModel) => taskViewModel.sortingString,
|
||||
@@ -59,5 +59,7 @@ export default class TaskContainingPageViewModel {
|
||||
public coreViewModel: CoreViewModel,
|
||||
public chatViewModel: ChatViewModel,
|
||||
public boardsAndTasksModel: BoardsAndTasksModel,
|
||||
) {}
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import BoardsAndTasksModel, {
|
||||
BoardInfoFileContent,
|
||||
} from "../../Model/Files/boardsAndTasksModel";
|
||||
|
||||
import BoardViewModel from "./boardViewModel";
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import BoardViewModel, { BoardPageTypes } from "./boardViewModel";
|
||||
import ChatViewModel, { ChatPageTypes } from "../Chat/chatViewModel";
|
||||
import CoreViewModel, { Context, ContextHost } from "../Global/coreViewModel";
|
||||
import { IndexManager } from "../../Model/Utility/utility";
|
||||
|
||||
export default class TaskPageViewModel {
|
||||
export default class TaskPageViewModel extends ContextHost<string> {
|
||||
contextDebugDescription = "task-page";
|
||||
|
||||
// data
|
||||
boardIndexManager: IndexManager<BoardViewModel> = new IndexManager(
|
||||
(boardViewModel: BoardViewModel) => boardViewModel.name.value,
|
||||
@@ -19,26 +21,33 @@ export default class TaskPageViewModel {
|
||||
getBasePath = (): string[] => {
|
||||
return [...this.boardsAndTasksModel.getViewPath()];
|
||||
};
|
||||
|
||||
getBoardViewPath = (boardId): string[] => {
|
||||
return [...this.getBasePath(), boardId];
|
||||
};
|
||||
|
||||
getLastUsedBoardPath = (): string[] => {
|
||||
return [...this.getBasePath(), TaskPageViewModelSubPaths.LastUsedBoard];
|
||||
};
|
||||
|
||||
// state
|
||||
newBoardNameInput: React.State<string> = new React.State("");
|
||||
|
||||
boardViewModels: React.MapState<BoardViewModel> = new React.MapState();
|
||||
|
||||
isShowingBoadList: React.State<boolean> = new React.State(true);
|
||||
|
||||
selectedBoardId: React.State<string | undefined> = new React.State<any>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
// context
|
||||
get isOpen(): boolean {
|
||||
return (
|
||||
this.chatViewModel.isOpen &&
|
||||
this.chatViewModel.selectedPage.value == ChatPageTypes.Tasks
|
||||
);
|
||||
}
|
||||
|
||||
get contextSelection(): string {
|
||||
return this.selectedBoardId.value;
|
||||
}
|
||||
|
||||
// guards
|
||||
cannotCreateBoard: React.State<boolean> = React.createProxyState(
|
||||
[this.newBoardNameInput],
|
||||
@@ -98,6 +107,8 @@ export default class TaskPageViewModel {
|
||||
};
|
||||
|
||||
closeBoard = (): void => {
|
||||
this.closeContext();
|
||||
|
||||
this.selectedBoardId.value = undefined;
|
||||
this.chatViewModel.resetColor();
|
||||
|
||||
@@ -154,6 +165,8 @@ export default class TaskPageViewModel {
|
||||
public chatViewModel: ChatViewModel,
|
||||
public boardsAndTasksModel: BoardsAndTasksModel,
|
||||
) {
|
||||
super();
|
||||
|
||||
this.chatViewModel = chatViewModel;
|
||||
|
||||
this.loadData();
|
||||
@@ -165,6 +178,11 @@ export default class TaskPageViewModel {
|
||||
this.updateBoardIndices();
|
||||
},
|
||||
);
|
||||
|
||||
// context
|
||||
this.chatViewModel.registerContext(ChatPageTypes.Tasks, this);
|
||||
|
||||
this.selectedBoardId.subscribeSilent(this.updateContexts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,16 @@ import BoardsAndTasksModel, {
|
||||
import { localeCompare, padZero } from "../../Model/Utility/utility";
|
||||
|
||||
import ChatViewModel from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import CoreViewModel, { Context } from "../Global/coreViewModel";
|
||||
import TaskContainingPageViewModel from "./taskContainingPageViewModel";
|
||||
import { allowDrag } from "../../View/utility";
|
||||
import { v4 } from "uuid";
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
|
||||
export default class TaskViewModel {
|
||||
export default class TaskViewModel extends Context {
|
||||
contextDebugDescription = "task";
|
||||
|
||||
// util
|
||||
get sortingString(): string {
|
||||
const splitDate: string[] = this.date.value.split("-");
|
||||
const year = padZero(splitDate[0], 4);
|
||||
@@ -82,21 +87,21 @@ export default class TaskViewModel {
|
||||
|
||||
// view
|
||||
open = (): void => {
|
||||
this.coreViewModel.context = this;
|
||||
this.containingModel.selectTask(this);
|
||||
};
|
||||
|
||||
close = (): void => {
|
||||
this.coreViewModel.closeContext(this.contextId);
|
||||
this.containingModel.closeTask();
|
||||
};
|
||||
|
||||
closeAndDiscard = (e: Event): void => {
|
||||
e.preventDefault();
|
||||
closeAndDiscard = (): void => {
|
||||
this.close();
|
||||
this.loadTaskData();
|
||||
};
|
||||
|
||||
closeAndSave = (e: Event): void => {
|
||||
e.preventDefault();
|
||||
closeAndSave = (): void => {
|
||||
this.close();
|
||||
this.save();
|
||||
};
|
||||
@@ -211,6 +216,8 @@ export default class TaskViewModel {
|
||||
public containingModel: TaskContainingPageViewModel,
|
||||
public task: TaskFileContent,
|
||||
) {
|
||||
super();
|
||||
|
||||
// load
|
||||
this.loadAllData();
|
||||
|
||||
@@ -218,6 +225,10 @@ export default class TaskViewModel {
|
||||
this.selectedVersionId.subscribeSilent((selectedVersionId) => {
|
||||
this.switchVersion(selectedVersionId);
|
||||
});
|
||||
|
||||
// keystrokes
|
||||
this.registerKeyStroke(CommonKeys.Apply, this.closeAndSave);
|
||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.closeAndDiscard);
|
||||
}
|
||||
|
||||
// utility
|
||||
|
||||
Reference in New Issue
Block a user