From bd53a51af835478d23bef4772ce7e50553dc3fdf Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Wed, 9 Oct 2024 15:32:52 -0400 Subject: Move a lot of things around --- hi-ui/src/store/channels.js | 71 --------------------------------------------- hi-ui/src/store/messages.js | 41 -------------------------- 2 files changed, 112 deletions(-) delete mode 100644 hi-ui/src/store/channels.js delete mode 100644 hi-ui/src/store/messages.js (limited to 'hi-ui/src/store') diff --git a/hi-ui/src/store/channels.js b/hi-ui/src/store/channels.js deleted file mode 100644 index 20702cc..0000000 --- a/hi-ui/src/store/channels.js +++ /dev/null @@ -1,71 +0,0 @@ -export class Channels { - constructor() { - this.channels = []; - } - - setChannels(channels) { - this.channels = [...channels]; - this.sort(); - return this; - } - - addChannel(channel) { - this.channels = [...this.channels, channel]; - this.sort(); - return this; - } - - deleteChannel(id) { - const channelIndex = this.channels.map((e) => e.id).indexOf(id); - if (channelIndex !== -1) { - this.channels.splice(channelIndex, 1); - } - return this; - } - - sort() { - this.channels.sort((a, b) => { - if (a.name < b.name) { - return -1; - } else if (a.name > b.name) { - return 1; - } - return 0; - }); - } -} - -export class ActiveChannel { - constructor() { - this.channel = null; - } - - isSet() { - return this.channel !== null; - } - - get() { - return this.channel; - } - - is(id) { - return this.channel === id; - } - - set(id) { - this.channel = id; - return this; - } - - deleteChannel(id) { - if (this.is(id)) { - return this.clear(); - } - return this; - } - - clear() { - this.channel = null; - return this; - } -} diff --git a/hi-ui/src/store/messages.js b/hi-ui/src/store/messages.js deleted file mode 100644 index 560b9e1..0000000 --- a/hi-ui/src/store/messages.js +++ /dev/null @@ -1,41 +0,0 @@ -export class Messages { - constructor() { - this.channels = {}; - } - - inChannel(channel) { - return this.channels[channel] || []; - } - - addMessage(message) { - let { - channel, - ...payload - } = message; - let channel_id = channel.id; - this.updateChannel(channel_id, (messages) => [...messages, payload]); - return this; - } - - addMessages(channel, payloads) { - this.updateChannel(channel, (messages) => [...messages, ...payloads]); - return this; - } - - - deleteMessage(channel, message) { - let messages = this.messages(channel).filter((msg) => msg.message.id != message); - this.channels[channel] = messages; - } - - deleteChannel(id) { - delete this.channels[id]; - return this; - } - - updateChannel(channel, callback) { - let messages = callback(this.inChannel(channel)); - messages.sort((a, b) => a.at - b.at); - this.channels[channel] = messages; - } -} -- cgit v1.2.3