Skip to content

Commit

Permalink
[feat] UserProfile Page 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
KinDDoGGang committed Nov 1, 2023
1 parent 4a168b3 commit b9cde7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
17 changes: 2 additions & 15 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import useModal from '@/hooks/useModal.ts';
import Filter from '@/components/Filter/Filter.tsx';
import { getRooms } from '@/api/room';
import isEmpty from 'lodash-es/isEmpty';
import { getProfile } from '@/api/userInfo';
import { UserInfoProps } from '@/context/UserInfoProvider.tsx';

type HomeProps = NextPage & {
getLayout: (page: React.ReactElement, ctx: NextPageContext) => React.ReactNode;
Expand All @@ -36,7 +34,6 @@ const defaultFilters = Object.values(FILTER_LABEL).map((value) => {

function Home() {
const [rooms, setRooms] = useState<RoomSearch[]>([]);
const [profile, setProfile] = useState<UserInfoProps>();
const [filters, setFilters] = useState<{ selected: boolean; value: string }[]>(defaultFilters);
const [clickedChip, setClickedChip] = useState(-1);
const router = useRouter();
Expand Down Expand Up @@ -83,16 +80,6 @@ function Home() {
setSearchParams(childData);
setRooms([]);
};
const selectProfile = async () => {
try {
const data = await getProfile();
if (data != null) {
setProfile(data);
}
} catch (error) {
console.error(error);
}
};
const openFilterPopup = () => {
openModal({
props: {
Expand Down Expand Up @@ -130,7 +117,7 @@ function Home() {
useEffect(() => {
(async () => {
await selectRooms();
await selectProfile();
// await selectProfile();
if (target?.current) {
const observer = new IntersectionObserver(callback, options);
observer.observe(target.current);
Expand Down Expand Up @@ -229,7 +216,7 @@ function Home() {
<div className="mt-[83px] fixed bottom-[-15px] w-full overflow-x-hidden left-[50%] translate-x-[-50%] px-[20px] max-w-max z-20 border-t-[1px] border-g2">
<div className="w-full">
<div className="mb-[13px] space-x-[8px] max-w-max">
<Nav profile={profile} />
<Nav />
</div>
</div>
</div>
Expand Down
28 changes: 23 additions & 5 deletions pages/userInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import { Nav, ProfileCard } from '@/components/index.tsx';
import { useRouter } from 'next/router';
import { getProfile } from '@/api/userInfo';
import { UserInfoProps } from '@/context/UserInfoProvider.tsx';

interface UserProfileProps {
imgSrc: string;
}

export default function UserProfile({ imgSrc }: UserProfileProps) {
const router = useRouter();
const { query } = router;
const userInfo = query.data ? JSON.parse(query.data as string) : {};
const [profile, setProfile] = useState<UserInfoProps>();
const selectProfile = async () => {
try {
const data = await getProfile();
if (data != null) {
setProfile(data);
}
} catch (error) {
console.error(error);
}
};

useEffect(() => {
(async () => {
await selectProfile();
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
<ProfileCard imageSrc={userInfo.imageFile?.path || imgSrc} userInfo={userInfo} />
{profile && <ProfileCard imageSrc={profile?.imageFile?.path || imgSrc} userInfo={profile} />}
<div className="mt-[83px] fixed bottom-[-15px] w-full overflow-x-hidden left-[50%] translate-x-[-50%] px-[20px] max-w-max border-t-[1px] border-g2">
<div className="w-full">
<div className="mb-[13px] space-x-[8px] max-w-max">
Expand Down

0 comments on commit b9cde7c

Please sign in to comment.