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

refactor: 각종 리팩터링 모음 #391

Merged
merged 8 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const CheckboxLabel = styled.label`
padding: 0 12px;

font-size: 1.2rem;
line-height: 1.6rem;
color: ${(props) => props.theme.color.sub};

background-color: ${(props) => props.theme.color.grayLight};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/@common/Confirm/Confirm.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Button = styled.button`

font-size: 1.5rem;
font-weight: normal;
line-height: 2rem;
letter-spacing: 1px;

border-radius: 8px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { styled } from 'styled-components';

export const Wrapper = styled.span`
display: inline-flex;
align-items: center;
font-size: 1.8rem;
line-height: 2.2rem;
`;
10 changes: 9 additions & 1 deletion frontend/src/components/@common/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren, forwardRef } from 'react';
import { PropsWithChildren, forwardRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { CloseButton, ModalBox, ModalContent } from './Modal.style';

Expand All @@ -13,6 +13,14 @@ const Modal = forwardRef<HTMLDialogElement, ModalProps>(function Modal(
) {
const root = document.getElementById('modal-root') ?? document.body;

useEffect(() => {
if (!isOpen) {
document.body.style.position = 'relative';
return;
}
document.body.style.position = 'fixed';
}, [isOpen]);
Comment on lines +16 to +22
Copy link
Member

Choose a reason for hiding this comment

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

C

이거는 어떤 역할인가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

모바일에서 모달이 열리면 뒤에 스크롤이 생기더라구요! 그래서 추가했습니다


return createPortal(
isOpen && (
<ModalBox aria-modal="true" ref={ref}>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/@common/Navbar/Navbar.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export const NavItem = styled.div`
`;

export const NavLabel = styled.p<{ $active?: boolean }>`
font-size: 1rem;
font-size: 1.2rem;
font-weight: 700;
line-height: 1.5rem;
color: ${({ $active, theme: { color } }) =>
$active ? color.fontPrimaryForBackground : color.subLight};
`;
4 changes: 2 additions & 2 deletions frontend/src/components/@common/Select/Select.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const Backdrop = styled.div`
height: 100%;
`;

export const OptionBox = styled.ul`
export const OptionBox = styled.ul<{ $top?: number }>`
position: absolute;
z-index: ${({ theme: { zIndex } }) => zIndex.modal};
top: 32px;
top: ${(props) => props.$top ?? 32}px;

width: 100%;

Expand Down
23 changes: 19 additions & 4 deletions frontend/src/components/@common/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useCallback } from 'react';
import { useEffect, useCallback, useState, useRef } from 'react';
import SvgIcons from 'components/@common/SvgIcons/SvgFill';
import { Backdrop, IconArea, OptionBox, OptionItem, SelectedValue, Wrapper } from './Select.style';
import useToggle from 'hooks/useToggle';
Expand All @@ -11,9 +11,14 @@ interface SelectProps {
placeholder?: string;
}

const DEFAULT_HEIGHT = 32;

const Select = ({ value, options, onChange, placeholder }: SelectProps) => {
const { isOn: isOpen, off: close, toggle } = useToggle();

const [optionHeight, setOptionHeight] = useState(DEFAULT_HEIGHT);
Copy link
Member

Choose a reason for hiding this comment

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

C

굳이 새로운 상태로 useEffect 안에서 처리하지 않아도 구현이 가능할 것 같아요

Suggested change
const [optionHeight, setOptionHeight] = useState(DEFAULT_HEIGHT);
const currentPos = selectRef.current?.getBoundingClientRect();
const optionHeight = options.length * 40;
const topPosition =
currentPos && currentPos.top + optionHeight + DEFAULT_HEIGHT > window.innerHeight
? -optionHeight
: DEFAULT_HEIGHT;

const selectRef = useRef<HTMLDivElement | null>(null);

const select = (option: string) => {
onChange?.(option);
close();
Expand All @@ -27,17 +32,27 @@ const Select = ({ value, options, onChange, placeholder }: SelectProps) => {
);

useEffect(() => {
if (!selectRef.current) return;
if (!isOpen) return;

const currentPos = selectRef.current.getBoundingClientRect();
const optionHeight = options.length * 40;

if (currentPos.top + optionHeight + DEFAULT_HEIGHT > window.innerHeight) {
setOptionHeight(-optionHeight);
} else {
setOptionHeight(DEFAULT_HEIGHT);
}

window.addEventListener('keyup', closeOnEscape);

return () => {
window.removeEventListener('keyup', closeOnEscape);
};
}, [isOpen, closeOnEscape]);
}, [isOpen, closeOnEscape, options.length]);

return (
<Wrapper>
<Wrapper ref={selectRef}>
<SelectedValue
type="button"
onClick={toggle}
Expand All @@ -52,7 +67,7 @@ const Select = ({ value, options, onChange, placeholder }: SelectProps) => {
{isOpen && (
<>
<Backdrop onClick={close} />
<OptionBox role="menu">
<OptionBox role="menu" $top={optionHeight}>
{options.map((option) => {
const selectOnClick = () => select(option);
const selectOnEnterOrSpace = ({ key }: React.KeyboardEvent<HTMLLIElement>) => {
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/@common/Toast/Toast.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@ export const MessageArea = styled.div`
export const Title = styled.p`
width: 100%;
margin-bottom: 8px;

font-size: 2rem;
font-weight: 900;
font: 900 2rem/2.4rem NanumSquareRound;
vertical-align: center;
`;

export const Message = styled.p`
width: 100%;
font-size: 1.8rem;
font-weight: 600;
font: 600 1.8rem/2.2rem NanumSquareRound;
`;

export const ToastListWrapper = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const Nickname = styled.p`
width: 100%;

font-size: 1.8rem;
line-height: 2.2rem;
text-overflow: ellipsis;
white-space: nowrap;
`;
Expand All @@ -54,26 +55,23 @@ export const ContentRow = styled.div`
display: flex;
align-items: end;
justify-content: space-between;

font-size: 1.4rem;
line-height: 1.8rem;
`;

export const DictionaryPlantName = styled.p`
overflow: hidden;

width: 70%;

font-size: 1.4rem;
color: ${(props) => props.theme.color.grayDark};
text-overflow: ellipsis;
white-space: nowrap;
`;

export const DaySince = styled.p`
font-size: 1.4rem;
`;

export const DaySinceNumber = styled.span`
margin-left: 2px;
font-size: 1.8rem;
margin-left: 1px;
font-weight: 900;
color: ${(props) => props.theme.color.primary};
`;
5 changes: 2 additions & 3 deletions frontend/src/components/petPlant/PetPlantCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ContentArea,
ContentRow,
CrownArea,
DaySince,
DaySinceNumber,
DictionaryPlantName,
ImageArea,
Expand Down Expand Up @@ -35,9 +34,9 @@ const PetPlantCard = ({
<Nickname aria-label="식물 별명">{nickname} </Nickname>
<ContentRow>
<DictionaryPlantName aria-label="식물 종류">{dictionaryPlantName}</DictionaryPlantName>
<DaySince aria-label="식물과 같이 지낸 시간">
<p aria-label="식물과 같이 지낸 시간">
D+<DaySinceNumber>{daySince}</DaySinceNumber>
</DaySince>
</p>
</ContentRow>
</ContentArea>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ export const Text = styled.span`
`;

export const Strong = styled.strong`
font: ${({ theme }) => theme.font.dictContent};
font-size: 2.4rem;
font-weight: bold;
color: ${({ theme }) => theme.color.primary};
`;

Expand Down Expand Up @@ -161,8 +158,8 @@ export const EnvironmentTitle = styled.span`

export const ButtonArea = styled.div`
display: flex;
justify-content: space-between;
column-gap: 10px;
justify-content: space-between;
`;

const ButtonLink = styled(Link)`
Expand All @@ -174,7 +171,8 @@ const ButtonLink = styled(Link)`
height: 36px;

font-size: 1.5rem;
font-weight: 500;
font-weight: 700;
line-height: 1.8rem;
letter-spacing: 1px;

border-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ export const HiddenLabel = styled.label`

export const Input = styled.input`
height: 30px;

font-size: 2.5rem;
line-height: 3rem;
text-align: center;

border: none;

&:focus {
Expand Down Expand Up @@ -194,7 +197,8 @@ const Button = styled.button`
height: 36px;

font-size: 1.5rem;
font-weight: 500;
font-weight: 700;
line-height: 1.8rem;
letter-spacing: 1px;

border-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const PetPlantRegisterForm = (props: PetPlantRegisterFormProps) => {
const isValidForm = Object.values(form).every((value) => value !== '');

const addToast = useAddToast();
const { mutate: registerPetPlant } = useRegisterPetPlant();
const { mutate: registerPetPlant, isPending } = useRegisterPetPlant();

const setNickname = ({ target: { value } }: React.ChangeEvent<HTMLInputElement>) => {
dispatch({ type: 'SET', key: 'nickname', maxLength: NUMBER.maxNicknameLength, value });
Expand Down Expand Up @@ -232,7 +232,7 @@ const PetPlantRegisterForm = (props: PetPlantRegisterFormProps) => {
</Stack.Element>
<Stack.Element height={STACK_ELEMENT_HEIGHT}>
<Center>
<Button type="submit" disabled={!isValidForm}>
<Button type="submit" disabled={!isValidForm || isPending}>
등록하기
</Button>
</Center>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ export const IconArea = styled.div`

width: 16px;
height: 100%;
margin-right: 12px;

font-size: 2rem;
margin-right: 8px;
`;

export const ItemHead = styled.p`
font-size: 1.4rem;
line-height: 1.8rem;
color: ${(props) => props.theme.color.sub};
`;

export const ItemContent = styled.p`
display: flex;
align-items: center;

margin-top: 8px;
font-size: 1rem;

font-size: 1.2rem;
line-height: 1.6rem;
`;
3 changes: 2 additions & 1 deletion frontend/src/components/petPlant/TimelineItemList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const TimelineItemList = ({ timelineItemList }: TimelineItemListProps) => (
<ItemContent>
{hasPrevious && (
<>
{previous}일 <SvgIcons icon="arrow-right-alt" color={theme.color.sub} />
{previous}일
<SvgIcons icon="arrow-right-alt" color={theme.color.sub} size={16} />
</>
)}
{current}일
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/search/SearchBox/SearchBox.style.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link } from 'react-router-dom';
import styled from 'styled-components';

export const Wrapper = styled.div<{ $fontSize: string }>`
export const Wrapper = styled.div<{ $fontSize: `${number}rem` }>`
position: relative;

display: flex;
Expand All @@ -10,6 +10,10 @@ export const Wrapper = styled.div<{ $fontSize: string }>`
width: 100%;

font-size: ${(props) => props.$fontSize};
line-height: ${(props) => {
const font = Number(props.$fontSize.slice(0, -3));
return `${Math.ceil(font * 1.2)}rem`;
}};
`;

export const InputBox = styled.div<{ $openBottom: boolean; $height: string }>`
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/search/SearchBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import theme from 'style/theme.style';
interface SearchBoxProps {
value: string;
height?: `${number}px`;
fontSize?: string;
fontSize?: `${number}rem`;
showResultSize?: number;
onChangeValue: (value: string) => void;
onResultClick?: (searchResult: DictionaryPlantNameSearchResult) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const Main = styled.main`
export const BackButton = styled.button`
display: flex;
align-items: center;
font-size: 2rem;
`;

export const BottomSheet = styled.div`
Expand Down Expand Up @@ -39,8 +38,7 @@ const Button = styled.button`
height: 36px;
padding: 0 1rem;

font-size: 1.5rem;
font-weight: 500;
font: 500 1.5rem/ 1.8rem NanumSquareRound;
letter-spacing: 1px;

border-radius: 4px;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/GardenPostList/GardenPostList.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { styled } from 'styled-components';

export const Main = styled.main`
position: relative;

width: 100%;
height: calc(100% - 90px);
margin-bottom: 70px;
padding: 8px;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const FilterTag = styled.p`
display: flex;
column-gap: 4px;
align-items: center;

font-size: 1.4rem;
line-height: 1.8rem;
`;

export const DeleteFilterButton = styled.button`
Expand Down
Loading