adding the ability to add and delete friends, in progress
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { onMount } from "svelte";
|
||||
import { binding_callbacks } from "svelte/internal"; // WTF is this?
|
||||
import App from "../../App.svelte";
|
||||
import Button from "../../pieces/Button.svelte";
|
||||
import DisplayAUser from "../../pieces/DisplayAUser.svelte";
|
||||
import Tabs from "../../pieces/Tabs.svelte";
|
||||
@@ -14,6 +15,8 @@
|
||||
let myFriends;
|
||||
let requestsMade, requestsRecieved;
|
||||
let usernameBeingViewed;
|
||||
let friendshipStatusFull; // id, date, senderUsername, reveiverUsername, status
|
||||
let friendshipFetch; // like a generic var for any friendship fetch actions that might happen
|
||||
|
||||
/**** Layout variables ****/
|
||||
let tabItems: string[] = ['All Users', 'My Friends', 'Friend Requests']
|
||||
@@ -49,10 +52,20 @@
|
||||
const fetchMyFriends = async() => {
|
||||
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
|
||||
.then( x => x.json() );
|
||||
// console.log('got all friends ')
|
||||
// console.log({...allFriends})
|
||||
console.log('got my friends ')
|
||||
console.log({...myFriends})
|
||||
};
|
||||
|
||||
let cherif;
|
||||
const fetchAFriend = async() => {
|
||||
cherif = await fetch('http://transcendance:8080/api/v2/network/myfriends/chbadad')
|
||||
.then( x => x.json() );
|
||||
console.log('got Cherif ')
|
||||
console.log(cherif)
|
||||
// console.log({...cherif})
|
||||
};
|
||||
|
||||
|
||||
const fetchRequestsMade = async() => {
|
||||
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
||||
.then( x => x.json() );
|
||||
@@ -93,19 +106,47 @@
|
||||
}
|
||||
};
|
||||
|
||||
const areWeFriends = async(aUsername) => {
|
||||
console.log("Are We Friends?")
|
||||
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
|
||||
.then( x => x.json());
|
||||
|
||||
};
|
||||
|
||||
const viewAUser = async(aUsername) => {
|
||||
console.log('Profile Friend updating userBeingViewed')
|
||||
usernameBeingViewed = aUsername;
|
||||
|
||||
friendshipStatusFull = undefined;
|
||||
// id, date, senderUsername, reveiverUsername, status
|
||||
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
|
||||
.then( x => x.json());
|
||||
|
||||
// sendUsername = userBeingViewed.username;
|
||||
|
||||
// prolly like fetch if you're friends or not?
|
||||
// GET http://transcendance:8080/api/v2/networks/myfriends?username=aUser but i need to make that as long as Cherif
|
||||
// doesn't have a better option
|
||||
// like i want this thing to return the Friendship ID ideally
|
||||
console.log('Friendship Status Full')
|
||||
console.log({...friendshipStatusFull})
|
||||
|
||||
};
|
||||
|
||||
|
||||
const acceptFriendRequest = async(relationshipId) => {
|
||||
console.log('accept friend request')
|
||||
friendshipFetch = undefined;
|
||||
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
|
||||
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/accept`, {
|
||||
method: "PATCH"})
|
||||
.then( x => x.json());
|
||||
};
|
||||
|
||||
const unfriend = async(relationshipId) => {
|
||||
console.log('Unfriend')
|
||||
friendshipFetch = undefined;
|
||||
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
|
||||
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}`, {
|
||||
method: "DELETE"})
|
||||
.then( x => x.json());
|
||||
};
|
||||
|
||||
|
||||
const blockAUser = async(friendshipId) => {
|
||||
|
||||
};
|
||||
@@ -143,12 +184,14 @@
|
||||
<!-- does this work? -->
|
||||
<!-- {#each allUsers as aUser (aUser.username)} -->
|
||||
{#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 -->
|
||||
<div class="status sidebar-item">{aUser.status}</div>
|
||||
<br>
|
||||
{#if aUser.username !== user.username}
|
||||
<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 -->
|
||||
<div class="status sidebar-item">{aUser.status}</div>
|
||||
<br>
|
||||
{/if}
|
||||
{/each}
|
||||
{:else if activeTabItem === 'My Friends' && myFriends !== undefined}
|
||||
<h3>{activeTabItem}</h3>
|
||||
@@ -178,10 +221,25 @@
|
||||
<DisplayAUser aUsername={usernameBeingViewed}/>
|
||||
|
||||
<div class="buttons-area">
|
||||
<!-- Add Friend -->
|
||||
<!-- not the current user, not blocked, not request already sent or received, basically no friendshipID -->
|
||||
<!-- so far not dealing with Blocked people -->
|
||||
{#if usernameBeingViewed !== user.username}
|
||||
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
|
||||
<!-- uhhhg why can't it be simple... -->
|
||||
<!-- {#if friendshipStatusFull === undefined} -->
|
||||
{#if friendshipStatusFull && friendshipStatusFull.id}
|
||||
{#if friendshipStatusFull.status === 'R'}
|
||||
{#if friendshipStatusFull.senderUsername === user.username}
|
||||
<div class="tile">Friend Request Sent</div>
|
||||
{:else}
|
||||
<!-- <Button type="secondary" on:click={() => acceptFriendRequest(usernameBeingViewed)}>Unfriend</Button> -->
|
||||
<Button type="secondary" on:click={() => acceptFriendRequest(friendshipStatusFull.id)}>Accept Friend Request</Button>
|
||||
{/if}
|
||||
{:else if friendshipStatusFull.status === 'A'}
|
||||
<div class="tile">You are Friends</div>
|
||||
<Button on:click={() => unfriend(friendshipStatusFull.id)}>Unfriend</Button>
|
||||
{/if}
|
||||
{:else}
|
||||
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<!-- {#if user not blocked}
|
||||
@@ -218,6 +276,7 @@
|
||||
{/if} -->
|
||||
<!-- {:else if userBeingViewed !== undefined} -->
|
||||
|
||||
<!-- <Button on:click={fetchAFriend}>Get Cherif</Button> -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user