WalidMoovin 2 years ago
parent
commit
d3f011b3f0
  1. 2
      back/volume/src/types.d.ts
  2. 17
      front/volume/src/App.svelte
  3. 48
      front/volume/src/components/Chat2.svelte
  4. 54
      front/volume/src/components/Leaderboard.svelte
  5. 9
      front/volume/src/components/NavBar.svelte

2
back/volume/src/types.d.ts

@ -1,5 +1,5 @@
declare module 'passport-42' { declare module 'passport-42' {
export type Profile = any export type Profile = any
export type VerifyCallback = any export type VerifyCallback = any
export class Strategy {}! export class Strategy {}
} }

17
front/volume/src/App.svelte

@ -12,6 +12,7 @@
import Chat2 from "./components/Chat2.svelte"; import Chat2 from "./components/Chat2.svelte";
import Channels from "./components/Channels.svelte"; import Channels from "./components/Channels.svelte";
import type { ChannelsType } from "./components/Channels.svelte"; import type { ChannelsType } from "./components/Channels.svelte";
import Leaderboard from "./components/Leaderboard.svelte";
import { store, getUser, login, logout, API_URL } from "./Auth"; import { store, getUser, login, logout, API_URL } from "./Auth";
@ -110,6 +111,13 @@
const handleSelectChannel = (channel: ChannelsType) => { const handleSelectChannel = (channel: ChannelsType) => {
selectedChannel = channel; selectedChannel = channel;
}; };
// LEADERBOARD
let isLeaderboardOpen = false;
function clickLeaderboard() {
isLeaderboardOpen = true;
}
</script> </script>
<main> <main>
@ -123,6 +131,7 @@
{clickFriends} {clickFriends}
{clickSpectate} {clickSpectate}
{clickChannels} {clickChannels}
{clickLeaderboard}
/> />
{#if isChannelsOpen} {#if isChannelsOpen}
{#if selectedChannel} {#if selectedChannel}
@ -150,6 +159,14 @@
<Spectate {spectate} /> <Spectate {spectate} />
</div> </div>
{/if} {/if}
{#if isLeaderboardOpen}
<div
on:click={() => (isLeaderboardOpen = false)}
on:keydown={() => (isLeaderboardOpen = false)}
>
<Leaderboard />
</div>
{/if}
{#if isFriendOpen} {#if isFriendOpen}
<div <div
on:click={() => { on:click={() => {

48
front/volume/src/components/Chat2.svelte

@ -4,6 +4,7 @@
name: string; name: string;
text: string; text: string;
} }
import { createEventDispatcher, onMount } from "svelte";
</script> </script>
<script lang="ts"> <script lang="ts">
@ -27,25 +28,18 @@
export let chatMessages: Array<chatMessagesType> = []; export let chatMessages: Array<chatMessagesType> = [];
let newText = ""; let newText = "";
const openProfile = (id: number) => (event: Event) => { const dispatch = createEventDispatcher();
const message = chatMessages.find((m) => m.id === id); let showProfileMenu = false;
if (message) { let selectedUserId = null;
const optionsModal = document.createElement("div"); function openProfile(id : number) {
optionsModal.classList.add("options-modal"); showProfileMenu = true;
optionsModal.innerHTML = ` selectedUserId = id;
<h3>${message.name}</h3>
<ul>
<li>View profile</li>
<li>View posts</li>
<li>View comments</li>
</ul>
`;
document.querySelector(".overlay")?.appendChild(optionsModal);
optionsModal.addEventListener("click", () => {
document.body.removeChild(optionsModal);
});
} }
}; function closeProfileMenu() {
showProfileMenu = false;
selectedUserId = null;
}
onMount(closeProfileMenu)
</script> </script>
<div class="overlay"> <div class="overlay">
@ -64,6 +58,24 @@
</p> </p>
{/each} {/each}
</div> </div>
{#if showProfileMenu}
<div class="profile-menu" on:click|stopPropagation on:keydown|stopPropagation>
<ul>
<!-- if admin
<li><button on:click={() => dispatch('delete-user', selectedUserId)}>Delete User</button></li>
<li><button on:click={() => dispatch('ban-user', selectedUserId)}>Ban User</button></li>
<li><button on:click={() => dispatch('mute-user', selectedUserId)}>Mute User</button></li>
<li><button on:click={() => dispatch('promote-user', selectedUserId)}>Promote User</button></li>
-->
<li><button on:click={() => dispatch('send-message', selectedUserId)}>Send Message</button></li>
<li><button on:click={() => dispatch('view-profile', selectedUserId)}>View Profile</button></li>
<li><button on:click={() => dispatch('add-friend', selectedUserId)}>Add Friend</button></li>
<li><button on:click={() => dispatch('invite-to-game', selectedUserId)}>Invite to Game</button></li>
<li><button on:click={() => dispatch('block-user', selectedUserId)}>Block User</button></li>
<li><button on:click={closeProfileMenu}>Close</button></li>
</ul>
</div>
{/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>

54
front/volume/src/components/Leaderboard.svelte

@ -0,0 +1,54 @@
<script lang="ts" context="module">
export interface Player {
username: string;
wins: number;
losses: number;
rank: number;
}
</script>
<script lang="ts">
export let leaderboard: Array<Player> = [];
</script>
<div class="overlay">
<div class="history" on:click|stopPropagation on:keydown|stopPropagation>
<div>
{#if leaderboard.length > 0}
<h2>Leaderboard</h2>
{#each leaderboard.slice(0, 10) as match}
<li>
<span>{match.username}</span>
<span>{match.wins} - {match.losses}</span>
<span>MP | rank #{match.rank}</span>
</li>
{/each}
{:else}
<p>No Players to display</p>
{/if}
</div>
</div>
</div>
<style>
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9998;
display: flex;
justify-content: center;
align-items: center;
}
.history {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 1rem;
width: 300px;
}
</style>

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

@ -10,6 +10,7 @@
{ text: "Channels" }, { text: "Channels" },
{ text: "History" }, { text: "History" },
{ text: "Friends" }, { text: "Friends" },
{ text: "Leaderboard"},
{ text: "Profile" }, { text: "Profile" },
]; ];
export let clickProfile = () => {}; export let clickProfile = () => {};
@ -17,11 +18,19 @@
export let clickFriends = () => {}; export let clickFriends = () => {};
export let clickSpectate = () => {}; export let clickSpectate = () => {};
export let clickChannels = () => {}; export let clickChannels = () => {};
export let clickLeaderboard = () => {};
</script> </script>
<nav class="navigation-bar"> <nav class="navigation-bar">
<ul> <ul>
{#each links as link} {#each links as link}
{#if link.text === "Leaderboard"}
<li>
<button on:click={clickLeaderboard}>
<p>Leaderboard</p>
</button>
</li>
{/if}
{#if link.text === "Spectate"} {#if link.text === "Spectate"}
<li> <li>
<button on:click={clickSpectate}> <button on:click={clickSpectate}>

Loading…
Cancel
Save