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

[Feature/BAR-225] 맞춤법 검사 결과 카드 UI 구현 #51

Merged
merged 15 commits into from
Feb 9, 2024

Conversation

dmswl98
Copy link
Member

@dmswl98 dmswl98 commented Feb 6, 2024

Summary

구현 내용 및 작업한 내역을 요약해서 적어주세요

To Reviewers

PR을 볼 때 주의깊게 봐야하거나 말하고 싶은 점을 적어주세요

2024-02-06.10.47.03.mov
  • hover, active 상태에 따라 색상이 변해야 하는 아이콘의 경우 컴포넌트로 작성했어요.
  • 아직 WRITE_INPUT_EXAMPLE 값으로 맞춤법 검사를 진행하고 있는데, 추후 사용자가 작성한 글에 따라 맞춤법 검사를 진행하도록 구현할 예정입니다.
  • api/spell-check의 반환 데이터 구조를 변경해보았는데 괜찮은지....ㅎㅎ
  • 맞춤법 결과에 대한 스타일링 부분 로직이 효율적인지 봐주세요.
export interface Suggestion {
  /* 맞춤법 오류 종류 */
  type: keyof typeof SPELLCHECK_TYPE;
  /* 맞춤법 오류 어절 */
  errorToken: string;
  /* 맞춤법 정정 어절 */
  correct: string;
}

export interface SpellCheckResult {
  suggestions: Suggestion[];
  correction: string; // 맞춤법 오류가 모두 정정된 문장
}

const getStyledSuggestion = (result: SpellCheckResult) => {
  const { suggestions, correction } = result;

  const init: (string | React.JSX.Element)[] = [];
  // 맞춤법 정정 어절 -> '안녕하세요|드립니다 다름이|추가해 주실'
  const pattern = suggestions.map(({ correct }) => correct).join('|');
  // 맞춤법 정정 어절 기반의 정규식 생성 -> /안녕하세요|드립니다 다름이|추가해 주실/g
  const regex = new RegExp(`${pattern}`, 'g');

  const splitedCorrection = correction.split(regex);
  const matches = correction.match(regex)!;

  // 맞춤법 정정 어절에 각 맞춤법 타입(spell, space, doubt)에 맞는 스타일링 적용
  const styledSuggestionTag = suggestions.map(({ type, correct }) => (
    <StyledSuggestion key={correct} type={type}>
      {correct}
    </StyledSuggestion>
  ));

  // 기존 문장에 스타일링 적용된 어절 삽입
  const styledSuggestion = splitedCorrection.reduce(
    (arr, element, index) =>
      matches[index]
        ? [...arr, element, styledSuggestionTag[index]]
        : [...arr, element],
    init,
  );

  return styledSuggestion;
};

How To Test

PR의 기능을 확인하는 방법을 상세하게 적어주세요

const WritePage = () => {
  const writeInput = useInput({ id: 'write-input' });

  return (
    <WritePageTab
      write={
        <>
          <WriteGuide />
          <WriteHistory data={MOCK} />
          <WriteTodayCard /> // 추가
          <WriteInput inputProps={writeInput} />
        </>
      }
      template={null}
    />
  );
};

@dmswl98 dmswl98 changed the title [Feature/BAR-225] 맞춤법 결과 카드 UI 구현 [Feature/BAR-225] 맞춤법 검사 결과 카드 UI 구현 Feb 6, 2024
Copy link
Contributor

@miro-ring miro-ring left a comment

Choose a reason for hiding this comment

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

Comment on lines 19 to 26
let correction = sentence;

suggestions.forEach(({ errorToken, correct }) => {
const regex = new RegExp(`${errorToken}`, 'g');
correction = correction.replace(regex, correct);
});

return correction;
Copy link
Contributor

Choose a reason for hiding this comment

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

reduce를 사용해서 정리할 수 있지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

5e3bfae 반영해두었습니다!

@@ -0,0 +1,17 @@
import type { SVGProps } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

요 형태로 사용하는게 더 편하신가요?

Copy link
Member Author

@dmswl98 dmswl98 Feb 7, 2024

Choose a reason for hiding this comment

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

fc8df1c svg로 변경해두었습니다!

@dmswl98
Copy link
Member Author

dmswl98 commented Feb 7, 2024

@dongkyun-dev 말씀해주신 부분 모두 반영해두었습니다~

최종 디자인 수정 사항

image

Comment on lines 8 to 9
import { type SpellCheckResponse } from '../../../../../api/spell/types';
import { usePostSpellCheck } from '../../../../../queries/useSpellCheck';
Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 뎁스 깊어지는건 절대경로 사용하면 어떨까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

308cc12 적용해두었습니다!

import { COLORS } from '@styles/tokens';

export const icon = style({
transition: 'all 100ms ease-in-out',
Copy link
Contributor

Choose a reason for hiding this comment

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

fill 속성에만 적용해도 괜찮을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

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

ec5b8b2 적용해두었습니당

Copy link
Contributor

@miro-ring miro-ring left a comment

Choose a reason for hiding this comment

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

고생하셧습니다!

@dmswl98 dmswl98 merged commit a293fca into main Feb 9, 2024
@dmswl98 dmswl98 deleted the feature/BAR-225 branch February 9, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants