-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
16 changed files
with
243 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
62 changes: 62 additions & 0 deletions
62
weatherfit_refactoring/src/Components/Molecules/DetailCategory.tsx
This file contains 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,62 @@ | ||
'use client' | ||
|
||
import feedDummy from '../../../public/dummy_data/feed.json' | ||
import ButtonStore, { ButtonStyle } from '../Atoms/Button/ButtonStore' | ||
import { categories } from '../data/CategoryList' | ||
|
||
export default function DetailCategory(boardId: BOARDID) { | ||
const id = boardId.boardId | ||
const post = feedDummy.feed_data.find(post => post.boardId === Number(id)) | ||
|
||
if (!post) { | ||
return <div>게시물이 삭제되었습니다.</div> | ||
} | ||
|
||
const findParentCategory = (subCategory: string): string | null => { | ||
for (const [parentCategory, subCategories] of Object.entries(categories)) { | ||
if (subCategories.includes(subCategory)) { | ||
return parentCategory | ||
} | ||
} | ||
return null | ||
} | ||
|
||
const categoryGroups: Record<string, string[]> = post.category.reduce( | ||
(groups: Record<string, string[]>, subCategory) => { | ||
const parentCategory = findParentCategory(subCategory) | ||
if (parentCategory && !groups[parentCategory]) { | ||
groups[parentCategory] = [] | ||
} | ||
if (parentCategory) { | ||
groups[parentCategory].push(subCategory) | ||
} | ||
return groups | ||
}, | ||
{}, | ||
) | ||
|
||
const handleSelectCategory = () => { | ||
// 카테고리 선택한 거 누르면 검색된 페이지로 이동하게 | ||
} | ||
|
||
return ( | ||
<div className="font-NanumSquareRound flex w-screen justify-center bg-stone-200 flex-col p-3"> | ||
{Object.entries(categoryGroups).map( | ||
([parentCategory, subCategories], index) => ( | ||
<div key={index} className="m-2 flex items-center"> | ||
<span className="font-bold text-[16px] mr-3">{parentCategory}</span> | ||
{subCategories.map((subCategory, index) => ( | ||
<ButtonStore | ||
key={index} | ||
onClickFunction={handleSelectCategory} | ||
buttonStyle={ButtonStyle.CATEGORY_BTN_Y} | ||
style="mr-2"> | ||
{subCategory} | ||
</ButtonStore> | ||
))} | ||
</div> | ||
), | ||
)} | ||
</div> | ||
) | ||
} |
64 changes: 64 additions & 0 deletions
64
weatherfit_refactoring/src/Components/Molecules/DetailContent.tsx
This file contains 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,64 @@ | ||
'use client' | ||
|
||
import feedDummy from '../../../public/dummy_data/feed.json' | ||
|
||
export default function DetailContent(boardId: BOARDID) { | ||
const id = boardId.boardId | ||
const post = feedDummy.feed_data.find(post => post.boardId === Number(id)) | ||
|
||
if (!post) { | ||
return <div>게시물이 삭제되었습니다.</div> | ||
} | ||
|
||
const handleHashTagClick = (hashTag: string) => { | ||
console.log('Clicked hashtag:', hashTag) | ||
} | ||
|
||
const extractAndStyleHashtags = (content: string) => { | ||
const hashTagRegex = /#[^\s#]+/g | ||
const splitContent = content.split(hashTagRegex) | ||
const matchedHashTags = content.match(hashTagRegex) || [] | ||
|
||
const result: (string | JSX.Element)[] = [] | ||
|
||
splitContent.forEach((current, index) => { | ||
const replacedContent = current | ||
.replace(/\n/g, '<br />') | ||
.replace(/ /g, ' ') | ||
|
||
result.push( | ||
<span | ||
key={`content-${index}`} | ||
className="break-all" | ||
dangerouslySetInnerHTML={{ __html: replacedContent }} // HTML 문자열을 설정하여 줄바꿈 인식 | ||
/>, | ||
) | ||
|
||
if (index !== splitContent.length - 1) { | ||
const currentHashTag = matchedHashTags[index] | ||
const tagIndex = post.hashTag.indexOf(currentHashTag.slice(1)) | ||
|
||
result.push( | ||
<span | ||
key={`hashtag-${index}`} | ||
className={ | ||
tagIndex !== -1 ? 'text-blue-400 cursor-pointer break-all' : '' | ||
} | ||
onClick={() => handleHashTagClick(currentHashTag)}> | ||
{currentHashTag} | ||
</span>, | ||
) | ||
} | ||
}) | ||
|
||
return result | ||
} | ||
|
||
return ( | ||
<div className="font-NanumSquareRound flex"> | ||
<div className="mr-3 font-semibold">{post.nickName}</div> | ||
{/* 추후에 더보기 접기 버튼 넣어야 할 듯 */} | ||
<div>{extractAndStyleHashtags(post.content)}</div> | ||
</div> | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
weatherfit_refactoring/src/Components/Molecules/DetailImge.tsx
This file contains 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 Image from 'next/image' | ||
import feedDummy from '../../../public/dummy_data/feed.json' | ||
|
||
export default function DetailImage(boardId: BOARDID) { | ||
const id = boardId.boardId | ||
const post = feedDummy.feed_data.find(post => post.boardId === Number(id)) | ||
|
||
if (!post) { | ||
return <div>게시물이 삭제되었습니다.</div> | ||
} | ||
|
||
return ( | ||
<div className="flex justify-center"> | ||
{post.images.map((image, index) => ( | ||
<Image | ||
key={index} | ||
src={image} | ||
width={100} | ||
height={200} | ||
alt={`image-${index}`} | ||
className="rounded-xl m-2" | ||
/> | ||
))} | ||
</div> | ||
) | ||
} |
38 changes: 23 additions & 15 deletions
38
weatherfit_refactoring/src/Components/Molecules/DetailProfile.tsx
This file contains 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,22 +1,30 @@ | ||
import Image from 'next/image' | ||
import { useRouter } from 'next/navigation' | ||
import { FeedData } from '@/Store/FeedData' | ||
|
||
export default function DetailProfile() { | ||
// const router = useRouter() | ||
// const { id } = router | ||
'use client' | ||
|
||
// const { feedData } = FeedData() | ||
import Image from 'next/image' | ||
import feedDummy from '../../../public/dummy_data/feed.json' | ||
|
||
// const post = feedData.find(post => post.boardId === Number(id)) | ||
export default function DetailProfile(boardId: BOARDID) { | ||
const id = boardId.boardId | ||
const post = feedDummy.feed_data.find(post => post.boardId === Number(id)) | ||
|
||
// if (!post) { | ||
// return <div>게시물이 삭제되었습니다.</div> | ||
// } | ||
if (!post) { | ||
return <div>게시물이 삭제되었습니다.</div> | ||
} | ||
|
||
return ( | ||
<> | ||
{/* <Image src={post.userImage} width={20} height={20} alt="profile" /> */} | ||
</> | ||
<div className="flex items-center font-NanumSquareRound mt-5"> | ||
<Image | ||
src={post.userImage} | ||
width={50} | ||
height={50} | ||
alt="profile" | ||
className="rounded-full" | ||
/> | ||
<div className="flex-col ml-3 pb-1"> | ||
<p className="text-lg">{post.nickName}</p> | ||
<p className="text-xs text-gray-400">@user_one</p> | ||
{/* <p className="text-xs text-gray-400">여기 아이디 들어가면 되려나</p> */} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains 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 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 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
19 changes: 19 additions & 0 deletions
19
weatherfit_refactoring/src/Components/Organisms/DetailOrganism.tsx
This file contains 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,19 @@ | ||
import DetailContent from '@/Components/Molecules/DetailContent' | ||
import DetailImage from '@/Components/Molecules/DetailImge' | ||
import DetailProfile from '@/Components/Molecules/DetailProfile' | ||
import DetailCategory from '../Molecules/DetailCategory' | ||
import feedDummy from '../../../public/dummy_data/feed.json' | ||
|
||
export default function DetailOrganism({ boardId }: BOARDID) { | ||
return ( | ||
<div className="h-screen space-y-5"> | ||
<div className="mx-5 space-y-5"> | ||
<DetailProfile boardId={boardId} /> | ||
<DetailImage boardId={boardId} /> | ||
{/* 좋아요 & 댓글 */} | ||
<DetailContent boardId={boardId} /> | ||
</div> | ||
<DetailCategory boardId={boardId} /> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.