Browse Source

some form button handling

master
WalidMoovin 2 years ago
parent
commit
8086a30145
  1. 2
      src/App.svelte
  2. 71
      src/components/Profile.svelte

2
src/App.svelte

@ -30,7 +30,7 @@
{username : "Bob", status : "online"}, {username : "Bob", status : "online"},
{username : "Charlie", status : "offline"}, {username : "Charlie", status : "offline"},
{username : "Dave", status : "offline"}, {username : "Dave", status : "offline"},
{username : "Eve", status : "online"}, {username : "Eve", status : "in a game"},
{username : "Frank", status : "online"}, {username : "Frank", status : "online"},
] ]
let isSpectateOpen = false; let isSpectateOpen = false;

71
src/components/Profile.svelte

@ -1,36 +1,71 @@
<script> <script>
export let username = ''; export let username = '';
export let realname = '';
export let wins = 0; export let wins = 0;
export let losses = 0; export let losses = 0;
export let elo = 0; export let elo = 0;
export let rank = -1; export let rank = -1;
export let is2faEnabled = false; export let is2faEnabled = false;
function toggle2fa() { async function handleSubmit (event) {
is2faEnabled = !is2faEnabled; event.preventDefault();
// const res = await fetch('', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({
// username
// })
// });
// if (res.ok) {
// console.log('username updated');
// }
// else {
// console.log('username update failed');
// }
alert('Trying to update username to ' + username);
}
async function handleAvatarUpload (event) {
event.preventDefault();
alert('Trying to upload avatar');
}
async function handle2fa (event) {
event.preventDefault();
alert('Trying to ' + (is2faEnabled ? 'disable' : 'enable') + ' 2FA');
} }
</script> </script>
<div class="overlay"> <div class="overlay">
<div class="profile" on:click|stopPropagation on:keydown|stopPropagation> <div class="profile" on:click|stopPropagation on:keydown|stopPropagation>
<div class="profile-header"> <div class="profile-header">
<img class="profile-img" src="img/profileicon.png" alt="Profile Icon"> <img class="profile-img" src="img/profileicon.png" alt="Profile Icon">
<h3>{username}</h3> <h3>{realname}</h3>
<button>Upload avatar</button> <form on:submit={handleAvatarUpload}>
<button type="submit">Upload Avatar</button>
</form>
</div> </div>
<div class="profile-body"> <div class="profile-body">
<p>Wins: {wins}</p> <form on:submit={handleSubmit}>
<p>Losses: {losses}</p> <div class="username">
<p>Winrate: {wins / (wins + losses) * 100}%</p> <label for="username">Username</label>
<p>Elo : {elo}</p> <input type="text" id="username" bind:value={username} />
<p>Rank: {rank}</p> </div>
<div class="two-factor-auth"> <button type="submit">Submit</button>
<button on:click={toggle2fa}> </form>
{#if is2faEnabled} <p>Wins: {wins}</p>
Disable 2FA <p>Losses: {losses}</p>
{:else} <p>Winrate: {wins / (wins + losses) * 100}%</p>
Enable 2FA <p>Elo : {elo}</p>
{/if} <p>Rank: {rank}</p>
</div> <form class="two-factor-auth" on:submit={handle2fa}>
<button type="submit">
{#if is2faEnabled}
Disable 2FA
{:else}
Enable 2FA
{/if}
</button>
</form>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save