Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#530] FloatingButton 컴포넌트 적용 #536

Merged
merged 10 commits into from
Apr 24, 2024
4 changes: 2 additions & 2 deletions public/icons/book-plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions public/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 30 additions & 13 deletions src/app/group/page.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
'use client';

import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { useInView } from 'react-intersection-observer';

import SSRSafeSuspense from '@/components/SSRSafeSuspense';
import TopHeader from '@/v1/base/TopHeader';
import SearchGroupInput from '@/v1/bookGroup/SearchGroup';
import SimpleBookGroupCard, {
SimpleBookGroupCardSkeleton,
} from '@/v1/bookGroup/SimpleBookGroupCard';
import DetailBookGroupCard, {
DetailBookGroupCardSkeleton,
} from '@/v1/bookGroup/DetailBookGroupCard';

import useEntireGroupsQuery from '@/queries/group/useEntireGroupsQuery';
import useMyGroupsQuery from '@/queries/group/useMyGroupQuery';
import { useMyProfileId } from '@/queries/user/useMyProfileQuery';
import { checkAuthentication } from '@/utils/helpers';

import useMounted from '@/hooks/useMounted';
import { checkAuthentication } from '@/utils/helpers';
import useToast from '@/v1/base/Toast/useToast';

import FloatingButton from '@/v1/base/FloatingButton';
import Loading from '@/v1/base/Loading';
import TopHeader from '@/v1/base/TopHeader';
import DetailBookGroupCard, {
DetailBookGroupCardSkeleton,
} from '@/v1/bookGroup/DetailBookGroupCard';
import SearchGroupInput from '@/v1/bookGroup/SearchGroup';
import SimpleBookGroupCard, {
SimpleBookGroupCardSkeleton,
} from '@/v1/bookGroup/SimpleBookGroupCard';

const GroupPage = () => {
const router = useRouter();
const { show: showToast } = useToast();

const isAuthenticated = checkAuthentication();

const handleSearchInputClick = () => {
alert('아직 준비 중인 기능이에요.');
};

const handleCreateGroupClick = () => {
isAuthenticated
? router.push('/group/create')
: showToast({ message: '로그인 후에 이용할 수 있어요!', type: 'normal' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

삼항연산자보다 if else를 사용하는 편이 더 가독성 좋을 것 같아요! 😀


return;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

유저 로그인 유무에 따라 Toast, Routing 기능을 적용하였습니다

더 자연스러운 토스트 메시지가 있다면 코멘트로 기재해주셔도 좋아요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 메세지 괜찮아요! 😲👍🏻


return (
<>
<TopHeader text="Group" />
Expand All @@ -36,9 +52,10 @@ const GroupPage = () => {
<EntireBookGroupList />
</SSRSafeSuspense>
</div>
{/* <Link href={'/group/create'}>
<FloatingButton position="bottom-right" />
</Link> */}
<FloatingButton
onClick={handleCreateGroupClick}
position="bottom-right"
/>
</>
);
};
Expand Down
39 changes: 24 additions & 15 deletions src/v1/base/FloatingButton.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
import { IconPlus } from '@public/icons';
import { ComponentPropsWithoutRef } from 'react';
import { createPortal } from 'react-dom';

import { IconPlus } from '@public/icons';

import Portal from './Portal';

interface FloatingButtonProps extends ComponentPropsWithoutRef<'button'> {
position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
onClick?: () => void;
}

const getPositionClasses = (position: string) => {
switch (position) {
case 'top-left': {
return 'top-[6.4rem] left-[1.2rem]';
return 'top-[1.3rem] left-[1.7rem]';
}
case 'top-right': {
return 'top-[6.4rem] right-[1.2rem]';
return 'top-[1.3rem] right-[1.7rem]';
}
case 'bottom-left': {
return 'bottom-[7.2rem] left-[1.2rem]';
return 'bottom-[8.3rem] left-[1.7rem]';
}
case 'bottom-right': {
return 'bottom-[7.2rem] right-[1.2rem]';
return 'bottom-[8.3rem] right-[1.7rem]';
}
Comment on lines -12 to +24
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

바뀐 BottomNavigation에 맞게 포지션 옵션을 수정했습니다

}
};

const FloatingButton = ({ position, ...props }: FloatingButtonProps) => {
const FloatingButton = ({
position,
onClick,
...props
}: FloatingButtonProps) => {
const positionClasses = getPositionClasses(position);

return createPortal(
<button
className={`${positionClasses} fixed left-[50%] top-[50%] flex h-[5.1rem] w-[5.1rem] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-main-900`}
{...props}
>
<IconPlus />
</button>,
document.body
return (
<Portal id="createBookGroupButton">
<button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3;

html id 속성에 들어갈 값이라 기왕이면 -로 구분하면 좋을 것 같아요! floating-button-portal..? 어떠신가용.. 🙄

className={`${positionClasses} absolute flex h-[5.1rem] w-[5.1rem] items-center justify-center rounded-full bg-main-900`}
onClick={onClick}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3;

shadow 스타일을 적용해야하는데.. 따로 config에 작성하기에는 불편해서 살펴보니, shadow-bookcover 정도 주면 괜찮아보여요.. 적용하면 어떨까요..!? 😀

{...props}
>
<IconPlus className="fill-white" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

body태그에 position: relative속성이 있어 absolute속성을 통해 포지션을 잡아봤어요

fixed로 스타일링하는대에 어려움이있었어요
Portal 컴포넌트가 body태그 이외에 main태그로도 적용할 수 있도록 수정한다면
fixed 속성을 적용하는게 가능할 것 같아요

이후에 여유가 된다면 Portal 컴포넌트를 수정하여 함께 적용해보도록 할게요

</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시.. 제가 figma에서 floating button 디자인을 조금 수정해봤는데.. 반영해주실 수 있을까요?! 🥹🙇🏻‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

그럼요

</Portal>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/v1/bookGroup/SearchGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SearchGroup = ({ onClick }: SearchGroup) => {
return (
<div className="flex">
<div className="rounded-bl-[0.4rem] rounded-tl-[0.4rem] border-[0.1rem] border-r-[0rem] border-solid border-black-100 bg-[#fffff] pl-[1rem] pt-[0.8rem]">
<IconSearch fill="#AFAFAF" />
<IconSearch className="fill-placeholder" />
</div>
<input
id="groupSearching"
Expand Down
Loading