Browse Source

fix disabled chan update -> moved joinChat to chat comp

master
nicolas-arnaud 2 years ago
parent
commit
33405a7b59
  1. 9
      front/volume/src/App.svelte
  2. 18
      front/volume/src/components/Channels.svelte
  3. 9
      front/volume/src/components/Chat.svelte

9
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<chatMessagesType>;
const handleSelectChannel = (channel: ChannelsType, messages: Array<chatMessagesType>) => {
selectedChannel = channel;
selectedMessages = messages;
const handleSelectChannel = (channel: ChannelsType) => {
setAppState(APPSTATE.CHANNELS + "#" + channel.name);
};
@ -225,8 +222,8 @@
on:keydown={() => setAppState(APPSTATE.CHANNELS)}
>
<Chat
{setAppState}
channel={selectedChannel}
messages={selectedMessages}
on:view-profile={openIdProfile}
on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame}

18
front/volume/src/components/Channels.svelte

@ -115,8 +115,9 @@
//--------------------------------------------------------------------------------/
export let onSelectChannel: (channel: ChannelsType, messages: Array<chatMessagesType>) => 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<chatMessagesType>) => {
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 @@
<li>
<span>{channel.name} : {channel.id}</span>
<div style="display:block; margin-right:10%">
<button on:click={() => selectChat(channel.id)}>🔌</button>
<button on:click={() => onSelectChannel(channel)}>🔌</button>
<button
on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button

9
front/volume/src/components/Chat.svelte

@ -3,6 +3,7 @@
import { store, API_URL } from "../Auth";
import { socket } from "../socket";
import { show_popup, content } from "./Alert/content";
import { APPSTATE } from "../App.svelte";
import type { ChannelsType, chatMessagesType } from "./Channels.svelte";
import type User from "./Profile.svelte";
</script>
@ -15,6 +16,7 @@
export let messages: Array<chatMessagesType> = [];
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();

Loading…
Cancel
Save