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/open-auth-window";
|
||||||
import "./auth/get-session-hash";
|
import "./auth/get-session-hash";
|
||||||
import "./user/get-user";
|
import "./user/get-user";
|
||||||
|
import "./profile/get-friend-requests";
|
||||||
import "./profile/get-me";
|
import "./profile/get-me";
|
||||||
import "./profile/update-profile";
|
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"),
|
getMe: () => ipcRenderer.invoke("getMe"),
|
||||||
updateProfile: (displayName: string, newProfileImagePath: string | null) =>
|
updateProfile: (displayName: string, newProfileImagePath: string | null) =>
|
||||||
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
|
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
|
||||||
|
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),
|
||||||
|
|
||||||
/* User */
|
/* User */
|
||||||
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
|
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,
|
RealDebridUser,
|
||||||
DownloadSource,
|
DownloadSource,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
|
PendingFriendRequest,
|
||||||
} from "@types";
|
} from "@types";
|
||||||
import type { DiskSpace } from "check-disk-space";
|
import type { DiskSpace } from "check-disk-space";
|
||||||
|
|
||||||
|
@ -132,6 +133,7 @@ declare global {
|
||||||
displayName: string,
|
displayName: string,
|
||||||
newProfileImagePath: string | null
|
newProfileImagePath: string | null
|
||||||
) => Promise<UserProfile>;
|
) => Promise<UserProfile>;
|
||||||
|
getFriendRequests: () => Promise<PendingFriendRequest[] | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|
|
@ -82,6 +82,10 @@ export function useUserDetails() {
|
||||||
console.log("sending friend request to", userId);
|
console.log("sending friend request to", userId);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const fetchPendingRequests = useCallback(async () => {
|
||||||
|
return window.electron.getFriendRequests();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
userDetails,
|
userDetails,
|
||||||
fetchUserDetails,
|
fetchUserDetails,
|
||||||
|
@ -90,6 +94,7 @@ export function useUserDetails() {
|
||||||
updateUserDetails,
|
updateUserDetails,
|
||||||
patchUser,
|
patchUser,
|
||||||
sendFriendRequest,
|
sendFriendRequest,
|
||||||
|
fetchPendingRequests,
|
||||||
profileBackground,
|
profileBackground,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Button, Modal, TextField } from "@renderer/components";
|
import { Button, Modal, TextField } from "@renderer/components";
|
||||||
import { PendingFriendRequest } from "@types";
|
import { PendingFriendRequest } from "@types";
|
||||||
import { SPACING_UNIT } from "@renderer/theme.css";
|
import { SPACING_UNIT } from "@renderer/theme.css";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { useToast, useUserDetails } from "@renderer/hooks";
|
import { useToast, useUserDetails } from "@renderer/hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
@ -10,19 +10,18 @@ import { UserFriendPendingRequest } from "./user-friend-pending-request";
|
||||||
export interface UserAddFriendsModalProps {
|
export interface UserAddFriendsModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
pendingRequests: PendingFriendRequest[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserAddFriendsModal = ({
|
export const UserAddFriendsModal = ({
|
||||||
visible,
|
visible,
|
||||||
onClose,
|
onClose,
|
||||||
|
pendingRequests,
|
||||||
}: UserAddFriendsModalProps) => {
|
}: UserAddFriendsModalProps) => {
|
||||||
const { t } = useTranslation("user_profile");
|
const { t } = useTranslation("user_profile");
|
||||||
|
|
||||||
const [friendCode, setFriendCode] = useState("");
|
const [friendCode, setFriendCode] = useState("");
|
||||||
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
||||||
const [pendingRequests, setPendingRequests] = useState<
|
|
||||||
PendingFriendRequest[]
|
|
||||||
>([]);
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ export const UserAddFriendsModal = ({
|
||||||
showSuccessToast(t("friend_request_sent"));
|
showSuccessToast(t("friend_request_sent"));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
showErrorToast("falhaaaa");
|
showErrorToast("Não foi possível enviar o pedido de amizade");
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsAddingFriend(false);
|
setIsAddingFriend(false);
|
||||||
|
@ -45,29 +44,12 @@ export const UserAddFriendsModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickFriend = (userId: string) => {
|
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 = () => {
|
const handleClickSeeProfile = () => {
|
||||||
// navigate(`profile/${friendCode}`);
|
onClose();
|
||||||
|
navigate(`/user/${friendCode}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickCancelFriendRequest = (userId: string) => {
|
const handleClickCancelFriendRequest = (userId: string) => {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import { UserGame, UserProfile } from "@types";
|
import { PendingFriendRequest, UserGame, UserProfile } from "@types";
|
||||||
import cn from "classnames";
|
import cn from "classnames";
|
||||||
|
|
||||||
import * as styles from "./user.css";
|
import * as styles from "./user.css";
|
||||||
import { SPACING_UNIT, vars } from "@renderer/theme.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 { useTranslation } from "react-i18next";
|
||||||
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
|
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
|
||||||
import {
|
import {
|
||||||
|
@ -90,8 +89,18 @@ export function UserContent({
|
||||||
navigate("/");
|
navigate("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [pendingRequests, setPendingRequests] = useState<
|
||||||
|
PendingFriendRequest[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
const isMe = userDetails?.id == userProfile.id;
|
const isMe = userDetails?.id == userProfile.id;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.electron.getFriendRequests().then((friendsRequests) => {
|
||||||
|
setPendingRequests(friendsRequests ?? []);
|
||||||
|
});
|
||||||
|
}, [isMe]);
|
||||||
|
|
||||||
const profileContentBoxBackground = useMemo(() => {
|
const profileContentBoxBackground = useMemo(() => {
|
||||||
if (profileBackground) return profileBackground;
|
if (profileBackground) return profileBackground;
|
||||||
/* TODO: Render background colors for other users */
|
/* TODO: Render background colors for other users */
|
||||||
|
@ -114,6 +123,7 @@ export function UserContent({
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<UserAddFriendsModal
|
<UserAddFriendsModal
|
||||||
|
pendingRequests={pendingRequests}
|
||||||
visible={showAddFriendsModal}
|
visible={showAddFriendsModal}
|
||||||
onClose={() => setShowAddFriendsModal(false)}
|
onClose={() => setShowAddFriendsModal(false)}
|
||||||
/>
|
/>
|
||||||
|
@ -231,9 +241,11 @@ export function UserContent({
|
||||||
<TelescopeIcon size={24} />
|
<TelescopeIcon size={24} />
|
||||||
</div>
|
</div>
|
||||||
<h2>{t("no_recent_activity_title")}</h2>
|
<h2>{t("no_recent_activity_title")}</h2>
|
||||||
<p style={{ fontFamily: "Fira Sans" }}>
|
{isMe && (
|
||||||
{t("no_recent_activity_description")}
|
<p style={{ fontFamily: "Fira Sans" }}>
|
||||||
</p>
|
{t("no_recent_activity_description")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { UserProfile } from "@types";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { setHeaderTitle } from "@renderer/features";
|
import { setHeaderTitle } from "@renderer/features";
|
||||||
import { useAppDispatch } from "@renderer/hooks";
|
import { useAppDispatch, useToast } from "@renderer/hooks";
|
||||||
import { UserSkeleton } from "./user-skeleton";
|
import { UserSkeleton } from "./user-skeleton";
|
||||||
import { UserContent } from "./user-content";
|
import { UserContent } from "./user-content";
|
||||||
import { SkeletonTheme } from "react-loading-skeleton";
|
import { SkeletonTheme } from "react-loading-skeleton";
|
||||||
|
@ -14,6 +14,8 @@ export const User = () => {
|
||||||
const [userProfile, setUserProfile] = useState<UserProfile>();
|
const [userProfile, setUserProfile] = useState<UserProfile>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const { showErrorToast } = useToast();
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const getUserProfile = useCallback(() => {
|
const getUserProfile = useCallback(() => {
|
||||||
|
@ -22,6 +24,7 @@ export const User = () => {
|
||||||
dispatch(setHeaderTitle(userProfile.displayName));
|
dispatch(setHeaderTitle(userProfile.displayName));
|
||||||
setUserProfile(userProfile);
|
setUserProfile(userProfile);
|
||||||
} else {
|
} else {
|
||||||
|
showErrorToast("Usuário não encontrado");
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue