Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions src/pages/CreateNameIds/hooks/useNameTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useState } from 'react'
import { useCreatingTimers } from '../../../shared/hooks/useCreatingTimers'

const useNameTag = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
아래 캡쳐의 각 태그들을 조작하는데 사용되는 함수들을 모은 hooks 입니다.
image

const { nameIds, addNameId, updateNameIds } = useCreatingTimers()
const [nameTag, setNameTag] = useState('')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
현재 input에 적고 있는 namTag의 값입니다.
최종적으로 timers의 name에 해당하게 됩니다.


const handleNameTagSubmit = e => {
e.preventDefault()
const trimmedName = nameTag.trim()

if (trimmedName) {
addNameId(`${Date.now()}${nameIds.length}`, trimmedName)
}

setNameTag('')
}
Comment on lines +8 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
input에 내용을 적고 추가를 눌렀을 때 발생하는 이벤트입니다.
addNameId(새로운 Id, 새로운 name) 함수를 이용 하여, 새로운 Name-Id 항목을 추가하게됩니다.
image
Name-Id 은 기존의 코드 tasks 내부에 들어있던 {id,task} 쌍을 의미하며(task의 이름이 혼용되어 name으로 변경하였습니다)
nameIds 는 기존 코드의 tasks에 해당합니다.

Copy link
Member

Choose a reason for hiding this comment

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

저는 개인적으로 함수의 인자를 객체 형태로 인자를 넘겨주는걸 선호해서 ㅎㅎ 이 부분은 수정해서 사용할게요.
함수로 넣으면 순서를 지켜야해서 휴먼 에러가 생길 확률이 높다고 생각해요.

const removeNameTag = removeId => {
const filteredNameIds = nameIds.filter(({ id }) => removeId !== id)
updateNameIds(filteredNameIds)
}
Comment on lines +18 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
클릭시 태그가 사라지는 기능을 위한 함수입니다.
삭제할 태그의 아이디를 받고, Name-Id 모음(기존의 tasks) 중에서 해당 아이디의 Name-Id 항목을 제거한 값으로, Name-Id 모음을 갱신합니다.

Copy link
Member

Choose a reason for hiding this comment

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

filteredNameIds는 id들의 조합 같은데 실제 반환값은 name객체의 모집군이라 filteredNames가 더 적합하지 않을까요?
해당 name를 사용해서 타이머를 생성하는 updateNameIds를 살펴보니 객체 구조이네용.

return {
nameTag,
setNameTag,
handleNameTagSubmit,
removeNameTag,
}
}

export default useNameTag
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import useCreateTasks from './hooks/useCreateTasks'
import useNavigation from 'shared/hooks/useNavigation'
import { Link, useLocation } from 'react-router-dom'
import { Link } from 'react-router-dom'

import * as S from './style'
import { colors } from 'shared/constants/colors'
Expand All @@ -10,23 +8,20 @@ import Text from 'shared/components/Text'
import Button from 'shared/components/Button'
import Input from 'shared/components/Input'
import Badge from 'shared/components/Badge'
import { useCreatingTimers } from '../../shared/hooks/useCreatingTimers'
import { useMemo } from 'react'
import useNameTags from './hooks/useNameTag'

const BUTTON_TEXT = Object.freeze({
VALID: '계속 진행하기',
INVALID: '할 일을 입력해주세요',
})

const CreateTask = () => {
const location = useLocation()
const { tasks, task, spareTime, setSpareTime, setTask, removeTask, handleSubmit, isValidTasks } =
useCreateTasks()
const CreateNameIds = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
네이밍을 변경하고, 함수들을 커스텀 훅스들로 이관하였습니다.
주요 이름 변경사항은
tasks => nameIds
task => name
변경이유는 다음과 같습니다

  • tasks라는 이름이 향후 사용될 timers와 혼동될 여지가 있고, 해당 변수가 name과 id 쌍들을 가진 배열이므로 변경하였습니다.
  • 또한 기존 코드에서 tasks는 timer의 id와 name , task는 name을 뜻하는등. tasks가 task의 복수형을 의미하지 않아 혼동이 있을 수 있습니다.

마이너한 이름 변동은 fileChanged에서 확인하시는 것이 좋을 것 같습니다!

Copy link
Member

Choose a reason for hiding this comment

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

name은 뒷플로우의 로직이 몰려있으니까 경현님 기준으로 맞추는게 맞다고 생각해요!
근데 nameIds는 조금 어색한 느낌이네요 ㅠㅠ 실제로는 name객체들의 모집군이지 않나요?

name.map(({id})=>id)

요 친구들 같이 느껴져요!

const { nameIds } = useCreatingTimers()
const { nameTag, setNameTag, removeNameTag, handleNameTagSubmit } = useNameTags()

const navigationValidator = () => {
const { spareTime } = location.state
setSpareTime(spareTime)
}

useNavigation(navigationValidator)
const isValidNames = useMemo(() => nameIds.length > 0, [nameIds])

return (
<S.Wrapper>
Expand All @@ -43,17 +38,17 @@ const CreateTask = () => {

<S.Section>
<S.TaskArea>
{tasks.map(({ id, task }) => (
<Badge key={id} onClick={() => removeTask(id)}>
{task}
{nameIds.map(({ id, name }) => (
<Badge key={id} onClick={() => removeNameTag(id)}>
{name}
</Badge>
))}
</S.TaskArea>
<S.Form onSubmit={handleSubmit}>
<S.Form onSubmit={handleNameTagSubmit}>
<Input
type="text"
value={task}
onChange={e => setTask(e.target.value)}
value={nameTag}
onChange={e => setNameTag(e.target.value)}
autoFocus={true}
required
/>
Expand All @@ -64,14 +59,14 @@ const CreateTask = () => {
</S.Section>

<S.ButtonArea>
<Link to="/createTimeDivider" state={{ spareTime, tasks }}>
<Button disabled={!isValidTasks}>
{!isValidTasks ? BUTTON_TEXT.INVALID : BUTTON_TEXT.VALID}
<Link to="/divideTime">
Copy link
Member

Choose a reason for hiding this comment

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

ㅎㅎㅎpath가 깔끔해서 좋네요

<Button disabled={!isValidNames}>
{!isValidNames ? BUTTON_TEXT.INVALID : BUTTON_TEXT.VALID}
</Button>
</Link>
</S.ButtonArea>
</S.Wrapper>
)
}

export default CreateTask
export default CreateNameIds
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useMemo, useState } from 'react'
import React, { useMemo } from 'react'
import { Link } from 'react-router-dom'

import * as S from './style'
import NavBar from 'shared/components/NavBar'
import Text from 'shared/components/Text'
import Button from 'shared/components/Button'
import Select from 'shared/components/Select'
import { TIME_TYPE, useCreatingTimers } from '../../shared/hooks/useCreatingTimers'

const HOUR_NUMBERS = Array.from({ length: 24 }, (_, i) => {
return { label: `${i}`, value: i }
Expand All @@ -15,26 +16,22 @@ const MINUTE_NUMBERS = Array.from({ length: 6 }, (_, i) => {
return { label: `${i * 10}`, value: i * 10 }
})

const TIME_TYPE = Object.freeze({
HOUR: 'hour',
MINUTE: 'minute',
})

const BUTTON_TEXT = Object.freeze({
VALID: '다음 단계',
INVALID: '시간을 입력해주세요',
})

const CreateTime = () => {
const [spareTime, setSpareTime] = useState({ [TIME_TYPE.HOUR]: '0', [TIME_TYPE.MINUTE]: '0' })
const CreateSpareTime = () => {
const { spareTime, updateSpareTime } = useCreatingTimers()

Comment on lines +24 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
spareTime이라는 변수를 지속적으로 사용하고, 이 페이지가 spareTime을 만드는 페이지라는 의미에서 페이지 이름을 변경하였습니다.

const isValidSpareTime = useMemo(
() => spareTime.hour !== '0' || spareTime.minute !== '0',
[spareTime],
)

const handleSpareTime = e => {
const handleSpareTimeChange = e => {
const { name, value } = e.target
setSpareTime({ ...spareTime, [name]: value })
updateSpareTime(name, value)
Comment on lines +32 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dahye1013
onChange의 핸들러로 사용되는 의미를 담기위해 변경하였습니다

Copy link
Member

Choose a reason for hiding this comment

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

change가 들어가니까 확실히 의미가 더 명시적인것 같네요 👍

}

return (
Expand All @@ -52,20 +49,22 @@ const CreateTime = () => {
name={'hour'}
data={HOUR_NUMBERS}
style={{ width: '10rem' }}
onChange={handleSpareTime}
onChange={handleSpareTimeChange}
value={spareTime[TIME_TYPE.HOUR]}
/>
<Text size={2}>시간</Text>
<Select
name={'minute'}
data={MINUTE_NUMBERS}
value={spareTime[TIME_TYPE.MINUTE]}
style={{ width: '10rem' }}
onChange={handleSpareTime}
onChange={handleSpareTimeChange}
/>
<Text size={2}>분</Text>
</S.Section>

<S.ButtonArea>
<Link to="/createTask" state={{ spareTime }}>
<Link to="/createNameIds">
<Button disabled={!isValidSpareTime}>
{!isValidSpareTime ? BUTTON_TEXT.INVALID : BUTTON_TEXT.VALID}
</Button>
Expand All @@ -75,4 +74,4 @@ const CreateTime = () => {
)
}

export default CreateTime
export default CreateSpareTime
File renamed without changes.
38 changes: 0 additions & 38 deletions src/pages/CreateTask/hooks/useCreateTasks.js

This file was deleted.

132 changes: 0 additions & 132 deletions src/pages/CreateTimeDivider/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { themeColors } from 'shared/constants/colors'
import styled from 'styled-components'
import Text from './Text'
import Text from '../../../shared/components/Text'

const TaskBox = ({ task, ...props }) => {
const { hour, minute } = task
const TaskBox = ({ timer, ...props }) => {
const { hour, minute, name } = timer

return (
<BoxContainer {...props}>
<BoxWrapper>
<Text size={1.4} color={themeColors.primary}>
{task.task}
{name}
Comment on lines +5 to +12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ljw0096
task의 이름이

  1. {time, hour, minute}을 담은 객체
  2. name의 의미
    하는 두가지 뜻으로 쓰여 task.task와 같은 구문이 생겼습니다.

따라서 task를 timer로 바꾸고, timer 객체 내의 name 값을 가져와 쓰는 방식으로 수정하였습니다

Copy link
Member

Choose a reason for hiding this comment

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

오 구조분해할당 👍

</Text>
<Text style={{ marginTop: '0.8rem', fontSize: '1.4rem' }}>
{hour.length === 1 ? `0${hour}` : hour} : {minute === '0' ? '00' : minute}
Expand Down
Loading