ok so i fixed the get user by username issue, left all the comments in the back so Cherif and I can go over what i changed just to make sure i didn't break something else, but yea that and my front work just fine

This commit is contained in:
Me
2022-12-11 06:04:03 +01:00
parent 61828e5be7
commit 6eeb2b5474
6 changed files with 107 additions and 48 deletions

View File

@@ -30,7 +30,6 @@ could be a list of friends and if they're active but i can't see that yet
let myFriends;
let requestsMade, requestsRecieved;
let allUsers;
let allFriends;
let userToDisplay;
@@ -40,89 +39,91 @@ could be a list of friends and if they're active but i can't see that yet
user = await fetch('http://transcendance:8080/api/v2/user')
.then( (x) => x.json() );
console.log('user is ')
console.log(user)
console.log(user.username)
// console.log('user is ')
// console.log(user)
// console.log(user.username)
myFriends = await fetch("http://transcendance:8080/api/v2/network/myfriends")
.then( (x) => x.json() );
console.log('my friends')
console.log(myFriends)
// console.log('my friends')
// console.log(myFriends)
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
.then( x => x.json() );
console.log('Requests pending ');
console.log(requestsMade);
// console.log('Requests pending ');
// console.log(requestsMade);
requestsRecieved = await fetch('http://transcendance:8080/api/v2/network/received')
.then( x => x.json() );
console.log('Requests received ');
console.log(requestsRecieved);
// console.log('Requests received ');
// console.log(requestsRecieved);
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
.then( x => x.json() );
console.log('got all users ' + allUsers)
// console.log('got all users ' + allUsers)
allFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() );
console.log('got all friends ' + allFriends)
})
const displayAllUsers = async() => {
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
.then( x => x.json() );
console.log('got all users ' + allUsers)
// console.log('got all users ' + allUsers)
};
const displayAllFriends = async() => {
allFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() );
console.log('got all friends ' + allFriends)
// console.log('got all friends ' + allFriends)
};
const displayRequestsMade = async() => {
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
.then( x => x.json() );
console.log('got requests made ' + requestsMade)
// console.log('got requests made ' + requestsMade)
};
// const sendFriendRequest =
let sentFriendRequest;
const friendUserByUsername = async(potenticalFriendUsername) => {
// const friendUserByUsername = async(potenticalFriendUsername) => {
const friendUserByUsername = async() => {
let valid = false;
if (potenticalFriendUsername === '' || potenticalFriendUsername.trim() === '') {
if (!user || !user.username) {
valid = false;
}
// if (potenticalFriendUsername === '' || potenticalFriendUsername.trim() === '') {
if (set.friendUsername === '' || set.friendUsername.trim() === '') {
errors.friendRequest = "You have to put a friend's name in.";
valid = false;
} else if (potenticalFriendUsername === user.username) {
} else if (set.friendUsername === user.username) {
errors.friendRequest = "You can't friend yourself."
valid = false;
} else {
valid = true;
}
if (!user || !user.username) {
valid = false;
}
// should i be checking if a Friend request has already been made ?
if (valid) {
let r = "R";
console.log('user is ')
console.log(user)
console.log(user.username)
console.log('friend is ')
console.log(set.friendUsername)
set.friendId = allUsers.find(f => f.username === set.friendUsername).id
console.log('friend found: ' + set.friendId)
// set.friendId = allUsers.find(f => f.username === set.friendUsername).id
// console.log('friend found: ' + set.friendId)
// ok this version works
// ok not really, requesterId and all that is good but...
@@ -137,7 +138,7 @@ could be a list of friends and if they're active but i can't see that yet
})
})
.then( x => x.json())
.then (x => console.log({...x}));
// .then (x => console.log({...x}));
// should i then update requtestsMade with another fetch?
// maybe also check if the request went through?
@@ -159,6 +160,10 @@ could be a list of friends and if they're active but i can't see that yet
{:else}
<!-- problem, i can't use user.id since Cherif doesn't want to expost that to the front...
is there something else i could use? -->
<!-- add a thing so it doesn't display the current user just all the other users -->
<!-- does this work? -->
<!-- {#each allUsers as aUser (aUser.username)} -->
{#each allUsers as aUser }
<!-- <div class="a-user" on:click={() => displayAUser(aUser.username)}>{aUser.username}</div> -->
<div class="a-user" on:click={() => userToDisplay = aUser.username}>{aUser.username}</div>
@@ -199,22 +204,23 @@ could be a list of friends and if they're active but i can't see that yet
<br> -->
<!-- <Button on:click={displayAllFriends}>Get All Friends</Button>
{#if allFriends !== undefined}
<div>{allFriends}</div>
{#each allFriends as friend}
<!-- <Button on:click={displayMyFriends}>Get All My Friends</Button>
{#if myFriends !== undefined}
<div>{myFriends}</div>
{#each myFriends as friend}
<div>{friend}{friend.username}</div>
{/each}
{/if} -->
<!-- <br>
<br>
<div>Make a Friend!</div>
<form on:submit|preventDefault={() => friendUserByUsername(set.friendUsername)}>
<!-- <form on:submit|preventDefault={() => friendUserByUsername(set.friendUsername)}> -->
<form on:submit|preventDefault={friendUserByUsername}>
<input type="text" placeholder="friend's username" bind:value={set.friendUsername}>
<div class="error">{errors.friendRequest}</div>
<Button type="secondary">Send Friend Request</Button>
</form> -->
</form>
<!-- <br> <br> -->
<!-- here i want to list all the requests you and have an accept and a decline button -->

View File

@@ -12,7 +12,8 @@
user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
.then( (x) => x.json() );
console.log('Display a user: ' + user.username)
// console.log('Display a user: ')
// console.log({...user})
})