mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: get friends requests from api
This commit is contained in:
parent
6ff48605da
commit
b3f87d5662
8 changed files with 54 additions and 32 deletions
|
@ -43,6 +43,7 @@ import "./auth/sign-out";
|
|||
import "./auth/open-auth-window";
|
||||
import "./auth/get-session-hash";
|
||||
import "./user/get-user";
|
||||
import "./profile/get-friend-requests";
|
||||
import "./profile/get-me";
|
||||
import "./profile/update-profile";
|
||||
|
||||
|
|
16
src/main/events/profile/get-friend-requests.ts
Normal file
16
src/main/events/profile/get-friend-requests.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi } from "@main/services";
|
||||
import { PendingFriendRequest } from "@types";
|
||||
|
||||
const getFriendRequests = async (
|
||||
_event: Electron.IpcMainInvokeEvent
|
||||
): Promise<PendingFriendRequest[] | null> => {
|
||||
try {
|
||||
const response = await HydraApi.get(`/profile/friend-requests`);
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("getFriendRequests", getFriendRequests);
|
|
@ -136,6 +136,7 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
getMe: () => ipcRenderer.invoke("getMe"),
|
||||
updateProfile: (displayName: string, newProfileImagePath: string | null) =>
|
||||
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
|
||||
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),
|
||||
|
||||
/* User */
|
||||
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
|
||||
|
|
2
src/renderer/src/declaration.d.ts
vendored
2
src/renderer/src/declaration.d.ts
vendored
|
@ -14,6 +14,7 @@ import type {
|
|||
RealDebridUser,
|
||||
DownloadSource,
|
||||
UserProfile,
|
||||
PendingFriendRequest,
|
||||
} from "@types";
|
||||
import type { DiskSpace } from "check-disk-space";
|
||||
|
||||
|
@ -132,6 +133,7 @@ declare global {
|
|||
displayName: string,
|
||||
newProfileImagePath: string | null
|
||||
) => Promise<UserProfile>;
|
||||
getFriendRequests: () => Promise<PendingFriendRequest[] | null>;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
|
|
|
@ -82,6 +82,10 @@ export function useUserDetails() {
|
|||
console.log("sending friend request to", userId);
|
||||
}, []);
|
||||
|
||||
const fetchPendingRequests = useCallback(async () => {
|
||||
return window.electron.getFriendRequests();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
userDetails,
|
||||
fetchUserDetails,
|
||||
|
@ -90,6 +94,7 @@ export function useUserDetails() {
|
|||
updateUserDetails,
|
||||
patchUser,
|
||||
sendFriendRequest,
|
||||
fetchPendingRequests,
|
||||
profileBackground,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Button, Modal, TextField } from "@renderer/components";
|
||||
import { PendingFriendRequest } from "@types";
|
||||
import { SPACING_UNIT } from "@renderer/theme.css";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { useToast, useUserDetails } from "@renderer/hooks";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
@ -10,19 +10,18 @@ import { UserFriendPendingRequest } from "./user-friend-pending-request";
|
|||
export interface UserAddFriendsModalProps {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
pendingRequests: PendingFriendRequest[];
|
||||
}
|
||||
|
||||
export const UserAddFriendsModal = ({
|
||||
visible,
|
||||
onClose,
|
||||
pendingRequests,
|
||||
}: UserAddFriendsModalProps) => {
|
||||
const { t } = useTranslation("user_profile");
|
||||
|
||||
const [friendCode, setFriendCode] = useState("");
|
||||
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
||||
const [pendingRequests, setPendingRequests] = useState<
|
||||
PendingFriendRequest[]
|
||||
>([]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
@ -37,7 +36,7 @@ export const UserAddFriendsModal = ({
|
|||
showSuccessToast(t("friend_request_sent"));
|
||||
})
|
||||
.catch(() => {
|
||||
showErrorToast("falhaaaa");
|
||||
showErrorToast("Não foi possível enviar o pedido de amizade");
|
||||
})
|
||||
.finally(() => {
|
||||
setIsAddingFriend(false);
|
||||
|
@ -45,29 +44,12 @@ export const UserAddFriendsModal = ({
|
|||
};
|
||||
|
||||
const handleClickFriend = (userId: string) => {
|
||||
navigate(userId);
|
||||
navigate(`/user/${userId}`);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setPendingRequests([
|
||||
{
|
||||
userId: "abcd1234",
|
||||
displayName: "Punheta Master 123",
|
||||
profileImageUrl:
|
||||
"https://cdn.discordapp.com/avatars/1239959140785455295/4aff4b901c7a9f5f814b4379b6cfd58a.webp",
|
||||
type: "RECEIVED",
|
||||
},
|
||||
{
|
||||
userId: "12345678",
|
||||
displayName: "Deyvis0n",
|
||||
profileImageUrl: null,
|
||||
type: "SENT",
|
||||
},
|
||||
]);
|
||||
}, []);
|
||||
|
||||
const handleClickSeeProfile = () => {
|
||||
// navigate(`profile/${friendCode}`);
|
||||
onClose();
|
||||
navigate(`/user/${friendCode}`);
|
||||
};
|
||||
|
||||
const handleClickCancelFriendRequest = (userId: string) => {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { UserGame, UserProfile } from "@types";
|
||||
import { PendingFriendRequest, UserGame, UserProfile } from "@types";
|
||||
import cn from "classnames";
|
||||
|
||||
import * as styles from "./user.css";
|
||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
|
||||
import {
|
||||
|
@ -90,8 +89,18 @@ export function UserContent({
|
|||
navigate("/");
|
||||
};
|
||||
|
||||
const [pendingRequests, setPendingRequests] = useState<
|
||||
PendingFriendRequest[]
|
||||
>([]);
|
||||
|
||||
const isMe = userDetails?.id == userProfile.id;
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.getFriendRequests().then((friendsRequests) => {
|
||||
setPendingRequests(friendsRequests ?? []);
|
||||
});
|
||||
}, [isMe]);
|
||||
|
||||
const profileContentBoxBackground = useMemo(() => {
|
||||
if (profileBackground) return profileBackground;
|
||||
/* TODO: Render background colors for other users */
|
||||
|
@ -114,6 +123,7 @@ export function UserContent({
|
|||
/>
|
||||
|
||||
<UserAddFriendsModal
|
||||
pendingRequests={pendingRequests}
|
||||
visible={showAddFriendsModal}
|
||||
onClose={() => setShowAddFriendsModal(false)}
|
||||
/>
|
||||
|
@ -231,9 +241,11 @@ export function UserContent({
|
|||
<TelescopeIcon size={24} />
|
||||
</div>
|
||||
<h2>{t("no_recent_activity_title")}</h2>
|
||||
<p style={{ fontFamily: "Fira Sans" }}>
|
||||
{t("no_recent_activity_description")}
|
||||
</p>
|
||||
{isMe && (
|
||||
<p style={{ fontFamily: "Fira Sans" }}>
|
||||
{t("no_recent_activity_description")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
|
|
|
@ -2,7 +2,7 @@ import { UserProfile } from "@types";
|
|||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { setHeaderTitle } from "@renderer/features";
|
||||
import { useAppDispatch } from "@renderer/hooks";
|
||||
import { useAppDispatch, useToast } from "@renderer/hooks";
|
||||
import { UserSkeleton } from "./user-skeleton";
|
||||
import { UserContent } from "./user-content";
|
||||
import { SkeletonTheme } from "react-loading-skeleton";
|
||||
|
@ -14,6 +14,8 @@ export const User = () => {
|
|||
const [userProfile, setUserProfile] = useState<UserProfile>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { showErrorToast } = useToast();
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const getUserProfile = useCallback(() => {
|
||||
|
@ -22,6 +24,7 @@ export const User = () => {
|
|||
dispatch(setHeaderTitle(userProfile.displayName));
|
||||
setUserProfile(userProfile);
|
||||
} else {
|
||||
showErrorToast("Usuário não encontrado");
|
||||
navigate(-1);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue