mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-09 11:42:21 +03:00
feat: implement undo friendship on friendlist modal
This commit is contained in:
parent
f631cd3013
commit
d9c140b2ab
@ -8,31 +8,28 @@ import cn from "classnames";
|
|||||||
import { SPACING_UNIT } from "@renderer/theme.css";
|
import { SPACING_UNIT } from "@renderer/theme.css";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface UserFriendItemProps {
|
export type UserFriendItemProps = {
|
||||||
userId: string;
|
userId: string;
|
||||||
profileImageUrl: string | null;
|
profileImageUrl: string | null;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
type: "SENT" | "RECEIVED" | "ACCEPTED";
|
|
||||||
onClickCancelRequest: (userId: string) => void;
|
|
||||||
onClickAcceptRequest: (userId: string) => void;
|
|
||||||
onClickRefuseRequest: (userId: string) => void;
|
|
||||||
onClickItem: (userId: string) => void;
|
onClickItem: (userId: string) => void;
|
||||||
}
|
} & (
|
||||||
|
| { type: "ACCEPTED"; onClickUndoFriendship: (userId: string) => void }
|
||||||
|
| {
|
||||||
|
type: "SENT" | "RECEIVED";
|
||||||
|
onClickCancelRequest: (userId: string) => void;
|
||||||
|
onClickAcceptRequest: (userId: string) => void;
|
||||||
|
onClickRefuseRequest: (userId: string) => void;
|
||||||
|
}
|
||||||
|
| { type: null }
|
||||||
|
);
|
||||||
|
|
||||||
export const UserFriendItem = ({
|
export const UserFriendItem = (props: UserFriendItemProps) => {
|
||||||
userId,
|
|
||||||
profileImageUrl,
|
|
||||||
displayName,
|
|
||||||
type,
|
|
||||||
onClickCancelRequest,
|
|
||||||
onClickAcceptRequest,
|
|
||||||
onClickRefuseRequest,
|
|
||||||
onClickItem,
|
|
||||||
}: UserFriendItemProps) => {
|
|
||||||
const { t } = useTranslation("user_profile");
|
const { t } = useTranslation("user_profile");
|
||||||
|
const { userId, profileImageUrl, displayName, type, onClickItem } = props;
|
||||||
|
|
||||||
const getRequestDescription = () => {
|
const getRequestDescription = () => {
|
||||||
if (type === null) return null;
|
if (type === "ACCEPTED" || type === null) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<small>
|
<small>
|
||||||
@ -42,11 +39,13 @@ export const UserFriendItem = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getRequestActions = () => {
|
const getRequestActions = () => {
|
||||||
|
if (type === null) return null;
|
||||||
|
|
||||||
if (type === "SENT") {
|
if (type === "SENT") {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
className={styles.cancelRequestButton}
|
className={styles.cancelRequestButton}
|
||||||
onClick={() => onClickCancelRequest(userId)}
|
onClick={() => props.onClickCancelRequest(userId)}
|
||||||
title={t("cancel_request")}
|
title={t("cancel_request")}
|
||||||
>
|
>
|
||||||
<XCircleIcon size={28} />
|
<XCircleIcon size={28} />
|
||||||
@ -59,14 +58,14 @@ export const UserFriendItem = ({
|
|||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
className={styles.acceptRequestButton}
|
className={styles.acceptRequestButton}
|
||||||
onClick={() => onClickAcceptRequest(userId)}
|
onClick={() => props.onClickAcceptRequest(userId)}
|
||||||
title={t("accept_request")}
|
title={t("accept_request")}
|
||||||
>
|
>
|
||||||
<CheckCircleIcon size={28} />
|
<CheckCircleIcon size={28} />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={styles.cancelRequestButton}
|
className={styles.cancelRequestButton}
|
||||||
onClick={() => onClickRefuseRequest(userId)}
|
onClick={() => props.onClickRefuseRequest(userId)}
|
||||||
title={t("ignore_request")}
|
title={t("ignore_request")}
|
||||||
>
|
>
|
||||||
<XCircleIcon size={28} />
|
<XCircleIcon size={28} />
|
||||||
@ -75,15 +74,19 @@ export const UserFriendItem = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
if (type === "ACCEPTED") {
|
||||||
<button
|
return (
|
||||||
className={styles.cancelRequestButton}
|
<button
|
||||||
onClick={() => onClickCancelRequest(userId)}
|
className={styles.cancelRequestButton}
|
||||||
title={t("undo_friendship")}
|
onClick={() => props.onClickUndoFriendship(userId)}
|
||||||
>
|
title={t("undo_friendship")}
|
||||||
<XCircleIcon size={28} />
|
>
|
||||||
</button>
|
<XCircleIcon size={28} />
|
||||||
);
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -3,6 +3,8 @@ import { UserFriend } from "@types";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { UserFriendItem } from "./user-friend-item";
|
import { UserFriendItem } from "./user-friend-item";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useToast, useUserDetails } from "@renderer/hooks";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface UserFriendModalListProps {
|
export interface UserFriendModalListProps {
|
||||||
userId: string;
|
userId: string;
|
||||||
@ -15,12 +17,17 @@ export const UserFriendModalList = ({
|
|||||||
userId,
|
userId,
|
||||||
closeModal,
|
closeModal,
|
||||||
}: UserFriendModalListProps) => {
|
}: UserFriendModalListProps) => {
|
||||||
|
const { t } = useTranslation("user_profile");
|
||||||
|
const { showErrorToast } = useToast();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [maxPage, setMaxPage] = useState(0);
|
const [maxPage, setMaxPage] = useState(0);
|
||||||
const [friends, setFriends] = useState<UserFriend[]>([]);
|
const [friends, setFriends] = useState<UserFriend[]>([]);
|
||||||
|
|
||||||
|
const { userDetails, undoFriendship } = useUserDetails();
|
||||||
|
const isMe = userDetails?.id == userId;
|
||||||
|
|
||||||
const loadNextPage = () => {
|
const loadNextPage = () => {
|
||||||
if (page > maxPage) return;
|
if (page > maxPage) return;
|
||||||
window.electron
|
window.electron
|
||||||
@ -36,11 +43,15 @@ export const UserFriendModalList = ({
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const reloadList = () => {
|
||||||
setPage(0);
|
setPage(0);
|
||||||
setMaxPage(0);
|
setMaxPage(0);
|
||||||
setFriends([]);
|
setFriends([]);
|
||||||
loadNextPage();
|
loadNextPage();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reloadList();
|
||||||
}, [userId]);
|
}, [userId]);
|
||||||
|
|
||||||
const handleClickFriend = (userId: string) => {
|
const handleClickFriend = (userId: string) => {
|
||||||
@ -48,6 +59,16 @@ export const UserFriendModalList = ({
|
|||||||
navigate(`/user/${userId}`);
|
navigate(`/user/${userId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUndoFriendship = (userId: string) => {
|
||||||
|
undoFriendship(userId)
|
||||||
|
.then(() => {
|
||||||
|
reloadList();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showErrorToast(t("try_again"));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@ -62,11 +83,9 @@ export const UserFriendModalList = ({
|
|||||||
userId={friend.id}
|
userId={friend.id}
|
||||||
displayName={friend.displayName}
|
displayName={friend.displayName}
|
||||||
profileImageUrl={friend.profileImageUrl}
|
profileImageUrl={friend.profileImageUrl}
|
||||||
onClickAcceptRequest={() => {}}
|
|
||||||
onClickCancelRequest={() => {}}
|
|
||||||
onClickRefuseRequest={() => {}}
|
|
||||||
onClickItem={handleClickFriend}
|
onClickItem={handleClickFriend}
|
||||||
type={"ACCEPTED"}
|
onClickUndoFriendship={handleUndoFriendship}
|
||||||
|
type={isMe ? "ACCEPTED" : null}
|
||||||
key={friend.id}
|
key={friend.id}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -301,7 +301,7 @@ export interface UserProfile {
|
|||||||
id: string;
|
id: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
profileImageUrl: string | null;
|
profileImageUrl: string | null;
|
||||||
profileVisibility: "PUBLIC" | "PRIVATE" | "FRIEND";
|
profileVisibility: "PUBLIC" | "PRIVATE" | "FRIENDS";
|
||||||
totalPlayTimeInSeconds: number;
|
totalPlayTimeInSeconds: number;
|
||||||
libraryGames: UserGame[];
|
libraryGames: UserGame[];
|
||||||
recentGames: UserGame[];
|
recentGames: UserGame[];
|
||||||
|
Loading…
Reference in New Issue
Block a user