Browse Source

Front reformat / error fixing / passing channel prop to chat component

master
WalidMoovin 2 years ago
parent
commit
5e111fbc7a
  1. 1
      front/volume/src/App.svelte
  2. 12
      front/volume/src/components/Channels.svelte
  3. 85
      front/volume/src/components/Chat.svelte
  4. 8
      front/volume/src/components/NavBar.svelte

1
front/volume/src/App.svelte

@ -136,6 +136,7 @@
on:keydown={() => setAppState(APPSTATE.CHANNELS)} on:keydown={() => setAppState(APPSTATE.CHANNELS)}
> >
<Chat <Chat
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}

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

@ -1,5 +1,4 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
export interface ChannelsType { export interface ChannelsType {
id: number; id: number;
name: string; name: string;
@ -10,8 +9,6 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import { API_URL, store } from "../Auth"; import { API_URL, store } from "../Auth";
import { io } from "../socket"; import { io } from "../socket";
import Select from 'svelte-select';
</script> </script>
<script lang="ts"> <script lang="ts">
@ -171,9 +168,7 @@
<div> <div>
<select bind:value={channelMode} > <select bind:value={channelMode} >
{#each channelOptions as option} {#each channelOptions as option}
<option value={option} selected={channelMode === option}> <option value={option} selected={channelMode === option}>{option}</option>
{option}
</option>
{/each} {/each}
</select> </select>
{#if channelMode!= ''} {#if channelMode!= ''}
@ -236,10 +231,11 @@
appearance: none; appearance: none;
cursor: pointer; cursor: pointer;
} }
span { span {
color: rgb(0, 0, 0); color: rgb(0, 0, 0);
font-size: 150%; /* Taille de la police en pourcentage */ font-size: 150%;
position: relative; /* Positionnement relatif */ position: relative;
padding: 10px; padding: 10px;
top: 2px; top: 2px;
} }

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

@ -94,7 +94,6 @@ import type User from "./Profile.svelte";
method: "POST", method: "POST",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
alert("User blocked"); alert("User blocked");
} else { } else {
@ -115,7 +114,6 @@ import type User from "./Profile.svelte";
method: "DELETE", method: "DELETE",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
alert("User unblocked"); alert("User unblocked");
} else { } else {
@ -137,7 +135,6 @@ import type User from "./Profile.svelte";
method: "POST", method: "POST",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
io.emit("kickUser", channel.id, $store.ftId, data1.ftId); io.emit("kickUser", channel.id, $store.ftId, data1.ftId);
alert("User banned"); alert("User banned");
@ -171,7 +168,6 @@ import type User from "./Profile.svelte";
method: "POST", method: "POST",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
alert("User muted"); alert("User muted");
} else { } else {
@ -192,7 +188,6 @@ import type User from "./Profile.svelte";
method: "POST", method: "POST",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
alert("User admined"); alert("User admined");
} else { } else {
@ -213,7 +208,6 @@ import type User from "./Profile.svelte";
method: "DELETE", method: "DELETE",
mode: "cors", mode: "cors",
}); });
const data2 = await res2.json();
if (res2.ok) { if (res2.ok) {
alert("User admin removed"); alert("User admin removed");
} else { } else {
@ -224,6 +218,7 @@ import type User from "./Profile.svelte";
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
</script> </script>
<div class="overlay" > <div class="overlay" >
<div class="chat" on:click|stopPropagation on:keydown|stopPropagation> <div class="chat" on:click|stopPropagation on:keydown|stopPropagation>
<div class="messages" > <div class="messages" >
@ -238,11 +233,9 @@ import type User from "./Profile.svelte";
> >
{ message.author } { message.author }
</span>: {message.text} </span>: {message.text}
{ {/if}
/if}
</p> </p>
{ {/each}
/each}
</div> </div>
{ #if showProfileMenu } { #if showProfileMenu }
<div <div
@ -252,89 +245,57 @@ import type User from "./Profile.svelte";
> >
<ul> <ul>
<li> <li>
<button on:click = {() => dispatch("send-message", selectedUser) <button on:click = {() => dispatch("send-message", selectedUser)}> Send Message </button>
}
> Send Message </button
>
</li> </li>
<li> <li>
<button on:click = {() => dispatch("view-profile", selectedUser) <button on:click = {() => dispatch("view-profile", selectedUser)}> View Profile </button>
}
> View Profile </button
>
</li> </li>
<li> <li>
<button on:click = {() => dispatch("add-friend", selectedUser)} <button on:click = {() => dispatch("add-friend", selectedUser)}> Add Friend </button>
> Add Friend </button
>
</li> </li>
<li> <li>
<button on:click = {() => dispatch("invite-to-game", selectedUser)} <button on:click = {() => dispatch("invite-to-game", selectedUser)}> Invite to Game </button>
> Invite to Game </button
>
</li> </li>
<li> <li>
{ #if !blockedUsers.filter((user) => user.username = selectedUser).length } { #if !blockedUsers.filter((user) => user.username = selectedUser).length }
<button on:click = {() => blockUser(selectedUser)}> Block User </button> <button on:click = {() => blockUser(selectedUser)}> Block User </button>
{:else } {:else }
<button on:click = {() => unblockUser(selectedUser)}> Unblock User </button> <button on:click = {() => unblockUser(selectedUser)}> Unblock User </button>
{ {/if}
/if}
</li> </li>
<li> <button on:click = { closeProfileMenu } > Close </button></li > <li> <button on:click = { closeProfileMenu } > Close </button></li >
</ul> </ul>
</div> </div>
{ {/if}
/if}
<form on:submit|preventDefault={ sendMessage }> <form on:submit|preventDefault={ sendMessage }>
<input type="text" placeholder = "Type a message..." bind:value={ newText } /> <input type="text" placeholder = "Type a message..." bind:value={ newText } />
<button> <button>
<img src="img/send.png" alt = "send" /> <img src="img/send.png" alt = "send" />
</button> </button>
</form> </form>
<button <button on:click|stopPropagation={ toggleChatMembers } on:keydown|stopPropagation > Chat Members </button>
on:click|stopPropagation={ toggleChatMembers }
on:keydown|stopPropagation > Chat Members </button
>
{ #if showChatMembers } { #if showChatMembers }
<div <div
class="chatMembers" class="chatMembers"
on:click|stopPropagation on:click|stopPropagation
on:keydown|stopPropagation on:keydown|stopPropagation
> >
<div> </div>
<ul> <ul>
{ #each chatMembers as member } { #each chatMembers as member }
<li> <li>
<p> <p>
{ member.username } { member.username }
<button on:click = {() => banUser(member.username) <button on:click = {() => banUser(member.username)}> ban </button>
}> ban </button> <button on:click = {() => kickUser(member.username)}> kick </button>
<button on:click = {() => kickUser(member.username) <button on:click = {() => muteUser(member.username)}> mute </button>
} <button on:click = {() => adminUser(member.username)}> promote </button>
> kick </button <button on:click = {() => removeAdminUser(member.username)}> demote </button>
>
<button on:click = {() => muteUser(member.username)}
> mute </button
>
<button on:click = {() => adminUser(member.username)}
> promote </button
>
<button on:click = {() => removeAdminUser(member.username)}
> demote </button
>
</p>
<p>
-----------------------------------------------------------------------------------
</p> </p>
</li> </li>
{ {/each}
/each}
</ul> </ul>
</div> {/if}
</div>
{
/if}
</div> </div>
</div> </div>
@ -373,14 +334,4 @@ import type User from "./Profile.svelte";
max-height: 100px; max-height: 100px;
overflow-y: scroll; overflow-y: scroll;
} }
.chatMembers ul {
list-style: none;
padding: 0;
margin: 0;
}
.chatMembers button {
width: 6rem;
}
</style> </style>

8
front/volume/src/components/NavBar.svelte

@ -1,9 +1,6 @@
<script lang="ts"> <script lang="ts">
let api = let api = "http://" + import.meta.env.VITE_HOST + ":" + import.meta.env.VITE_BACK_PORT;
"http://" +
import.meta.env.VITE_HOST +
":" +
import.meta.env.VITE_BACK_PORT;
export let links = [ export let links = [
{ text: "Home" }, { text: "Home" },
{ text: "Channels" }, { text: "Channels" },
@ -12,6 +9,7 @@
{ text: "Leaderboard" }, { text: "Leaderboard" },
{ text: "Profile" }, { text: "Profile" },
]; ];
export let clickProfile = () => {}; export let clickProfile = () => {};
export let clickHistory = () => {}; export let clickHistory = () => {};
export let clickFriends = () => {}; export let clickFriends = () => {};

Loading…
Cancel
Save