Repository navigation
[FEAT] 홈 투두 생성 모달 하위 태스크/텍스트 입력 UX 개선 #158
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90223a4
feat(web): 메모 필드 300자 제한 스키마 검증 추가 (#157)
kimminna 9e9c6ce
feat(web): 메모 필드 자동 높이 조절 및 스크롤 처리 (#157)
kimminna 994540d
feat(web): 하위 태스크 다중 입력 및 투두명 글자 수 제한 구현 (#157)
kimminna 6025373
fix(web): 완료된 투두 체크박스 비활성화 제거 (#157)
kimminna 847e704
fix(web): 하위 태스크 목록에 안정적인 id 기반 key 적용 (#157)
kimminna 8cc09da
refactor(web): 하위 태스크 입력 엔터·백스페이스 로직을 공통 유틸로 분리 (#157)
kimminna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 55 additions & 21 deletions
76
.../[locale]/(main)/(with-time-sidebar)/home/_components/todo-modal/CreateTodoTaskFields.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,76 @@ | ||
| import { Checkbox } from "@repo/timo-design-system/ui"; | ||
|
|
||
| import type { CreateTodoRequest } from "@/api/todo/todo-schema"; | ||
| import type { UseFormRegister } from "react-hook-form"; | ||
| import type { KeyboardEvent } from "react"; | ||
|
|
||
| const resizeTextarea = (element: HTMLTextAreaElement | null) => { | ||
| if (!element) return; | ||
| element.style.height = "auto"; | ||
| element.style.height = `${element.scrollHeight}px`; | ||
| }; | ||
|
|
||
| export interface CreateTodoTaskFieldsProps { | ||
| register: UseFormRegister<CreateTodoRequest>; | ||
| titleValue: string; | ||
| titlePlaceholder: string; | ||
| subtaskInput: string; | ||
| onTitleChange: (value: string) => void; | ||
| subtaskInputs: string[]; | ||
| subtaskPlaceholder: string; | ||
| onSubtaskInputChange: (value: string) => void; | ||
| registerSubtaskInputRef: ( | ||
| index: number, | ||
| ) => (element: HTMLTextAreaElement | null) => void; | ||
| onSubtaskInputChange: (index: number, value: string) => void; | ||
| onSubtaskInputKeyDown: ( | ||
| index: number, | ||
| event: KeyboardEvent<HTMLTextAreaElement>, | ||
| ) => void; | ||
| } | ||
|
|
||
| export const CreateTodoTaskFields = ({ | ||
| register, | ||
| titleValue, | ||
| titlePlaceholder, | ||
| subtaskInput, | ||
| onTitleChange, | ||
| subtaskInputs, | ||
| subtaskPlaceholder, | ||
| registerSubtaskInputRef, | ||
| onSubtaskInputChange, | ||
| onSubtaskInputKeyDown, | ||
| }: CreateTodoTaskFieldsProps) => { | ||
| return ( | ||
| <div className="flex w-full flex-col items-start gap-1.5"> | ||
| <div className="flex w-full items-center gap-2"> | ||
| <Checkbox checked={false} onChange={() => {}} disabled /> | ||
| <input | ||
| {...register("title")} | ||
| <div className="flex w-full items-center justify-center gap-2"> | ||
| <Checkbox checked={false} onChange={() => {}} /> | ||
| <textarea | ||
| value={titleValue} | ||
| ref={resizeTextarea} | ||
| onChange={(event) => { | ||
| onTitleChange(event.target.value); | ||
| resizeTextarea(event.currentTarget); | ||
| }} | ||
| placeholder={titlePlaceholder} | ||
| className="typo-headline-b-14 text-timo-black min-w-0 flex-1 outline-none" | ||
| /> | ||
| </div> | ||
| <div className="flex w-full items-center gap-2"> | ||
| <Checkbox checked={false} onChange={() => {}} disabled /> | ||
| <input | ||
| value={subtaskInput} | ||
| onChange={(event) => onSubtaskInputChange(event.target.value)} | ||
| placeholder={subtaskPlaceholder} | ||
| className="typo-body-r-12 text-timo-gray-800 min-w-0 flex-1 outline-none" | ||
| rows={1} | ||
| className="typo-headline-b-14 text-timo-black min-w-0 flex-1 resize-none overflow-hidden wrap-break-word outline-none" | ||
| /> | ||
| </div> | ||
|
|
||
| {subtaskInputs.map((value, index) => ( | ||
| <div | ||
| key={index} | ||
| className="flex w-full items-center justify-center gap-2" | ||
| > | ||
| <Checkbox checked={false} onChange={() => {}} /> | ||
| <textarea | ||
| value={value} | ||
| ref={registerSubtaskInputRef(index)} | ||
| onChange={(event) => { | ||
| onSubtaskInputChange(index, event.target.value); | ||
| resizeTextarea(event.currentTarget); | ||
| }} | ||
| onKeyDown={(event) => onSubtaskInputKeyDown(index, event)} | ||
| placeholder={subtaskPlaceholder} | ||
| rows={1} | ||
| className="typo-body-r-12 text-timo-gray-800 min-w-0 flex-1 resize-none overflow-hidden wrap-break-word outline-none" | ||
| /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...o-web/app/[locale]/(main)/(with-time-sidebar)/home/_hooks/todo-modal/use-subtask-field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { useController } from "react-hook-form"; | ||
|
|
||
| import type { CreateTodoRequest } from "@/api/todo/todo-schema"; | ||
| import type { KeyboardEvent } from "react"; | ||
| import type { Control } from "react-hook-form"; | ||
|
|
||
| const MAX_SUBTASK_COUNT = 10; | ||
|
|
||
| export interface UseSubtaskFieldParams { | ||
| control: Control<CreateTodoRequest>; | ||
| } | ||
|
|
||
| export const useSubtaskField = ({ control }: UseSubtaskFieldParams) => { | ||
| const { field } = useController({ name: "subtasks", control }); | ||
| const [subtaskInputs, setSubtaskInputs] = useState<string[]>([""]); | ||
| const inputRefs = useRef<Array<HTMLTextAreaElement | null>>([]); | ||
| const pendingFocusIndex = useRef<number | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (pendingFocusIndex.current === null) return; | ||
|
|
||
| const index = pendingFocusIndex.current; | ||
| pendingFocusIndex.current = null; | ||
|
|
||
| const element = inputRefs.current[index]; | ||
| if (!element) return; | ||
|
|
||
| element.focus(); | ||
| const caretPosition = element.value.length; | ||
| element.setSelectionRange(caretPosition, caretPosition); | ||
| }, [subtaskInputs.length]); | ||
|
|
||
| const syncFormValue = (inputs: string[]) => { | ||
| field.onChange(inputs.map((input) => input.trim()).filter(Boolean)); | ||
| }; | ||
|
|
||
| const registerInputRef = | ||
| (index: number) => (element: HTMLTextAreaElement | null) => { | ||
| inputRefs.current[index] = element; | ||
| }; | ||
|
|
||
| const handleInputChange = (index: number, value: string) => { | ||
| setSubtaskInputs((prev) => { | ||
| const next = prev.map((input, i) => (i === index ? value : input)); | ||
| syncFormValue(next); | ||
| return next; | ||
| }); | ||
| }; | ||
|
|
||
| const handleInputKeyDown = ( | ||
| index: number, | ||
| event: KeyboardEvent<HTMLTextAreaElement>, | ||
| ) => { | ||
| if (event.key === "Enter" && !event.shiftKey) { | ||
| event.preventDefault(); | ||
|
|
||
| setSubtaskInputs((prev) => { | ||
| const isLastField = index === prev.length - 1; | ||
| const hasValue = Boolean(prev[index]?.trim()); | ||
| const canAddMore = prev.length < MAX_SUBTASK_COUNT; | ||
|
|
||
| if (!isLastField || !hasValue || !canAddMore) return prev; | ||
|
|
||
| pendingFocusIndex.current = prev.length; | ||
| return [...prev, ""]; | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const isFieldEmpty = subtaskInputs[index] === ""; | ||
| const canMergeIntoPrevious = index > 0; | ||
|
|
||
| if (event.key === "Backspace" && isFieldEmpty && canMergeIntoPrevious) { | ||
| event.preventDefault(); | ||
| pendingFocusIndex.current = index - 1; | ||
| setSubtaskInputs((prev) => prev.filter((_, i) => i !== index)); | ||
| } | ||
| }; | ||
|
|
||
| const reset = () => { | ||
| setSubtaskInputs([""]); | ||
| inputRefs.current = []; | ||
| }; | ||
|
|
||
| return { | ||
| subtaskInputs, | ||
| registerInputRef, | ||
| handleInputChange, | ||
| handleInputKeyDown, | ||
| reset, | ||
| }; | ||
| }; |
26 changes: 26 additions & 0 deletions
26
...imo-web/app/[locale]/(main)/(with-time-sidebar)/home/_hooks/todo-modal/use-title-field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { useController } from "react-hook-form"; | ||
|
|
||
| import type { CreateTodoRequest } from "@/api/todo/todo-schema"; | ||
| import type { Control } from "react-hook-form"; | ||
|
|
||
| import { | ||
| TITLE_MAX_WEIGHTED_LENGTH, | ||
| truncateToWeightedLength, | ||
| } from "@/app/[locale]/(main)/(with-time-sidebar)/home/_utils/text-length"; | ||
|
|
||
| export interface UseTitleFieldParams { | ||
| control: Control<CreateTodoRequest>; | ||
| } | ||
|
|
||
| export const useTitleField = ({ control }: UseTitleFieldParams) => { | ||
| const { field } = useController({ name: "title", control }); | ||
|
|
||
| const handleTitleChange = (value: string) => { | ||
| field.onChange(truncateToWeightedLength(value, TITLE_MAX_WEIGHTED_LENGTH)); | ||
| }; | ||
|
|
||
| return { | ||
| title: field.value, | ||
| handleTitleChange, | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.