Browse Source

adding friends, some cleaning

master
WalidMoovin 2 years ago
parent
commit
14c0caa61b
  1. 4
      src/App.svelte
  2. 27
      src/components/Friends.svelte
  3. 12
      src/components/MatchHistory.svelte
  4. 4
      src/components/Profile.svelte
  5. 2
      src/components/Spectate.svelte

4
src/App.svelte

@ -14,10 +14,10 @@
isHistoryOpen = true; isHistoryOpen = true;
} }
let matches = [ let matches = [
{winner : "Alice", loser : "Bob", points : "-5", rank : "22"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"}, {winner : "Alice", loser : "Bob", points : "10", rank : "24"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"}, {winner : "Alice", loser : "Bob", points : "10", rank : "24"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"}, {winner : "Alice", loser : "Bob", points : "7", rank : "23"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"}, {winner : "Alice", loser : "Bob", points : "10", rank : "24"},
{winner : "Alice", loser : "Bob", points : "10", rank : "24"}, {winner : "Alice", loser : "Bob", points : "10", rank : "24"},
] ]

27
src/components/Friends.svelte

@ -1,11 +1,31 @@
<script> <script>
export let friends = []; export let friends = [];
async function addFriend(event) {
event.preventDefault();
const usernameInput = event.target.querySelector('input[type="text"]');
const username = usernameInput.value;
// const response = await fetch('', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({ username })
// });
// if (response.ok) {
// console.log('Friend added successfully');
// } else {
// console.log('Failed to add friend');
// }
// usernameInput.value = '';
alert('Trying to add friend' + username);
}
</script> </script>
<div class="overlay"> <div class="overlay">
<div class="friends" on:click|stopPropagation on:keydown|stopPropagation> <div class="friends" on:click|stopPropagation on:keydown|stopPropagation>
<div> <div>
{#if friends.length > 0} {#if friends.length > 0}
<h2>Monkey friends</h2>
{#each friends.slice(0, 10) as friends} {#each friends.slice(0, 10) as friends}
<li> <li>
<span>{friends.username} is {friends.status}</span> <span>{friends.username} is {friends.status}</span>
@ -14,6 +34,13 @@
{:else} {:else}
<p>No friends to display</p> <p>No friends to display</p>
{/if} {/if}
<div>
<h3>Add a friend</h3>
<form on:submit={addFriend}>
<input type="text" />
<button type="submit">Add</button>
</form>
</div>
</div> </div>
</div> </div>
</div> </div>

12
src/components/MatchHistory.svelte

@ -6,12 +6,16 @@
<div class="history" on:click|stopPropagation on:keydown|stopPropagation> <div class="history" on:click|stopPropagation on:keydown|stopPropagation>
<div> <div>
{#if matches.length > 0} {#if matches.length > 0}
<h2>Last 10 monkey games</h2>
{#each matches.slice(0, 10) as match} {#each matches.slice(0, 10) as match}
<li> <li>
<span>{match.winner} vs {match.loser}</span> <span>{match.winner} 1 - 0 {match.loser}</span>
<span>{match.winner} won 1-0</span> {#if match.points > 0}
<span>points won : {match.points}</span> <span>+{match.points}</span>
<span>rank #{match.rank}</span> {:else}
<span>{match.points}</span>
{/if}
<span>MP | rank #{match.rank}</span>
</li> </li>
{/each} {/each}
{:else} {:else}

4
src/components/Profile.svelte

@ -8,7 +8,7 @@
export let is2faEnabled = false; export let is2faEnabled = false;
async function handleSubmit (event) { async function handleSubmit (event) {
event.preventDefault(); event.preventDefault();
// const res = await fetch('', { // const response = await fetch('', {
// method: 'POST', // method: 'POST',
// headers: { // headers: {
// 'Content-Type': 'application/json' // 'Content-Type': 'application/json'
@ -17,7 +17,7 @@
// username // username
// }) // })
// }); // });
// if (res.ok) { // if (response.ok) {
// console.log('username updated'); // console.log('username updated');
// } // }
// else { // else {

2
src/components/Spectate.svelte

@ -7,6 +7,7 @@
<div class="spectate" on:click|stopPropagation on:keydown|stopPropagation> <div class="spectate" on:click|stopPropagation on:keydown|stopPropagation>
<div> <div>
{#if spectate.length > 0} {#if spectate.length > 0}
<h2>Monkey spectating</h2>
{#each spectate.slice(0, 10) as spectate} {#each spectate.slice(0, 10) as spectate}
<li> <li>
<span>{spectate.player1} VS {spectate.player2}</span> <span>{spectate.player1} VS {spectate.player2}</span>
@ -41,4 +42,5 @@
padding: 1rem; padding: 1rem;
width: 300px; width: 300px;
} }
</style> </style>
Loading…
Cancel
Save