diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index f22f624..246c878 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -47,7 +47,7 @@ await formatChannelNames(channels); const channel = channels.find((c: ChannelsType) => c.name === currentChannelName); if (channel) { - //chan.selectChat(channel.id); // disabled as it causes a bug where joining a channel happen twice + chan.selectChat(channel.id); // disabled as it causes a bug where joining a channel happen twice } else { alert("Failed loading channel"); } @@ -167,10 +167,7 @@ setAppState(APPSTATE.CHANNELS); } let selectedChannel: ChannelsType; - let selectedMessages: Array; - const handleSelectChannel = (channel: ChannelsType, messages: Array) => { - selectedChannel = channel; - selectedMessages = messages; + const handleSelectChannel = (channel: ChannelsType) => { setAppState(APPSTATE.CHANNELS + "#" + channel.name); }; @@ -225,8 +222,8 @@ on:keydown={() => setAppState(APPSTATE.CHANNELS)} > ) => void; + export let onSelectChannel: (channel: ChannelsType) => void; let channel: ChannelsType; + export const selectChat = (id: number) => { console.log("channel: ", id) getChannels().then(() => { @@ -126,21 +127,10 @@ } else { show_popup("Did not find channel", false) } + }) }; - socket.on("messages", (msgs: Array) => { - console.log("You are joining channel: ", channel.name) - onSelectChannel(channel, msgs); - channel = undefined; - }); - - socket.on("failedJoin", (error: string) => { - show_popup(`Failed to join channel: ${error}`, false) - channel = undefined; - }); - - const createChannel = async () => { let name: string; let password = ""; @@ -268,7 +258,7 @@
  • {channel.name} : {channel.id}
    - + @@ -15,6 +16,7 @@ export let messages: Array = []; let newText = ""; + export let setAppState: (newState: APPSTATE | string) => void; onMount(async () => { getMembers(); usersInterval = setInterval(async () => { @@ -22,7 +24,6 @@ }, 1000); }); - async function getMembers() { if (!channel) return; let res = await fetch(API_URL + "/users/blocked/", { @@ -42,6 +43,12 @@ messages = [...messages, msg]; }); + socket.on("failedJoin", (error: string) => { + show_popup(`Failed to join channel: ${error}`, false) + setAppState("/channels") + }); + + onDestroy(() => { clearInterval(usersInterval) socket.disconnect();