Browse Source

* Chat fixes

* Some CSS
master
vvandenb 2 years ago
parent
commit
2414a18e87
  1. 16
      front/volume/src/App.svelte
  2. 3
      front/volume/src/components/Channels.svelte
  3. 42
      front/volume/src/components/Chat.svelte
  4. 2
      front/volume/src/components/Friends.svelte
  5. 3
      front/volume/src/components/Pong/GameCreation.svelte
  6. 3
      front/volume/src/components/Pong/Matchmaking.svelte
  7. 1
      front/volume/src/components/Pong/Pong.svelte
  8. 2
      front/volume/src/components/Profile.svelte

16
front/volume/src/App.svelte

@ -81,7 +81,6 @@
return null; return null;
} }
let chan: Channels;
async function openDirectChat(event: CustomEvent<string>) { async function openDirectChat(event: CustomEvent<string>) {
const DMUsername = event.detail; const DMUsername = event.detail;
let DMChannel: Array<ChannelsType> = []; let DMChannel: Array<ChannelsType> = [];
@ -89,7 +88,8 @@
if (res && res.ok) { if (res && res.ok) {
DMChannel = await res.json(); DMChannel = await res.json();
if (DMChannel.length != 0) if (DMChannel.length != 0)
chan.selectChat(DMChannel[0].id); await formatChannelNames(DMChannel)
setAppState(APPSTATE.CHANNELS + "#" + DMChannel[0].name)
} else { } else {
console.log("Creating DMChannel: " + $store.username + "&" + DMUsername) console.log("Creating DMChannel: " + $store.username + "&" + DMUsername)
fetch(API_URL + "/channels", { fetch(API_URL + "/channels", {
@ -112,14 +112,15 @@
if (response && response.ok) { if (response && response.ok) {
DMChannel = await response.json(); DMChannel = await response.json();
if (DMChannel.length != 0) { if (DMChannel.length != 0) {
chan.selectChat(DMChannel[0].id); await formatChannelNames(DMChannel)
setAppState(APPSTATE.CHANNELS + "#" + DMChannel[0].name)
} else { } else {
alert("Error creating DM"); alert("Error creating DM");
} }
} else { } else {
alert("Error creating DM"); alert("Error creating DM");
} }
}).catch((error) => { }).catch(() => {
alert("Error creating DM"); alert("Error creating DM");
}) })
} }
@ -192,13 +193,15 @@
{clickLeaderboard} {clickLeaderboard}
/> />
{#if appState.includes(`${APPSTATE.CHANNELS}#`)} {#if appState.includes(`${APPSTATE.CHANNELS}#`)}
{#key appState}
<div <div
on:click={() => setAppState(APPSTATE.CHANNELS)} on:click={() => setAppState(APPSTATE.CHANNELS)}
on:keydown={() => setAppState(APPSTATE.CHANNELS)} on:keydown={() => setAppState(APPSTATE.CHANNELS)}
> >
<Chat <Chat
{appState}
{setAppState} {setAppState}
channel={selectedChannel} bind:channel={selectedChannel}
on:view-profile={openIdProfile} on:view-profile={openIdProfile}
on:add-friend={addFriend} on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame} on:invite-to-game={pong.inviteToGame}
@ -206,6 +209,7 @@
on:return-home={resetAppState} on:return-home={resetAppState}
/> />
</div> </div>
{/key}
{/if} {/if}
{#if appState.includes(APPSTATE.CHANNELS)} {#if appState.includes(APPSTATE.CHANNELS)}
<div <div
@ -213,7 +217,7 @@
on:click={resetAppState} on:click={resetAppState}
on:keydown={resetAppState} on:keydown={resetAppState}
> >
<Channels bind:this={chan} onSelectChannel={handleSelectChannel} /> <Channels onSelectChannel={handleSelectChannel} />
</div> </div>
{/if} {/if}
{#if appState === APPSTATE.LEADERBOARD} {#if appState === APPSTATE.LEADERBOARD}

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

@ -281,8 +281,7 @@
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
width: 500px; width: 500px;
overflow-y: scroll; overflow: auto;
overflow-x: auto;
max-height: 80%; max-height: 80%;
} }

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

@ -4,26 +4,49 @@
import { io, Socket } from "socket.io-client"; import { io, Socket } from "socket.io-client";
import { show_popup, content } from "./Alert/content"; import { show_popup, content } from "./Alert/content";
import { APPSTATE } from "../App.svelte"; import { APPSTATE } from "../App.svelte";
import type { ChannelsType, chatMessagesType } from "./Channels.svelte"; import { formatChannelNames, type ChannelsType, type chatMessagesType } from "./Channels.svelte";
import type User from "./Profile.svelte"; import type User from "./Profile.svelte";
</script> </script>
<script lang="ts"> <script lang="ts">
let usersInterval: ReturnType<typeof setInterval>;
let blockedUsers: Array<User> = [];
let chatMembers: Array<User> = [];
export let channel: ChannelsType; export let channel: ChannelsType;
export let messages: Array<chatMessagesType> = []; export let messages: Array<chatMessagesType> = [];
let newText = ""; export let appState: string;
export let setAppState: (newState: APPSTATE | string) => void; export let setAppState: (newState: APPSTATE | string) => void;
let socket: Socket; let socket: Socket;
let newText = "";
let usersInterval: ReturnType<typeof setInterval>;
let blockedUsers: Array<User> = [];
let chatMembers: Array<User> = [];
async function getCurrentChannel() {
const res = await fetch(API_URL + "/channels", {
credentials: "include",
mode: "cors",
});
if (res.ok) {
const newChannels: Array<ChannelsType> = await res.json();
await formatChannelNames(newChannels);
newChannels.forEach((newChannel) => {
const urlSplit = appState.split("#", 2)
if (urlSplit.length > 1) {
const currentChannelName = appState.split("#", 2)[1];
if (newChannel.name === currentChannelName) {
channel = newChannel;
}
}
});
}
}
onMount(async () => { onMount(async () => {
socket = io( socket = io(
"http://" + (import.meta.env.VITE_HOST ?? "localhost") + ":3001" "http://" + (import.meta.env.VITE_HOST ?? "localhost") + ":3001"
); );
socket.connect(); socket.connect();
if (!channel) setAppState("/channels"); await getCurrentChannel();
if (!channel) setAppState(APPSTATE.CHANNELS);
if (!channel.password) { if (!channel.password) {
socket.emit("joinChannel", { socket.emit("joinChannel", {
UserId: $store.ftId, UserId: $store.ftId,
@ -442,6 +465,7 @@
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
max-width: 90%; max-width: 90%;
max-height: 80vh;
width: auto; width: auto;
margin: auto; margin: auto;
display: flex; display: flex;
@ -451,7 +475,7 @@
.messages { .messages {
height: 400px; height: 400px;
width: 100%; width: 100%;
overflow-y: scroll; overflow-y: auto;
border-bottom: 1px solid #dedede; border-bottom: 1px solid #dedede;
padding-bottom: 1rem; padding-bottom: 1rem;
} }
@ -509,7 +533,7 @@
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
max-height: 70%; max-height: 70%;
overflow-y: scroll; overflow-y: auto;
z-index: 1; z-index: 1;
} }

2
front/volume/src/components/Friends.svelte

@ -121,6 +121,8 @@
padding: 1rem; padding: 1rem;
width: 300px; width: 300px;
color: #e8e6e3; color: #e8e6e3;
max-height: 80vh;
overflow: auto;
} }
h2, h2,

3
front/volume/src/components/Pong/GameCreation.svelte

@ -79,6 +79,9 @@
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
width: 50vw; width: 50vw;
max-width: 80vw;
max-height: 80vh;
overflow: auto;
} }
.name-input { .name-input {

3
front/volume/src/components/Pong/Matchmaking.svelte

@ -28,5 +28,8 @@
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
max-width: 80vw;
max-height: 80vh;
overflow: auto;
} }
</style> </style>

1
front/volume/src/components/Pong/Pong.svelte

@ -224,6 +224,7 @@
h1 { h1 {
margin-bottom: 2rem; margin-bottom: 2rem;
text-align: center;
} }
button { button {

2
front/volume/src/components/Profile.svelte

@ -169,6 +169,8 @@
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;
max-width: 80%; max-width: 80%;
max-height: 80vh;
overflow: auto;
width: 375px; width: 375px;
color: #e8e6e3; color: #e8e6e3;
} }

Loading…
Cancel
Save