prepare messagePage layout
This commit is contained in:
Vendored
+14
@@ -332,6 +332,20 @@ main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* src/View/ChatPages/messagePage.css */
|
||||||
|
#chat-page #main #message-page .content {
|
||||||
|
padding: 0px;
|
||||||
|
overflow: hidden;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 1fr var(--control-height);
|
||||||
|
}
|
||||||
|
#message-page #message-container {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
#message-page #composer {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
/* src/View/Components/chatEntry.css */
|
/* src/View/Components/chatEntry.css */
|
||||||
.chat-entry {
|
.chat-entry {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
Vendored
+71
-17
@@ -233,6 +233,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/Model/Utility/utility.ts
|
// src/Model/Utility/utility.ts
|
||||||
|
function createTimestamp() {
|
||||||
|
return (/* @__PURE__ */ new Date()).toISOString();
|
||||||
|
}
|
||||||
function stringify(data) {
|
function stringify(data) {
|
||||||
return JSON.stringify(data, null, 4);
|
return JSON.stringify(data, null, 4);
|
||||||
}
|
}
|
||||||
@@ -380,7 +383,7 @@
|
|||||||
})(Color || {});
|
})(Color || {});
|
||||||
|
|
||||||
// src/Model/chatModel.ts
|
// src/Model/chatModel.ts
|
||||||
var ChatModel = class {
|
var ChatModel = class _ChatModel {
|
||||||
connectionModel;
|
connectionModel;
|
||||||
storageModel;
|
storageModel;
|
||||||
settingsModel;
|
settingsModel;
|
||||||
@@ -466,7 +469,7 @@
|
|||||||
if (info != null) {
|
if (info != null) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
} else {
|
} else {
|
||||||
this.info = generateChatInfo("0");
|
this.info = _ChatModel.generateChatInfo("0");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
restoreColor = () => {
|
restoreColor = () => {
|
||||||
@@ -501,6 +504,20 @@
|
|||||||
};
|
};
|
||||||
// messaging
|
// messaging
|
||||||
sendMessage = (body) => {
|
sendMessage = (body) => {
|
||||||
|
const senderName = this.settingsModel.username;
|
||||||
|
if (senderName == "") return false;
|
||||||
|
const allChannels = [this.info.primaryChannel];
|
||||||
|
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||||
|
allChannels.push(secondaryChannel);
|
||||||
|
}
|
||||||
|
const combinedChannel = allChannels.join("/");
|
||||||
|
const chatMessage = _ChatModel.createChatMessage(
|
||||||
|
combinedChannel,
|
||||||
|
senderName,
|
||||||
|
body
|
||||||
|
);
|
||||||
|
this.connectionModel.sendMessageOrStore(chatMessage);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
// memory
|
// memory
|
||||||
loadData = () => {
|
loadData = () => {
|
||||||
@@ -521,15 +538,26 @@
|
|||||||
this.restoreInfo();
|
this.restoreInfo();
|
||||||
this.restoreColor();
|
this.restoreColor();
|
||||||
}
|
}
|
||||||
};
|
// utility
|
||||||
function generateChatInfo(primaryChannel) {
|
static generateChatInfo = (primaryChannel) => {
|
||||||
return {
|
return {
|
||||||
primaryChannel,
|
primaryChannel,
|
||||||
secondaryChannels: [],
|
secondaryChannels: [],
|
||||||
encryptionKey: "",
|
encryptionKey: "",
|
||||||
hasUnreadMessages: false
|
hasUnreadMessages: false
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
static createChatMessage = (channel, sender, body) => {
|
||||||
|
return {
|
||||||
|
dataVersion: "v2",
|
||||||
|
id: v4_default(),
|
||||||
|
channel,
|
||||||
|
sender,
|
||||||
|
body,
|
||||||
|
dateSent: createTimestamp()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// src/Model/chatListModel.ts
|
// src/Model/chatListModel.ts
|
||||||
var ChatListModel = class {
|
var ChatListModel = class {
|
||||||
@@ -601,6 +629,7 @@
|
|||||||
var ChatViewModel = class {
|
var ChatViewModel = class {
|
||||||
chatModel;
|
chatModel;
|
||||||
storageModel;
|
storageModel;
|
||||||
|
settingsViewModel;
|
||||||
chatListViewModel;
|
chatListViewModel;
|
||||||
// state
|
// state
|
||||||
index = new State(0);
|
index = new State(0);
|
||||||
@@ -625,6 +654,7 @@
|
|||||||
() => this.primaryChannelInput.value == "" || this.primaryChannelInput.value == this.primaryChannel.value
|
() => this.primaryChannelInput.value == "" || this.primaryChannelInput.value == this.primaryChannel.value
|
||||||
);
|
);
|
||||||
cannotSetEncryptionKey;
|
cannotSetEncryptionKey;
|
||||||
|
cannotSendMessage;
|
||||||
// sorting
|
// sorting
|
||||||
updateIndex = () => {
|
updateIndex = () => {
|
||||||
this.index.value = this.chatModel.index;
|
this.index.value = this.chatModel.index;
|
||||||
@@ -670,6 +700,11 @@
|
|||||||
this.chatModel.delete();
|
this.chatModel.delete();
|
||||||
this.chatListViewModel.restoreChats();
|
this.chatListViewModel.restoreChats();
|
||||||
};
|
};
|
||||||
|
// messaging
|
||||||
|
sendMessage = () => {
|
||||||
|
this.chatModel.sendMessage(this.composingMessage.value);
|
||||||
|
this.composingMessage.value = "";
|
||||||
|
};
|
||||||
// restore
|
// restore
|
||||||
restorePageSelection = () => {
|
restorePageSelection = () => {
|
||||||
const path = storageKeys.chatLastUsedPage(this.chatModel.id);
|
const path = storageKeys.chatLastUsedPage(this.chatModel.id);
|
||||||
@@ -690,9 +725,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// init
|
// init
|
||||||
constructor(chatModel, storageModel2, chatListViewModel2) {
|
constructor(chatModel, storageModel2, settingsViewModel2, chatListViewModel2) {
|
||||||
this.chatModel = chatModel;
|
this.chatModel = chatModel;
|
||||||
this.storageModel = storageModel2;
|
this.storageModel = storageModel2;
|
||||||
|
this.settingsViewModel = settingsViewModel2;
|
||||||
this.chatListViewModel = chatListViewModel2;
|
this.chatListViewModel = chatListViewModel2;
|
||||||
this.primaryChannel.value = chatModel.info.primaryChannel;
|
this.primaryChannel.value = chatModel.info.primaryChannel;
|
||||||
this.primaryChannelInput.value = chatModel.info.primaryChannel;
|
this.primaryChannelInput.value = chatModel.info.primaryChannel;
|
||||||
@@ -701,6 +737,10 @@
|
|||||||
[this.encryptionKeyInput],
|
[this.encryptionKeyInput],
|
||||||
() => this.encryptionKeyInput.value == this.chatModel.info.encryptionKey
|
() => this.encryptionKeyInput.value == this.chatModel.info.encryptionKey
|
||||||
);
|
);
|
||||||
|
this.cannotSendMessage = createProxyState(
|
||||||
|
[this.settingsViewModel.username],
|
||||||
|
() => this.settingsViewModel.username.value == ""
|
||||||
|
);
|
||||||
this.color.value = chatModel.color;
|
this.color.value = chatModel.color;
|
||||||
this.restoreSecondaryChannels();
|
this.restoreSecondaryChannels();
|
||||||
this.restorePageSelection();
|
this.restorePageSelection();
|
||||||
@@ -712,6 +752,7 @@
|
|||||||
var ChatListViewModel = class {
|
var ChatListViewModel = class {
|
||||||
chatListModel;
|
chatListModel;
|
||||||
storageModel;
|
storageModel;
|
||||||
|
settingsViewModel;
|
||||||
// state
|
// state
|
||||||
newChatPrimaryChannel = new State("");
|
newChatPrimaryChannel = new State("");
|
||||||
chatViewModels = new ListState();
|
chatViewModels = new ListState();
|
||||||
@@ -736,7 +777,12 @@
|
|||||||
this.chatViewModels.remove(chatViewModel);
|
this.chatViewModels.remove(chatViewModel);
|
||||||
};
|
};
|
||||||
createChatViewModel = (chatModel) => {
|
createChatViewModel = (chatModel) => {
|
||||||
return new ChatViewModel(chatModel, this.storageModel, this);
|
return new ChatViewModel(
|
||||||
|
chatModel,
|
||||||
|
this.storageModel,
|
||||||
|
this.settingsViewModel,
|
||||||
|
this
|
||||||
|
);
|
||||||
};
|
};
|
||||||
// view
|
// view
|
||||||
openChat = (chatViewModel) => {
|
openChat = (chatViewModel) => {
|
||||||
@@ -760,9 +806,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// init
|
// init
|
||||||
constructor(chatListModel2, storageModel2) {
|
constructor(chatListModel2, storageModel2, settingsViewModel2) {
|
||||||
this.chatListModel = chatListModel2;
|
this.chatListModel = chatListModel2;
|
||||||
this.storageModel = storageModel2;
|
this.storageModel = storageModel2;
|
||||||
|
this.settingsViewModel = settingsViewModel2;
|
||||||
this.restoreChats();
|
this.restoreChats();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -790,7 +837,7 @@
|
|||||||
|
|
||||||
// src/View/ChatPages/messagePage.tsx
|
// src/View/ChatPages/messagePage.tsx
|
||||||
function MessagePage(chatViewModel) {
|
function MessagePage(chatViewModel) {
|
||||||
return /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("div", { class: "toolbar" }, /* @__PURE__ */ createElement("span", { "subscribe:innerText": chatViewModel.primaryChannel })));
|
return /* @__PURE__ */ createElement("div", { id: "message-page" }, /* @__PURE__ */ createElement("div", { class: "toolbar" }, /* @__PURE__ */ createElement("span", { "subscribe:innerText": chatViewModel.primaryChannel })), /* @__PURE__ */ createElement("div", { class: "content" }, /* @__PURE__ */ createElement("div", { id: "message-container" }), /* @__PURE__ */ createElement("div", { id: "composer" })));
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/View/translations.ts
|
// src/View/translations.ts
|
||||||
@@ -1460,7 +1507,7 @@
|
|||||||
"input",
|
"input",
|
||||||
{
|
{
|
||||||
placeholder: translations.homePage.yourNamePlaceholder,
|
placeholder: translations.homePage.yourNamePlaceholder,
|
||||||
"bind:value": settingsViewModel2.nameInput,
|
"bind:value": settingsViewModel2.usernameInput,
|
||||||
"on:enter": settingsViewModel2.setName
|
"on:enter": settingsViewModel2.setName
|
||||||
}
|
}
|
||||||
))), /* @__PURE__ */ createElement("div", { class: "flex-row justify-end" }, /* @__PURE__ */ createElement(
|
))), /* @__PURE__ */ createElement("div", { class: "flex-row justify-end" }, /* @__PURE__ */ createElement(
|
||||||
@@ -1549,17 +1596,19 @@
|
|||||||
var SettingsViewModel = class {
|
var SettingsViewModel = class {
|
||||||
settingsModel;
|
settingsModel;
|
||||||
// state
|
// state
|
||||||
nameInput = new State("");
|
username = new State("");
|
||||||
|
usernameInput = new State("");
|
||||||
firstDayOfWeekInput = new State(0);
|
firstDayOfWeekInput = new State(0);
|
||||||
// guards
|
// guards
|
||||||
cannotSetName = createProxyState(
|
cannotSetName = createProxyState(
|
||||||
[this.nameInput],
|
[this.usernameInput],
|
||||||
() => this.nameInput.value == "" || this.nameInput.value == this.settingsModel.username
|
() => this.usernameInput.value == "" || this.usernameInput.value == this.settingsModel.username
|
||||||
);
|
);
|
||||||
// set
|
// set
|
||||||
setName = () => {
|
setName = () => {
|
||||||
this.settingsModel.setName(this.nameInput.value);
|
this.settingsModel.setName(this.usernameInput.value);
|
||||||
this.nameInput.callSubscriptions();
|
this.username.value = this.settingsModel.username;
|
||||||
|
this.usernameInput.callSubscriptions();
|
||||||
};
|
};
|
||||||
setFirstDayofWeek = () => {
|
setFirstDayofWeek = () => {
|
||||||
this.settingsModel.setFirstDayOfWeek(this.firstDayOfWeekInput.value);
|
this.settingsModel.setFirstDayOfWeek(this.firstDayOfWeekInput.value);
|
||||||
@@ -1567,7 +1616,8 @@
|
|||||||
// init
|
// init
|
||||||
constructor(settingsModel2) {
|
constructor(settingsModel2) {
|
||||||
this.settingsModel = settingsModel2;
|
this.settingsModel = settingsModel2;
|
||||||
this.nameInput.value = settingsModel2.username;
|
this.username.value = settingsModel2.username;
|
||||||
|
this.usernameInput.value = settingsModel2.username;
|
||||||
this.firstDayOfWeekInput.value = settingsModel2.firstDayOfWeek;
|
this.firstDayOfWeekInput.value = settingsModel2.firstDayOfWeek;
|
||||||
this.firstDayOfWeekInput.subscribe(this.setFirstDayofWeek);
|
this.firstDayOfWeekInput.subscribe(this.setFirstDayofWeek);
|
||||||
}
|
}
|
||||||
@@ -1585,7 +1635,11 @@
|
|||||||
storageModel.print();
|
storageModel.print();
|
||||||
var settingsViewModel = new SettingsViewModel(settingsModel);
|
var settingsViewModel = new SettingsViewModel(settingsModel);
|
||||||
var connectionViewModel = new ConnectionViewModel(connectionModel);
|
var connectionViewModel = new ConnectionViewModel(connectionModel);
|
||||||
var chatListViewModel = new ChatListViewModel(chatListModel, storageModel);
|
var chatListViewModel = new ChatListViewModel(
|
||||||
|
chatListModel,
|
||||||
|
storageModel,
|
||||||
|
settingsViewModel
|
||||||
|
);
|
||||||
document.body.append(/* @__PURE__ */ createElement("div", { id: "background" }));
|
document.body.append(/* @__PURE__ */ createElement("div", { id: "background" }));
|
||||||
document.querySelector("main").append(
|
document.querySelector("main").append(
|
||||||
HomePage(settingsViewModel, connectionViewModel, chatListViewModel),
|
HomePage(settingsViewModel, connectionViewModel, chatListViewModel),
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/* layout */
|
||||||
|
#chat-page #main #message-page .content {
|
||||||
|
padding: 0px;
|
||||||
|
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 1fr var(--control-height);
|
||||||
|
}
|
||||||
|
|
||||||
|
#message-page #message-container {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* composer */
|
||||||
|
#message-page #composer {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
|
import "./messagePage.css";
|
||||||
|
|
||||||
import * as React from "bloatless-react";
|
import * as React from "bloatless-react";
|
||||||
|
|
||||||
import ChatViewModel from "../../ViewModel/chatViewModel";
|
import ChatViewModel from "../../ViewModel/chatViewModel";
|
||||||
|
|
||||||
export function MessagePage(chatViewModel: ChatViewModel) {
|
export function MessagePage(chatViewModel: ChatViewModel) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div id="message-page">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<span subscribe:innerText={chatViewModel.primaryChannel}></span>
|
<span subscribe:innerText={chatViewModel.primaryChannel}></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<div id="message-container"></div>
|
||||||
|
<div id="composer"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user