Browse Source

upload avatar, chat fixed, working on change username

master
WalidMoovin 2 years ago
parent
commit
73c9cdfc17
  1. 1
      back/volume/src/main.ts
  2. 2
      back/volume/src/users/dto/user.dto.ts
  3. BIN
      front/volume/public/img/profileicon.png
  4. 17
      front/volume/src/components/Channels.svelte
  5. 11
      front/volume/src/components/Chat2.svelte
  6. 3
      front/volume/src/components/NavBar.svelte
  7. 73
      front/volume/src/components/Profile.svelte

1
back/volume/src/main.ts

@ -7,6 +7,7 @@ import * as session from 'express-session'
import * as passport from 'passport' import * as passport from 'passport'
import { type NestExpressApplication } from '@nestjs/platform-express' import { type NestExpressApplication } from '@nestjs/platform-express'
import * as cookieParser from 'cookie-parser' import * as cookieParser from 'cookie-parser'
import { Response } from 'express';
async function bootstrap () { async function bootstrap () {
const logger = new Logger() const logger = new Logger()

2
back/volume/src/users/dto/user.dto.ts

@ -5,7 +5,7 @@ import { Express } from 'express'
export class UserDto { export class UserDto {
@IsPositive() @IsPositive()
@IsNotEmpty() @IsOptional()
readonly ftId: number readonly ftId: number
@IsString() @IsString()

BIN
front/volume/public/img/profileicon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

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

@ -3,6 +3,8 @@
export interface ChannelsType { export interface ChannelsType {
id: string; id: string;
name: string; name: string;
privacy: string;
password: string;
messages: Array<chatMessagesType>; messages: Array<chatMessagesType>;
} }
</script> </script>
@ -19,13 +21,28 @@
const createChannel = () => { const createChannel = () => {
const name = prompt("Enter a name for the new channel:"); const name = prompt("Enter a name for the new channel:");
if (name) { if (name) {
const privacy = prompt("Enter a privacy setting for the new channel (public/private):");
if (privacy !== "public" && privacy !== "private") {
alert("Invalid privacy setting");
}
let password = "";
if (privacy === "private") {
password = prompt("Enter a password for the new channel:");
if (!password) {
alert("Invalid password");
}
}
if (privacy === "public" || password) {
const newChannel: ChannelsType = { const newChannel: ChannelsType = {
id: Math.random().toString(), id: Math.random().toString(),
name, name,
privacy,
password,
messages: [] messages: []
}; };
channels = [newChannel, ...channels]; channels = [newChannel, ...channels];
} }
}
// TODO: save to database // TODO: save to database
}; };
</script> </script>

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

@ -95,15 +95,4 @@
height: 200px; height: 200px;
overflow-y: scroll; overflow-y: scroll;
} }
.options-modal {
position: absolute;
top: 0;
left: 0;
background-color: white;
padding: 1rem;
border: 1px solid #ccc;
border-radius: 5px;
z-index: 9999;
}
</style> </style>

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

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
let api = "http://" + import.meta.env.VITE_HOST + ":" + import.meta.env.VITE_BACK_PORT;
export let links = [ export let links = [
{ text: "Home", url: "img/pong.png" }, { text: "Home", url: "img/pong.png" },
{ text: "Spectate" }, { text: "Spectate" },
@ -41,7 +42,7 @@
{#if link.text === "Profile"} {#if link.text === "Profile"}
<li> <li>
<button on:click={clickProfile}> <button on:click={clickProfile}>
<img src="img/profileicon.png" alt="profile icon" /> <img src={api + '/avatar'} alt="avatar" />
</button> </button>
</li> </li>
{/if} {/if}

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

@ -1,3 +1,9 @@
<script lang="ts" context="module">
export interface User {
username: string;
}
</script>
<script lang="ts"> <script lang="ts">
let api = "http://" + import.meta.env.VITE_HOST + ":" + import.meta.env.VITE_BACK_PORT let api = "http://" + import.meta.env.VITE_HOST + ":" + import.meta.env.VITE_BACK_PORT
export let username = ""; export let username = "";
@ -7,45 +13,21 @@
export let elo = 0; export let elo = 0;
export let rank = -1; export let rank = -1;
export let is2faEnabled = false; export let is2faEnabled = false;
async function handleSubmit(event: Event) { export let avatar = api + "/avatar";
event.preventDefault(); const handleSubmit = () => {
// const response = await fetch('', { const user: User = { username : username};
// method: 'POST', fetch("http://localhost:3001/", {
// headers: { method: "POST",
// 'Content-Type': 'application/json' body: JSON.stringify(user),
// }, credentials: 'include'
// body: JSON.stringify({ })
// username .then((res) => res.json())
// }) .then((data) => {
// });
// if (response.ok) {
// console.log('username updated');
// }
// else {
// console.log('username update failed');
// }
alert("Trying to update username to " + username);
}
async function handleAvatarUpload(event: Event) {
event.preventDefault();
const fileInput = document.getElementById('avatar-input') as HTMLInputElement;
const file = fileInput.files[0];
const formData = new FormData();
formData.append('avatar', file);
try {
const response = await fetch(api + '/avatar', {
method: 'POST',
body: formData,
mode: 'cors'
});
const data = await response.json();
console.log(data); console.log(data);
} catch (error) { })
console.error(error); .catch((err) => {
} console.error(err);
});
} }
async function handle2fa(event: Event) { async function handle2fa(event: Event) {
event.preventDefault(); event.preventDefault();
@ -56,16 +38,19 @@
<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={avatar} alt="avatar" />
<h3>{realname}</h3> <h3>{realname}</h3>
<form on:submit={handleAvatarUpload}> <form action="http://localhost:3001/avatar"
<label for="avatar-input">Choose avatar:</label> method="post"
<input type="file" id="avatar-input" accept="image/*"> enctype="multipart/form-data">
<button type="submit" id="upload-button">Upload</button> <label for="mavatar-input">Select a file:</label>
<input type="file" id="avatar-input" name="avatar" />
<br /><br />
<input type="submit" />
</form> </form>
</div> </div>
<div class="profile-body"> <div class="profile-body">
<form on:submit={handleSubmit}> <form on:submit|preventDefault={handleSubmit}>
<div class="username"> <div class="username">
<label for="username">Username</label> <label for="username">Username</label>
<input type="text" id="username" bind:value={username} /> <input type="text" id="username" bind:value={username} />

Loading…
Cancel
Save