Skip to content

Commit

Permalink
fix: 불필요한 코드 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
rabyeoljji committed Dec 27, 2024
1 parent 1898a05 commit 51b2777
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 77 deletions.
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"remark": "^15.0.1",
"remark-gfm": "^4.0.0",
"remirror": "^2.0.39",
"strip-markdown": "^6.0.0",
"swiper": "^11.1.15",
"tailwind-merge": "^2.2.2",
"tailwind-scrollbar-hide": "^1.1.7",
Expand Down
11 changes: 2 additions & 9 deletions src/app/(routes)/document/[id]/(main)/@header/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Text from '@/shared/components/ui/text'
import { cn } from '@/shared/lib/utils'
import Link from 'next/link'
import { useParams, useRouter } from 'next/navigation'
import usePreviousPath from '@/shared/hooks/use-previous-path'
import GoBackButton from '@/shared/components/custom/go-back-button'
import { getRelativeTime } from '@/shared/utils/date'
import { useQuery } from '@tanstack/react-query'
Expand All @@ -31,7 +30,6 @@ const Header = () => {
const [isTitleHidden, setIsTitleHidden] = useState(false)
const titleRef = useRef<HTMLHeadingElement | null>(null)

const { getPreviousPath } = usePreviousPath({ getCustomPath: true })
const { data } = useQuery(queries.document.item(Number(id)))
const { mutate: deleteDocumentMutation } = useDeleteDocument()

Expand All @@ -57,11 +55,6 @@ const Header = () => {
}
}, [])

const handleClickCancel = () => {
const previousPath = getPreviousPath()
previousPath ? router.replace(previousPath) : router.replace('/')
}

