From 2e2e3980ab78052be74f4007c343e69a583648fe Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 10 Oct 2024 22:30:18 -0400 Subject: Compute the active channel from the current routing state, not from a store. --- ui/lib/apiServer.js | 3 +-- ui/lib/components/ActiveChannel.svelte | 7 ++++--- ui/lib/components/Channel.svelte | 8 +------ ui/lib/components/ChannelList.svelte | 8 +++---- ui/lib/components/MessageInput.svelte | 30 +++++++++++++------------- ui/lib/store.js | 3 +-- ui/lib/store/channels.js | 35 ------------------------------- ui/routes/(app)/+layout.svelte | 6 ++++-- ui/routes/(app)/ch/[channel]/+page.svelte | 15 ++++--------- 9 files changed, 32 insertions(+), 83 deletions(-) (limited to 'ui') diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js index f6d6148..538fa85 100644 --- a/ui/lib/apiServer.js +++ b/ui/lib/apiServer.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import { activeChannel, channelsList, logins, messages } from '$lib/store'; +import { channelsList, logins, messages } from '$lib/store'; export const apiServer = axios.create({ baseURL: '/api/', @@ -82,7 +82,6 @@ function onChannelEvent(data) { channelsList.update((value) => value.addChannel(data.id, data.name)) break; case 'deleted': - activeChannel.update((value) => value.deleteChannel(data.id)); channelsList.update((value) => value.deleteChannel(data.id)); messages.update((value) => value.deleteChannel(data.id)); break; diff --git a/ui/lib/components/ActiveChannel.svelte b/ui/lib/components/ActiveChannel.svelte index 978e952..ece9f55 100644 --- a/ui/lib/components/ActiveChannel.svelte +++ b/ui/lib/components/ActiveChannel.svelte @@ -1,10 +1,11 @@
  • { - channels = value.channels; - }); + $: channels = $channelsList.channels; diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index b33574b..0da78d4 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -1,30 +1,28 @@
    - +
    diff --git a/ui/lib/store.js b/ui/lib/store.js index b964b4b..ae17ffa 100644 --- a/ui/lib/store.js +++ b/ui/lib/store.js @@ -1,10 +1,9 @@ import { writable } from 'svelte/store'; -import { ActiveChannel, Channels } from '$lib/store/channels'; +import { Channels } from '$lib/store/channels'; import { Messages } from '$lib/store/messages'; import { Logins } from '$lib/store/logins'; export const currentUser = writable(null); -export const activeChannel = writable(new ActiveChannel()); export const logins = writable(new Logins()); export const channelsList = writable(new Channels()); export const messages = writable(new Messages()); diff --git a/ui/lib/store/channels.js b/ui/lib/store/channels.js index bb6c86c..b57ca7e 100644 --- a/ui/lib/store/channels.js +++ b/ui/lib/store/channels.js @@ -34,38 +34,3 @@ export class Channels { }); } } - -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/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index f8744c1..1d561ae 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -1,5 +1,6 @@ - +
    + +
    -- cgit v1.2.3