summaryrefslogtreecommitdiff
path: root/ui/src/lib/store/channels.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-10 21:05:48 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-10 21:05:48 -0400
commit4401dce2b5545ce8117818812d8e3c8919f5f7fd (patch)
treedf04478e6094a2a8cdd14ecd31b77caacff78de6 /ui/src/lib/store/channels.js
parent999996961e6e8ebcde125ff0022df875d62817b3 (diff)
Remove redundancy in `hi-ui` directory name.
Diffstat (limited to 'ui/src/lib/store/channels.js')
-rw-r--r--ui/src/lib/store/channels.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/ui/src/lib/store/channels.js b/ui/src/lib/store/channels.js
new file mode 100644
index 0000000..bb6c86c
--- /dev/null
+++ b/ui/src/lib/store/channels.js
@@ -0,0 +1,71 @@
+export class Channels {
+ constructor() {
+ this.channels = [];
+ }
+
+ setChannels(channels) {
+ this.channels = [...channels];
+ this.sort();
+ return this;
+ }
+
+ addChannel(id, name) {
+ this.channels = [...this.channels, { id, name }];
+ 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;
+ }
+}