-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 모집 공고에 시간 추가 및 지원서 정렬 추가 #131
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
The head ref may contain hidden characters: "130-feat-\uBAA8\uC9D1-\uACF5\uACE0\uC5D0-\uC2DC\uAC04-\uCD94\uAC00-\uBC0F-\uC9C0\uC6D0\uC11C-\uC815\uB82C-\uCD94\uAC00"
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc5d9f6
feat: 모집 공고에 시작, 종료 시간 추가
ff1451 9eb540c
feat: 지원자 목록 정렬 추가 및 시간 표시
ff1451 9040175
feat: 채팅, 모집 공고 링크 파싱 기능 추가
ff1451 795d226
feat: 인스타그램 파싱 추가
ff1451 4c9b561
fix: prettier error
ff1451 f89bb16
refactor: 유틸 분리 및 타입 변경
ff1451 a642c55
chore: 타입 변경 반영
ff1451 104d73e
chore: 동일 스타일 통합 및 entity 확장 사용
ff1451 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
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,157 @@ | ||
| import { Fragment, useMemo } from 'react'; | ||
| import { cn } from '@/utils/ts/cn'; | ||
|
|
||
| const URL_REGEX = /(?:https?:\/\/|www\.)[^\s]+/gi; | ||
| const TRAILING_PUNCTUATION_REGEX = /[)\]}>.,!?;:'"`]+$/; | ||
| const INSTAGRAM_HANDLE_REGEX = | ||
| /(^|[^A-Za-z0-9._])(@[A-Za-z0-9_](?:[A-Za-z0-9._]{0,28}[A-Za-z0-9_])?)(?=$|[^A-Za-z0-9._])/g; | ||
|
|
||
| type LinkPart = | ||
| | { | ||
| type: 'text'; | ||
| value: string; | ||
| } | ||
| | { | ||
| type: 'link'; | ||
| value: string; | ||
| href: string; | ||
| }; | ||
|
|
||
| interface LinkifiedTextProps { | ||
| text: string; | ||
| className?: string; | ||
| linkClassName?: string; | ||
| } | ||
|
|
||
| const normalizeHref = (url: string) => { | ||
| if (/^https?:\/\//i.test(url)) { | ||
| return url; | ||
| } | ||
|
|
||
| return `https://${url}`; | ||
| }; | ||
|
|
||
| const splitTrailingPunctuation = (value: string) => { | ||
| const trailing = value.match(TRAILING_PUNCTUATION_REGEX)?.[0] ?? ''; | ||
|
|
||
| if (!trailing) { | ||
| return { link: value, trailing: '' }; | ||
| } | ||
|
|
||
| return { | ||
| link: value.slice(0, -trailing.length), | ||
| trailing, | ||
| }; | ||
| }; | ||
|
|
||
| const parseLinkParts = (text: string): LinkPart[] => { | ||
| const parts: LinkPart[] = []; | ||
| const matcher = new RegExp(URL_REGEX); | ||
| let lastIndex = 0; | ||
| let match = matcher.exec(text); | ||
|
|
||
| while (match) { | ||
| const matchedText = match[0]; | ||
| const startIndex = match.index; | ||
| const endIndex = startIndex + matchedText.length; | ||
|
|
||
| if (startIndex > lastIndex) { | ||
| parts.push({ type: 'text', value: text.slice(lastIndex, startIndex) }); | ||
| } | ||
|
|
||
| const { link, trailing } = splitTrailingPunctuation(matchedText); | ||
|
|
||
| if (link) { | ||
| parts.push({ type: 'link', value: link, href: normalizeHref(link) }); | ||
| } | ||
|
|
||
| if (trailing) { | ||
| parts.push({ type: 'text', value: trailing }); | ||
| } | ||
|
|
||
| lastIndex = endIndex; | ||
| match = matcher.exec(text); | ||
| } | ||
|
|
||
| if (lastIndex < text.length) { | ||
| parts.push({ type: 'text', value: text.slice(lastIndex) }); | ||
| } | ||
|
|
||
| return parts; | ||
| }; | ||
|
|
||
| const parseInstagramParts = (text: string): LinkPart[] => { | ||
| const parts: LinkPart[] = []; | ||
| const matcher = new RegExp(INSTAGRAM_HANDLE_REGEX); | ||
| let lastIndex = 0; | ||
| let match = matcher.exec(text); | ||
|
|
||
| while (match) { | ||
| const prefix = match[1] ?? ''; | ||
| const handle = match[2]; | ||
| const startIndex = match.index; | ||
| const handleStartIndex = startIndex + prefix.length; | ||
| const handleEndIndex = handleStartIndex + handle.length; | ||
|
|
||
| if (startIndex > lastIndex) { | ||
| parts.push({ type: 'text', value: text.slice(lastIndex, startIndex) }); | ||
| } | ||
|
|
||
| if (prefix) { | ||
| parts.push({ type: 'text', value: prefix }); | ||
| } | ||
|
|
||
| parts.push({ | ||
| type: 'link', | ||
| value: handle, | ||
| href: `https://instagram.com/${handle.slice(1)}`, | ||
| }); | ||
|
|
||
| lastIndex = handleEndIndex; | ||
| match = matcher.exec(text); | ||
| } | ||
|
|
||
| if (lastIndex < text.length) { | ||
| parts.push({ type: 'text', value: text.slice(lastIndex) }); | ||
| } | ||
|
|
||
| return parts; | ||
| }; | ||
|
|
||
| function LinkifiedText({ text, className, linkClassName }: LinkifiedTextProps) { | ||
| const parts = useMemo(() => { | ||
| return parseLinkParts(text).flatMap((part) => { | ||
| if (part.type === 'link') { | ||
| return [part]; | ||
| } | ||
|
|
||
| return parseInstagramParts(part.value); | ||
| }); | ||
| }, [text]); | ||
|
|
||
| const content = parts.map((part, index) => { | ||
| if (part.type === 'text') { | ||
| return <Fragment key={`text-${index}`}>{part.value}</Fragment>; | ||
| } | ||
|
|
||
| return ( | ||
| <a | ||
| key={`link-${index}`} | ||
| href={part.href} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className={cn('text-primary break-all underline', linkClassName)} | ||
| > | ||
| {part.value} | ||
| </a> | ||
| ); | ||
| }); | ||
|
|
||
| if (className) { | ||
| return <span className={className}>{content}</span>; | ||
| } | ||
|
|
||
| return <>{content}</>; | ||
| } | ||
|
|
||
| export default LinkifiedText; |
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
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
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.