const handleClickDownload = (menuItemKey: string) => {
if (menuItemKey === 'download') {
alert('clicked ' + menuItemKey)
Expand All @@ -70,7 +63,7 @@ const Header = () => {

const handleClickDelete = () => {
deleteDocumentMutation([Number(id)], {
onSuccess: () => router.push('/document'),
onSuccess: () => router.replace('/document'),
})
}
return (
Expand All @@ -83,7 +76,7 @@ const Header = () => {
>
<div className="flex size-full items-center justify-between">
<div className="flex items-center">
<GoBackButton icon="cancel" onClick={handleClickCancel} />
<GoBackButton icon="cancel" />
{isTitleHidden && (
<Text as="h2" typography="text1-medium" className="ml-[16px]">
{data?.documentName}
Expand Down
14 changes: 1 addition & 13 deletions src/app/(routes)/notification/@header/default.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
'use client'

import GoBackButton from '@/shared/components/custom/go-back-button'
import Text from '@/shared/components/ui/text'
import usePreviousPath from '@/shared/hooks/use-previous-path'
import { useRouter } from 'next/navigation'

const Header = () => {
const router = useRouter()
const { getPreviousPath } = usePreviousPath({ getCustomPath: true })

const handleClick = () => {
const previousPath = getPreviousPath()
previousPath ? router.push(previousPath) : router.push('/')
}

return (
<header className="relative flex h-[54px] w-full items-center bg-background-base-01 px-[16px]">
<GoBackButton onClick={handleClick} />
<GoBackButton />
<Text typography="subtitle2-medium" className="center">
알림
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import Text from '@/shared/components/ui/text'
import { useEffect, useMemo, useState } from 'react'
import {
calculateAvailableQuizCount,
extractPlainText,
formatFileSize,
generateMarkdownFromFile,
isValidFileType,
} from '../../utils'
import { extractPlainText } from '@/features/search/utils'
import Editor from '@/features/write/components/editor'
import { useDirectoryContext } from '@/features/directory/contexts/directory-context'
import { useCreateDocument } from '@/requests/document/hooks'
Expand Down
36 changes: 11 additions & 25 deletions src/features/document/components/swipeable-document-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import Tag from '@/shared/components/ui/tag'
import { useRouter } from 'next/navigation'
import MoveDocumentDrawer from '@/features/document/components/move-document-drawer'
import DeleteDocumentSwipeButton from '../delete-document-swipe-button'
import usePreviousPath from '@/shared/hooks/use-previous-path'
import { useDocumentContext } from '../../contexts/document-context'
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import stripMarkdown from 'strip-markdown'
import { extractPlainText } from '../../utils'

interface DocumentProps {
id: number
Expand Down Expand Up @@ -47,7 +43,6 @@ const SwipeableDocumentCard = ({
const x = useMotionValue(0)
const controls = useAnimation()
const router = useRouter()
const { setPreviousPath } = usePreviousPath()

const isChecked = checkDoc.isChecked(id)

Expand All @@ -68,28 +63,19 @@ const SwipeableDocumentCard = ({
setIsDragging(false)
}

const getTextRemoveMarkdownSyntax = (markdown: string): string => {
const result = unified()
.use(remarkParse) // 마크다운 파싱
.use(stripMarkdown) // 문법 제거
.use(remarkStringify)
.processSync(markdown) // 동기 처리

return String(result) // 결과 반환
const handleClickCard = () => {
if (isSelectMode) {
handleCheckedChange(!isChecked)
return
}
if (!isDragging && !isSwiped) {
router.push(`/document/${id}`)
}
}

return (
<div
onClick={() => {
if (isSelectMode) {
handleCheckedChange(!isChecked)
return
}
if (!isDragging && !isSwiped) {
setPreviousPath('/document')
router.push(`/document/${id}`)
}
}}
onClick={handleClickCard}
className={cn(
`relative flex h-[104px] max-w-full items-center overflow-hidden rounded-[16px] bg-white px-[16px] pb-[20px] pt-[17px] shrink-0 cursor-pointer`,
className
Expand Down Expand Up @@ -138,7 +124,7 @@ const SwipeableDocumentCard = ({
typography="text1-regular"
className="w-[calc(100%-55px)] truncate text-nowrap break-all text-text-sub"
>
{getTextRemoveMarkdownSyntax(content)}
{extractPlainText(content)}
</Text>

<Text typography="text2-medium" className="flex w-fit items-center text-text-sub">
Expand Down
20 changes: 16 additions & 4 deletions src/features/document/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { marked } from 'marked'
import * as pdfjs from 'pdfjs-dist'
import '@/shared/utils/pdf'
import { TextItem, TextMarkedContent } from 'pdfjs-dist/types/src/display/api'
import mammoth from 'mammoth'

/** markdown string을 받아 markdown 문법을 제거해 텍스트만 반환하는 함수 */
export function extractPlainText(markdownText: string): string {
// 마크다운 -> HTML 변환
const html = marked(markdownText, { headerIds: false, mangle: false })

// HTML -> 텍스트 추출
const div = document.createElement('div')
div.innerHTML = html
return div.textContent || ''
}

// 1000자 당, 2문제 생성을 가정
export const QUESTIONS_PER_THOUSAND = 2

Expand All @@ -12,10 +24,6 @@ export const calculateAvailableQuizCount = (charCount: number) => {
return quizCount
}

function isTextItem(item: TextItem | TextMarkedContent): item is TextItem {
return 'str' in item && 'transform' in item
}

export const formatFileSize = (size: number) => {
if (size < 1024) return `${size} B`
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`
Expand Down Expand Up @@ -50,6 +58,10 @@ export const isValidFileType = (file: File): boolean => {
)
}

function isTextItem(item: TextItem | TextMarkedContent): item is TextItem {
return 'str' in item && 'transform' in item
}

/** 입력받은 file(pdf, docx, txt)을 markdown으로 변환해 반환하는 함수 */
export const generateMarkdownFromFile = async (file: File): Promise<string> => {
if (!file) {
Expand Down
12 changes: 1 addition & 11 deletions src/features/search/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Text from '@/shared/components/ui/text'
import React from 'react'
import { marked } from 'marked'
import { extractPlainText } from '@/features/document/utils'

/**
* 텍스트에서 키워드를 강조하는 함수
Expand Down Expand Up @@ -56,16 +56,6 @@ export function highlightAndTrimText(text: string, keyword: string): JSX.Element
)
}

export function extractPlainText(markdownText: string): string {
// 마크다운 -> HTML 변환
const html = marked(markdownText, { headerIds: false, mangle: false })

// HTML -> 텍스트 추출
const div = document.createElement('div')
div.innerHTML = html
return div.textContent || ''
}

/** 마크다운 텍스트를 받아
* 문법을 제거하고 키워드에 강조를 해서 반환하는 함수
*/
Expand Down

0 comments on commit 51b2777

Please sign in to comment.