From 041ad18a6dcfd3681e78c7a897ea5275eec21968 Mon Sep 17 00:00:00 2001 From: Talon Date: Fri, 23 Aug 2024 22:32:58 +0200 Subject: [PATCH] Fix initial channel creation bug in frontend --- frontend/src/api.ts | 2 +- frontend/src/views/main.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index ad22d7e..a05aa2e 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -45,7 +45,7 @@ export const API = { async createChannel(name: string) { const response = await API.request("POST", "channels", { name }); const json = await response.json(); - return json.channel as IChannel; + return json as IChannel; }, async deleteChannel(id: string) { diff --git a/frontend/src/views/main.ts b/frontend/src/views/main.ts index ada7b86..e05a3b4 100644 --- a/frontend/src/views/main.ts +++ b/frontend/src/views/main.ts @@ -162,7 +162,11 @@ export class MainView extends View { if (state.defaultChannelId) { this.switchChannel(state.defaultChannelId.toString()); } else { - this.switchChannel(state.channelList.channels[0].id.toString()); + if (state.channelList.channels.length > 0) { + this.switchChannel(state.channelList.channels[0].id.toString()); + } else { + this.createNewChannel(); + } } } state.save();