-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some work towards friend infra (#30)
* Some work towards friend infra * withCredentials: true for relationships api * pass profileUserId thru to card * done
- Loading branch information
Showing
6 changed files
with
137 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import axios from "axios" | ||
|
||
interface UserFriendsWithRequest { | ||
id: number | ||
} | ||
|
||
export const enum RelationshipType { | ||
NotFriend = "not_friend", | ||
Friend = "friend", | ||
Mutual = "mutual", | ||
} | ||
|
||
export interface UserFriendsWithResponse { | ||
code: number | ||
friend: boolean | ||
mutual: boolean | ||
} | ||
|
||
const userRelationshipsApiInstance = axios.create({ | ||
baseURL: process.env.REACT_APP_USER_RELATIONSHIPS_API_BASE_URL, | ||
withCredentials: true, | ||
}) | ||
|
||
export const fetchUserFriendsWith = async ( | ||
request: UserFriendsWithRequest | ||
): Promise<UserFriendsWithResponse> => { | ||
try { | ||
const response = await userRelationshipsApiInstance.get( | ||
"/v1/friends/with", | ||
{ | ||
params: { | ||
id: request.id, | ||
}, | ||
} | ||
) | ||
return { | ||
code: response.status, | ||
friend: response.data.friend, | ||
mutual: response.data.mutual, | ||
} | ||
} catch (e: any) { | ||
throw new Error("Failed to fetch user friends data from server") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,71 @@ | ||
import { Typography } from "@mui/material" | ||
import { Button, Typography } from "@mui/material" | ||
import Stack from "@mui/material/Stack" | ||
import Box from "@mui/material/Box" | ||
import { AddUserIcon } from "../images/icons/AddUserIcon" | ||
import { RelationshipType } from "../../adapters/akatsuki-api/userRelationships" | ||
import { useIdentityContext } from "../../context/identity" | ||
|
||
const getRelationshipColor = (relationship: RelationshipType) => { | ||
switch (relationship) { | ||
case RelationshipType.Friend: | ||
return "#00FF00" | ||
case RelationshipType.Mutual: | ||
return "#CF6179" | ||
case RelationshipType.NotFriend: | ||
return "rgba(18, 15, 29, 1)" | ||
} | ||
} | ||
|
||
export const ProfileRelationshipCard = ({ | ||
profileUserId, | ||
relationship, | ||
setRelationship, | ||
followers, | ||
}: { | ||
profileUserId: number | ||
relationship: RelationshipType | ||
setRelationship: (relationship: RelationshipType) => void | ||
followers: number | ||
}) => { | ||
const { identity } = useIdentityContext() | ||
|
||
const onClick = () => { | ||
if (profileUserId === identity?.userId) { | ||
return | ||
} | ||
|
||
if (relationship === RelationshipType.NotFriend) { | ||
// Add them as a friend over the API | ||
// Conditionally set mutual vs. friend | ||
} else { | ||
// Remove them as a friend over the API | ||
setRelationship(RelationshipType.NotFriend) | ||
} | ||
} | ||
|
||
return ( | ||
<Stack | ||
direction="row" | ||
spacing={1.5} | ||
bgcolor="rgba(18, 15, 29, 1)" | ||
borderRadius={11} | ||
py={0.5} | ||
px={1.5} | ||
alignItems="center" | ||
> | ||
{/* TODO: color icon based on relationship status */} | ||
{/* https://www.figma.com/design/moJEAJT6UYGnwQYIuKzanf?node-id=76-1050#878804687 */} | ||
<Box borderRadius={11} overflow="hidden"> | ||
<Button | ||
onClick={() => onClick()} | ||
sx={{ textDecoration: "none", color: "white", padding: 0 }} | ||
> | ||
<Stack | ||
direction="row" | ||
spacing={1.5} | ||
bgcolor={getRelationshipColor(relationship)} //"rgba(18, 15, 29, 1)" | ||
py={0.5} | ||
px={1.5} | ||
alignItems="center" | ||
> | ||
{/* TODO: color icon based on relationship status */} | ||
{/* https://www.figma.com/design/moJEAJT6UYGnwQYIuKzanf?node-id=76-1050#878804687 */} | ||
|
||
<Box width={23} height={23}> | ||
<AddUserIcon /> | ||
</Box> | ||
<Typography variant="h6">{followers}</Typography> | ||
</Stack> | ||
<Box width={23} height={23}> | ||
<AddUserIcon /> | ||
</Box> | ||
<Typography variant="h6">{followers}</Typography> | ||
</Stack> | ||
</Button> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters