mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
getting user profile from api
This commit is contained in:
parent
a974141360
commit
b8895afc0a
8 changed files with 57 additions and 14 deletions
|
@ -1,17 +1,15 @@
|
|||
import axios from "axios";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { userProfileSchema } from "../helpers/validators";
|
||||
import { logger } from "@main/services";
|
||||
import { HydraApi } from "@main/services/hydra-api";
|
||||
|
||||
const getUserProfile = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
username: string
|
||||
) => {
|
||||
return axios
|
||||
.get(`${process.env.API_URL}/profile/${username}`)
|
||||
return HydraApi.get(`/profile/${username}`)
|
||||
.then((response) => {
|
||||
const profile = userProfileSchema.parse(response.data);
|
||||
console.log(profile);
|
||||
return profile;
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -20,4 +18,4 @@ const getUserProfile = async (
|
|||
});
|
||||
};
|
||||
|
||||
registerEvent("getUserProfiel", getUserProfile);
|
||||
registerEvent("getUserProfile", getUserProfile);
|
||||
|
|
|
@ -39,6 +39,7 @@ export function Header({ onSearch, onClear, search }: HeaderProps) {
|
|||
|
||||
const title = useMemo(() => {
|
||||
if (location.pathname.startsWith("/game")) return headerTitle;
|
||||
if (location.pathname.startsWith("/profile")) return headerTitle;
|
||||
if (location.pathname.startsWith("/search")) return t("search_results");
|
||||
|
||||
return t(pathTitle[location.pathname]);
|
||||
|
|
|
@ -143,6 +143,10 @@ export function Sidebar() {
|
|||
}
|
||||
};
|
||||
|
||||
const handleClickProfile = () => {
|
||||
navigate("/profile/brownie");
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<aside
|
||||
|
@ -154,7 +158,11 @@ export function Sidebar() {
|
|||
maxWidth: sidebarWidth,
|
||||
}}
|
||||
>
|
||||
<button type="button" className={styles.profileButton}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.profileButton}
|
||||
onClick={handleClickProfile}
|
||||
>
|
||||
<div className={styles.profileAvatar}>
|
||||
<PersonIcon />
|
||||
|
||||
|
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
|
@ -13,6 +13,7 @@ import type {
|
|||
StartGameDownloadPayload,
|
||||
RealDebridUser,
|
||||
DownloadSource,
|
||||
UserProfile,
|
||||
} from "@types";
|
||||
import type { DiskSpace } from "check-disk-space";
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
import { store } from "./store";
|
||||
|
||||
import * as resources from "@locales";
|
||||
import { Profile } from "./pages/profile/profile";
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
|
@ -54,6 +55,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|||
<Route path="/game/:shop/:objectID" Component={GameDetails} />
|
||||
<Route path="/search" Component={SearchResults} />
|
||||
<Route path="/settings" Component={Settings} />
|
||||
<Route path="profile/:username" Component={Profile} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</HashRouter>
|
||||
|
|
16
src/renderer/src/pages/profile/profile-content.tsx
Normal file
16
src/renderer/src/pages/profile/profile-content.tsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { UserProfile } from "@types";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export interface ProfileContentProps {
|
||||
userProfile: UserProfile;
|
||||
}
|
||||
|
||||
export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||
const { t } = useTranslation("profile");
|
||||
|
||||
return (
|
||||
<>
|
||||
<p>{userProfile.username}</p>
|
||||
</>
|
||||
);
|
||||
};
|
7
src/renderer/src/pages/profile/profile-skeleton.tsx
Normal file
7
src/renderer/src/pages/profile/profile-skeleton.tsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
export const ProfileSkeleton = () => {
|
||||
return (
|
||||
<>
|
||||
<p>Loading....</p>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -1,17 +1,27 @@
|
|||
import { UserProfile } from "@types";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { setHeaderTitle } from "@renderer/features";
|
||||
import { useAppDispatch } from "@renderer/hooks";
|
||||
import { ProfileSkeleton } from "./profile-skeleton";
|
||||
import { ProfileContent } from "./profile-content";
|
||||
|
||||
export const Profile = () => {
|
||||
const { username } = useParams();
|
||||
const [userProfile, setUserProfile] = useState<UserProfile>();
|
||||
|
||||
const { t } = useTranslation("profile");
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p>Tela do usuarioooooooo</p>
|
||||
</>
|
||||
);
|
||||
useEffect(() => {
|
||||
window.electron.getUserProfile(username!).then((userProfile) => {
|
||||
if (userProfile) {
|
||||
dispatch(setHeaderTitle(userProfile.username));
|
||||
setUserProfile(userProfile);
|
||||
}
|
||||
});
|
||||
}, [dispatch]);
|
||||
|
||||
if (!userProfile) return <ProfileSkeleton />;
|
||||
|
||||
return <ProfileContent userProfile={userProfile} />;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue