sort chats alphabetically
This commit is contained in:
@@ -14,7 +14,7 @@ export default class ChatListViewModel {
|
||||
chatViewModels: React.ListState<ChatViewModel> = new React.ListState();
|
||||
|
||||
selectedChat: React.State<ChatViewModel | undefined> = new React.State<
|
||||
ChatViewModel | undefined
|
||||
ChatViewModel | undefined
|
||||
>(undefined);
|
||||
|
||||
// guards
|
||||
@@ -23,6 +23,15 @@ export default class ChatListViewModel {
|
||||
() => this.newChatPrimaryChannel.value == ""
|
||||
);
|
||||
|
||||
// sorting
|
||||
get sortedPrimaryChannels(): string[] {
|
||||
return this.chatListModel.sortedPrimaryChannels;
|
||||
}
|
||||
|
||||
getIndexOfChat(chat: ChatViewModel): number {
|
||||
return this.sortedPrimaryChannels.indexOf(chat.primaryChannel.value);
|
||||
}
|
||||
|
||||
// methods
|
||||
createChat = (): void => {
|
||||
const chatModel: ChatModel = this.chatListModel.createChat(
|
||||
|
||||
@@ -11,6 +11,8 @@ export default class ChatViewModel {
|
||||
storageModel: StorageModel;
|
||||
|
||||
// state
|
||||
index: React.State<number> = new React.State(0);
|
||||
|
||||
primaryChannel: React.State<string> = new React.State("");
|
||||
primaryChannelInput: React.State<string> = new React.State("");
|
||||
|
||||
@@ -26,6 +28,12 @@ export default class ChatViewModel {
|
||||
this.primaryChannelInput.value == this.primaryChannel.value
|
||||
);
|
||||
|
||||
// sorting
|
||||
updateIndex = (): void => {
|
||||
const index = this.chatListViewModel.getIndexOfChat(this);
|
||||
this.index.value = index;
|
||||
};
|
||||
|
||||
// methods
|
||||
open = (): void => {
|
||||
this.chatListViewModel.openChat(this);
|
||||
@@ -58,6 +66,7 @@ export default class ChatViewModel {
|
||||
this.primaryChannelInput.value = chatModel.info.primaryChannel;
|
||||
|
||||
this.restorePageSelection();
|
||||
this.updateIndex();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user