ok the friendship and user refactor is done, there are still a lot of comments but that's fine, it's duct taped together, but it works, time to merge

This commit is contained in:
Me
2023-01-05 11:21:34 +01:00
parent d3be6e5fe8
commit 46090b1e33
10 changed files with 98 additions and 164 deletions

View File

@@ -11,7 +11,7 @@
let user;
let allUsers;
let myFriends;
let myFriendships;
let requestsMade, requestsRecieved;
let blockedUsers;
let usernameBeingViewed;
@@ -45,7 +45,7 @@
const fetchAll = async() => {
// no need to await i think it can load in the background
fetchAllUsers();
fetchMyFriends();
fetchMyFriendships();
fetchRequestsMade();
fetchRequestsReceived();
fetchBlockedUsers();
@@ -59,11 +59,13 @@
console.log({...allUsers})
};
const fetchMyFriends = async() => {
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
// it's more like fetch friendships
// then i need to extract the users
const fetchMyFriendships = async() => {
myFriendships = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() );
console.log('got my friends ')
console.log({...myFriends})
console.log({...myFriendships})
};
const fetchRequestsMade = async() => {
@@ -127,12 +129,11 @@
console.log('Friendship Status Full')
console.log({...friendshipStatusFull})
};
const acceptFriendRequest = async(relationshipId) => {
console.log('accept friend request')
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/accept`, {
method: "PATCH"})
.then( x => x.json());
@@ -147,7 +148,6 @@
const declineFriendRequest = async(relationshipId) => {
console.log('decline friend request')
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/decline
const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/decline`, {
method: "PATCH"})
.then( x => x.json());
@@ -173,16 +173,15 @@
activeTabItem = activeTabItem;
};
const blockANonFriendUser = async(aUser) => {
const blockANonFriendUser = async(aUsername) => {
console.log('Block a non friend user, their username')
console.log({...aUser})
console.log(aUsername)
const blockResp = await fetch("http://transcendance:8080/api/v2/network/relations", {
method : "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
"receiverUsername": aUser.username,
"receiverId": aUser.username,
"receiverUsername": aUsername,
"status": "B"
})
})
@@ -222,7 +221,7 @@
if (activeTabItem === 'All Users') {
await fetchAllUsers();
} else if (activeTabItem === 'My Friends') {
await fetchMyFriends();
await fetchMyFriendships();
} else if (activeTabItem === 'Friend Requests') {
await fetchRequestsReceived();
} else if (activeTabItem === 'Blocked Users') {
@@ -265,15 +264,18 @@
<div class="status sidebar-item">{aUser.status}</div>
<br>
{/each}
{:else if activeTabItem === 'My Friends' && myFriends !== undefined}
{:else if activeTabItem === 'My Friends' && myFriendships !== undefined}
<h3>{activeTabItem}</h3>
{#if Object.keys(myFriends).length === 0}
{#if Object.keys(myFriendships).length === 0}
<div class="tip">You don't have any Friends... Yet!</div>
{/if}
<!-- {#each myFriends as aUser (aUser.id)} -->
{#each myFriends as aUser}
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
<div class="status sidebar-item">{aUser.status}</div>
{#each myFriendships as aFriendship}
{#if aFriendship.senderUsername !== user.username}
<div class="sidebar-item" on:click={() => viewAUser(aFriendship.senderUsername)}>{aFriendship.senderUsername}</div>
{:else if aFriendship.receiverUsername !== user.username}
<div class="sidebar-item" on:click={() => viewAUser(aFriendship.receiverUsername)}>{aFriendship.receiverUsername}</div>
{/if}
<br>
{/each}
{:else if activeTabItem === 'Friend Requests' && requestsRecieved !== undefined}
@@ -340,7 +342,7 @@
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
<Button on:click={() => blockANonFriendUser(usernameBeingViewed)}>Block User</Button>
{/if}
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
<!-- <Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button> -->
</div>
{:else}
<div class="placeholder">

View File

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