From 22ce0549e20ee397cf5953bd6b7aafc752deaa28 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sat, 2 Nov 2024 20:02:24 -0400 Subject: Run prettier, make lint part of pre-commit --- ui/lib/apiServer.js | 148 +++++++-------- ui/lib/components/ActiveChannel.svelte | 62 +++---- ui/lib/components/Channel.svelte | 27 ++- ui/lib/components/ChannelList.svelte | 18 +- ui/lib/components/CreateChannelForm.svelte | 34 ++-- ui/lib/components/CurrentUser.svelte | 33 ++-- ui/lib/components/Invite.svelte | 5 +- ui/lib/components/Invites.svelte | 12 +- ui/lib/components/LogIn.svelte | 48 +++-- ui/lib/components/Message.svelte | 44 ++--- ui/lib/components/MessageInput.svelte | 50 +++--- ui/lib/components/MessageRun.svelte | 33 ++-- ui/lib/store/messages.js | 5 +- ui/routes/(app)/+layout.svelte | 238 +++++++++++++------------ ui/routes/(app)/ch/[channel]/+page.svelte | 8 +- ui/routes/(app)/me/+page.svelte | 46 +++-- ui/routes/(login)/invite/[invite]/+page.js | 2 +- ui/routes/(login)/invite/[invite]/+page.svelte | 49 ++--- ui/routes/(login)/login/+page.svelte | 33 ++-- ui/routes/(login)/setup/+page.svelte | 33 ++-- ui/routes/+layout.svelte | 58 +++--- 21 files changed, 518 insertions(+), 468 deletions(-) (limited to 'ui') diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js index 5c6e5ef..3714b63 100644 --- a/ui/lib/apiServer.js +++ b/ui/lib/apiServer.js @@ -2,122 +2,124 @@ import axios from 'axios'; import { channelsList, logins, messages } from '$lib/store'; export const apiServer = axios.create({ - baseURL: '/api/', - validateStatus: () => true, + baseURL: '/api/', + validateStatus: () => true }); export async function boot() { - return apiServer.get('/boot'); + return apiServer.get('/boot'); } export async function setup(name, password) { - return apiServer.post('/setup', { name, password }); + return apiServer.post('/setup', { name, password }); } export async function logIn(name, password) { - return apiServer.post('/auth/login', { name, password }); + return apiServer.post('/auth/login', { name, password }); } export async function logOut() { - return apiServer.post('/auth/logout', {}); + return apiServer.post('/auth/logout', {}); } export async function changePassword(password, to) { - return apiServer.post('/password', { password, to }); + return apiServer.post('/password', { password, to }); } export async function createChannel(name) { - return apiServer.post('/channels', { name }); + return apiServer.post('/channels', { name }); } export async function postToChannel(channelId, body) { - return apiServer.post(`/channels/${channelId}`, { body }); + return apiServer.post(`/channels/${channelId}`, { body }); } export async function deleteMessage(messageId) { - // TODO + // TODO } export async function createInvite() { - return apiServer.post(`/invite`, {}); + return apiServer.post(`/invite`, {}); } export async function getInvite(inviteId) { - return apiServer.get(`/invite/${inviteId}`); + return apiServer.get(`/invite/${inviteId}`); } export async function acceptInvite(inviteId, username, password) { - const data = { - name: username, - password, - }; - return apiServer.post(`/invite/${inviteId}`, data); + const data = { + name: username, + password + }; + return apiServer.post(`/invite/${inviteId}`, data); } export function subscribeToEvents(resume_point) { - const eventsUrl = new URL('/api/events', window.location); - eventsUrl.searchParams.append('resume_point', resume_point); - const evtSource = new EventSource(eventsUrl.toString()); - // TODO: this should process all incoming events and store them. - // TODO: eventually we'll need to handle expiring old info, so as not to use - // infinite browser memory. - /* - * Known message types as of now: - * - created: a channel is created. - * - action: ignore. - * - message: a message is created. - * - action: display message in channel. - * - message_deleted: a message is deleted. - * - action: replace message with <...>. - * - deleted: a channel is deleted. - * - action: remove channel from sidebar. - */ - evtSource.onmessage = (evt) => { - const data = JSON.parse(evt.data); - - switch (data.type) { - case 'login': - onLoginEvent(data); - break; - case 'channel': - onChannelEvent(data); - break; - case 'message': - onMessageEvent(data); - break; - } - } - - return evtSource; + const eventsUrl = new URL('/api/events', window.location); + eventsUrl.searchParams.append('resume_point', resume_point); + const evtSource = new EventSource(eventsUrl.toString()); + // TODO: this should process all incoming events and store them. + // TODO: eventually we'll need to handle expiring old info, so as not to use + // infinite browser memory. + /* + * Known message types as of now: + * - created: a channel is created. + * - action: ignore. + * - message: a message is created. + * - action: display message in channel. + * - message_deleted: a message is deleted. + * - action: replace message with <...>. + * - deleted: a channel is deleted. + * - action: remove channel from sidebar. + */ + evtSource.onmessage = (evt) => { + const data = JSON.parse(evt.data); + + switch (data.type) { + case 'login': + onLoginEvent(data); + break; + case 'channel': + onChannelEvent(data); + break; + case 'message': + onMessageEvent(data); + break; + } + }; + + return evtSource; } function onLoginEvent(data) { - switch (data.event) { - case 'created': - logins.update((value) => value.addLogin(data.id, data.name)) - break; - } + switch (data.event) { + case 'created': + logins.update((value) => value.addLogin(data.id, data.name)); + break; + } } function onChannelEvent(data) { - switch (data.event) { - case 'created': - channelsList.update((value) => value.addChannel(data.id, data.name)) - break; - case 'deleted': - channelsList.update((value) => value.deleteChannel(data.id)); - messages.update((value) => value.deleteChannel(data.id)); - break; - } + switch (data.event) { + case 'created': + channelsList.update((value) => value.addChannel(data.id, data.name)); + break; + case 'deleted': + channelsList.update((value) => value.deleteChannel(data.id)); + messages.update((value) => value.deleteChannel(data.id)); + break; + } } function onMessageEvent(data) { - switch (data.event) { - case 'sent': - messages.update((value) => value.addMessage(data.channel, data.id, data.at, data.sender, data.body)); - break; - case 'deleted': - messages.update((value) => value.deleteMessage(data.id)); - break; - } + switch (data.event) { + case 'sent': + messages.update((value) => + value.addMessage(data.channel, data.id, data.at, data.sender, data.body) + ); + break; + case 'deleted': + messages.update((value) => value.deleteMessage(data.id)); + break; + } } diff --git a/ui/lib/components/ActiveChannel.svelte b/ui/lib/components/ActiveChannel.svelte index 76bf13a..212048a 100644 --- a/ui/lib/components/ActiveChannel.svelte +++ b/ui/lib/components/ActiveChannel.svelte @@ -1,42 +1,42 @@
- {#each chunkBy(messageList, msg => msg.sender) as [sender, messages]} -
- -
- {/each} + {#each chunkBy(messageList, (msg) => msg.sender) as [sender, messages]} +
+ +
+ {/each}
diff --git a/ui/lib/components/Channel.svelte b/ui/lib/components/Channel.svelte index bbe9ff7..60c9092 100644 --- a/ui/lib/components/Channel.svelte +++ b/ui/lib/components/Channel.svelte @@ -1,21 +1,18 @@ -
  • - - # - {name} - +
  • + + # + {name} +
  • diff --git a/ui/lib/components/ChannelList.svelte b/ui/lib/components/ChannelList.svelte index 316e404..f7376c1 100644 --- a/ui/lib/components/ChannelList.svelte +++ b/ui/lib/components/ChannelList.svelte @@ -1,16 +1,16 @@ diff --git a/ui/lib/components/CreateChannelForm.svelte b/ui/lib/components/CreateChannelForm.svelte index b716736..6b50fb1 100644 --- a/ui/lib/components/CreateChannelForm.svelte +++ b/ui/lib/components/CreateChannelForm.svelte @@ -1,23 +1,29 @@
    - - + +
    diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index 03ac7fa..7aac442 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -1,28 +1,38 @@
    - - + +
    diff --git a/ui/lib/components/MessageRun.svelte b/ui/lib/components/MessageRun.svelte index af699ab..4894885 100644 --- a/ui/lib/components/MessageRun.svelte +++ b/ui/lib/components/MessageRun.svelte @@ -1,23 +1,24 @@
    - - @{name}: - - {#each messages as { at, body }} - - {/each} + class="card card-hover m-4 px-4 py-1 relative" + class:own-message={ownMessage} + class:other-message={!ownMessage} +> + + @{name}: + + {#each messages as { at, body }} + + {/each}
    diff --git a/ui/lib/store/messages.js b/ui/lib/store/messages.js index 7d1fbe1..884b296 100644 --- a/ui/lib/store/messages.js +++ b/ui/lib/store/messages.js @@ -4,7 +4,7 @@ export class Messages { } inChannel(channel) { - return this.channels[channel] = (this.channels[channel] || []); + return (this.channels[channel] = this.channels[channel] || []); } addMessage(channel, id, at, sender, body) { @@ -15,12 +15,11 @@ export class Messages { setMessages(messages) { this.channels = {}; for (let { channel, id, at, sender, body } of messages) { - this.inChannel(channel).push({ id, at, sender, body, }); + this.inChannel(channel).push({ id, at, sender, body }); } return this; } - deleteMessage(message) { for (let channel in this.channels) { this.updateChannel(channel, (messages) => messages.filter((msg) => msg.id != message)); diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index ae80324..9843979 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -1,145 +1,147 @@ - understory + understory {#if loading} -

    Loading…

    +

    Loading…

    {:else} -
    - -
    -
    - -
    -
    - -
    -
    -
    +
    + +
    +
    + +
    +
    + +
    +
    +
    {/if} diff --git a/ui/routes/(app)/ch/[channel]/+page.svelte b/ui/routes/(app)/ch/[channel]/+page.svelte index 7bd28d9..74ad28b 100644 --- a/ui/routes/(app)/ch/[channel]/+page.svelte +++ b/ui/routes/(app)/ch/[channel]/+page.svelte @@ -1,10 +1,10 @@
    - +
    diff --git a/ui/routes/(app)/me/+page.svelte b/ui/routes/(app)/me/+page.svelte index 82af3c7..26537ad 100644 --- a/ui/routes/(app)/me/+page.svelte +++ b/ui/routes/(app)/me/+page.svelte @@ -3,9 +3,12 @@ import Invites from '$lib/components/Invites.svelte'; - let currentPassword = "", newPassword = "", confirmPassword = "", passwordForm; + let currentPassword = '', + newPassword = '', + confirmPassword = '', + passwordForm; let pending = false; - $: valid = (newPassword === confirmPassword) && (newPassword !== currentPassword); + $: valid = newPassword === confirmPassword && newPassword !== currentPassword; $: disabled = pending || !valid; async function onPasswordChange() { @@ -20,22 +23,41 @@ } -
    -