ok after talking with cherif we decided not to send things like the user.id so i need to recreate more or less what i had before, but i'm gonna keep using the user.id everywhere in the back and keep my better simpler friendship.entity, working on all that now, got a thing that compiles in the front and back, a few more things to fix and then test everything

This commit is contained in:
Me
2023-01-03 19:42:14 +01:00
parent b7b9b3d645
commit 000987fbde
7 changed files with 75 additions and 66 deletions

View File

@@ -14,7 +14,7 @@
let myFriends;
let requestsMade, requestsRecieved;
let blockedUsers;
let userIdBeingViewed;
let usernameBeingViewed;
let friendshipStatusFull; // id, date, senderUsername, reveiverUsername, status
/**** Layout variables ****/
@@ -60,7 +60,7 @@
};
const fetchMyFriends = async() => {
myFriends = await fetch('http://transcendance:8080/api/v2/network/relations')
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() );
console.log('got my friends ')
console.log({...myFriends})
@@ -90,10 +90,10 @@
/**** END OF MAIN FETCH ****/
// returns everything but BLOCKED
const fetchFriendshipFull = async(aUserId) => {
const fetchFriendshipFull = async(aUsername) => {
console.log('fetch friendship from a username')
console.log(aUserId)
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/relations/${aUserId}`)
console.log(aUsername)
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
.then( x => x.json());
console.log({...friendshipStatusFull})
};
@@ -105,21 +105,20 @@
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
"receiverUsername": aUser.username,
"receiverId": aUser.id,
"status": "R"
})
})
.then( x => x.json())
fetchFriendshipFull(aUser.id);
fetchFriendshipFull(aUser.username);
};
const viewAUser = async(aUserId) => {
const viewAUser = async(aUsername) => {
console.log('Profile Friend updating userBeingViewed')
userIdBeingViewed = aUserId;
usernameBeingViewed = aUsername;
// friendshipStatusFull = undefined;
// id, date, senderUsername, reveiverUsername, status
await fetchFriendshipFull(aUserId);
await fetchFriendshipFull(aUsername);
console.log('Friendship Status Full')
console.log({...friendshipStatusFull})
@@ -135,7 +134,7 @@
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
console.log('accepted friend request, now response')
console.log({...resp})
await fetchFriendshipFull(userIdBeingViewed);
await fetchFriendshipFull(usernameBeingViewed);
// will this make it reload? C'est un peu bourain... do i even need it?
activeTabItem = activeTabItem;
@@ -150,7 +149,7 @@
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
console.log('declined friend request, now response')
console.log({...resp})
await fetchFriendshipFull(userIdBeingViewed);
await fetchFriendshipFull(usernameBeingViewed);
};
const unfriend = async(relationshipId) => {
@@ -161,7 +160,7 @@
// friendshipStatusFull = undefined;
// OR
await fetchFriendshipFull(userIdBeingViewed);
await fetchFriendshipFull(usernameBeingViewed);
if (Object.keys(friendshipStatusFull).length === 0)
friendshipStatusFull = undefined;
@@ -178,14 +177,14 @@
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
"receiverUsername": aUser.username,
"receiverId": aUser.id,
"receiverId": aUser.username,
"status": "B"
})
})
.then( x => x.json())
await fetchBlockedUsers();
await fetchAllUsers();
userIdBeingViewed = undefined;
usernameBeingViewed = undefined;
friendshipStatusFull = undefined;
// will this make it reload?
@@ -201,7 +200,7 @@
console.log({...resp})
await fetchBlockedUsers();
await fetchAllUsers();
userIdBeingViewed = undefined;
usernameBeingViewed = undefined;
friendshipStatusFull = undefined;
// will this make it reload?
@@ -252,9 +251,9 @@
{/if}
<!-- does this work? -->
<!-- {#each allUsers as aUser (aUser.username)} -->
<!-- {#each allUsers as aUser} -->
{#each allUsers as aUser (aUser.id)}
<div class="sidebar-item" on:click={() => viewAUser(aUser.id)}>{aUser.username}</div>
<!-- {#each allUsers as aUser (aUser.id)} -->
{#each allUsers as aUser}
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
<!-- i could make an indicator component? like green for connected or something?
i could use words but color them?
i could make it so if they're in a game -->
@@ -268,7 +267,7 @@
{/if}
<!-- {#each myFriends as aUser (aUser.id)} -->
{#each myFriends as aUser}
<div class="sidebar-item" on:click={() => viewAUser(aUser.id)}>{aUser.username}</div>
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
<div class="status sidebar-item">{aUser.status}</div>
<br>
{/each}
@@ -300,9 +299,9 @@
<div class="main-display">
{#if userIdBeingViewed !== undefined}
{#if usernameBeingViewed !== undefined}
<!-- <DisplayAUser aUsername={usernameBeingViewed}/> -->
<DisplayAUser aUserId={userIdBeingViewed}/>
<DisplayAUser aUsername={usernameBeingViewed}/>
<div class="buttons-area">
{#if friendshipStatusFull && friendshipStatusFull.id}
@@ -333,8 +332,8 @@
{/if}
{/if}
{:else}
<Button type="secondary" on:click={() => sendFriendRequest(userIdBeingViewed)}>Add Friend</Button>
<Button on:click={() => blockANonFriendUser(userIdBeingViewed)}>Block User</Button>
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
<Button on:click={() => blockANonFriendUser(usernameBeingViewed)}>Block User</Button>
{/if}
</div>
{:else}

View File

@@ -4,14 +4,14 @@
import GenerateUserDisplay from './GenerateUserDisplay.svelte';
// export let aUsername;
export let aUserId;
export let aUsername;
let user;
onMount( async() => {
// 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=${aUserId}`)
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`)
.then( (x) => x.json() );
// console.log('Display a user: ')
@@ -32,12 +32,12 @@
// 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=${aUserId}`)
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`)
.then( (x) => x.json() );
};
// $: aUsername, updateUser();
$: aUserId, updateUser();
$: aUsername, updateUser();
</script>
@@ -49,7 +49,7 @@
<!-- <GenerateUserDisplay user={user} primary={true}/> -->
{:else}
<h2>Sorry</h2>
<div>Failed to load user {aUserId}</div>
<div>Failed to load user {aUsername}</div>
{/if}