-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 프로젝트 목록 기능 추가 (#56) #63
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { Key, ReactNode } from 'react'; | ||
|
|
||
| import clsx from 'clsx'; | ||
|
|
||
| export interface CardViewProps<T> { | ||
| items: readonly T[]; | ||
| getKey: (item: T, index: number) => Key; | ||
| renderCard: (item: T) => ReactNode; | ||
| className?: string; | ||
| itemClassName?: string; | ||
| empty?: ReactNode; | ||
| ariaLabal?: string; | ||
| } | ||
|
|
||
| export function CardView<T>({ | ||
| items, | ||
| getKey, | ||
| renderCard, | ||
| className, | ||
| itemClassName, | ||
| empty, | ||
| ariaLabal, | ||
| }: CardViewProps<T>) { | ||
| if (items.length === 0) { | ||
| return <div className="cardView__empty">{empty ?? 'No items'}</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={clsx('cardView', className)} role="list" aria-label={ariaLabal}> | ||
| {items.map((item, index) => ( | ||
| <div | ||
| key={getKey(item, index)} | ||
| className={clsx('cardView__item', itemClassName)} | ||
| role="listitem" | ||
| > | ||
| {renderCard(item)} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default CardView; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import type { Key, ReactNode } from 'react'; | ||
|
|
||
| import clsx from 'clsx'; | ||
|
|
||
| export interface ListViewProps<T> { | ||
| items: readonly T[]; | ||
| getKey: (item: T, index: number) => Key; | ||
|
|
||
| renderLeading?: (item: T) => ReactNode; | ||
| renderTrailing?: (item: T) => ReactNode; | ||
| renderInfo: (item: T) => ReactNode; | ||
|
|
||
| onItemClick?: (item: T) => void; | ||
| className?: string; | ||
| itemClassName?: string; | ||
| empty?: ReactNode; | ||
| ariaLabel?: string; | ||
| } | ||
|
|
||
| export function ListView<T>({ | ||
| items, | ||
| getKey, | ||
| renderLeading, | ||
| renderTrailing, | ||
| renderInfo, | ||
| onItemClick, | ||
| className, | ||
| itemClassName, | ||
| empty, | ||
| ariaLabel, | ||
| }: ListViewProps<T>) { | ||
| if (items.length === 0) { | ||
| return <div className="listView__empty">{empty ?? 'No items'}</div>; | ||
| } | ||
|
|
||
| const isClickable = Boolean(onItemClick); | ||
|
|
||
| return ( | ||
| <div className={clsx('listView', className)} role="list" aria-label={ariaLabel}> | ||
| {items.map((item, index) => { | ||
| const key = getKey(item, index); | ||
|
|
||
| return ( | ||
| <div | ||
| key={key} | ||
| className={clsx('listView__item', itemClassName, isClickable && 'is-clickable')} | ||
| role="listitem" | ||
| tabIndex={isClickable ? 0 : undefined} | ||
| onClick={isClickable ? () => onItemClick?.(item) : undefined} | ||
| onKeyDown={ | ||
| isClickable | ||
| ? (e) => { | ||
| if (e.key === 'Enter' || e.key === ' ') { | ||
| e.preventDefault(); | ||
| onItemClick?.(item); | ||
| } | ||
| } | ||
| : undefined | ||
| } | ||
| > | ||
| {renderLeading && <div className="listView__leading">{renderLeading(item)}</div>} | ||
|
|
||
| {/* <div className="listView__content"> | ||
| <div className="listView__title">{renderTitle(item)}</div> | ||
|
|
||
| {(renderUpdatedAt || renderMeta) && ( | ||
| <div className="listView__meta"> | ||
| {renderUpdatedAt && ( | ||
| <span className="listView__updated">{renderUpdatedAt(item)}</span> | ||
| )} | ||
| {renderMeta && <span className="listView__metaExtra">{renderMeta(item)}</span>} | ||
| </div> | ||
| )} | ||
|
|
||
| {renderStats && <div className="listView__stats">{renderStats(item)}</div>} | ||
| </div> */} | ||
YeoEunnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className="listView__content">{renderInfo(item)}</div> | ||
|
|
||
| {renderTrailing && ( | ||
| <div className="listView__trailing ml-auto shrink-0">{renderTrailing(item)}</div> | ||
| )} | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default ListView; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,32 @@ | ||
| import type { CardItems } from '@/types/project'; | ||
| import type { ViewMode } from '@/types/home'; | ||
| import type { ProjectItem } from '@/types/project'; | ||
|
|
||
| import { CardView, ListView } from '../common'; | ||
|
Check failure on line 4 in src/components/home/ProjectsSection.tsx
|
||
| import ProjectCard from '../projects/ProjectCard'; | ||
| import { ProjectCardSkeleton } from '../projects/ProjectCardSkeleton'; | ||
| import ProjectHeader from '../projects/ProjectHeader'; | ||
| import ProjectList from '../projects/ProjectList'; | ||
|
|
||
| const SKELETON_CARD_COUNT = 9; | ||
| const SKELETON_LIST_COUNT = 6; | ||
|
|
||
| type Props = { | ||
| isLoading: boolean; | ||
| query: string; | ||
| onChangeQuery: (value: string) => void; | ||
| projects: CardItems[]; | ||
| projects: ProjectItem[]; | ||
| viewMode: ViewMode; | ||
| onChangeViewMode: (viewMode: ViewMode) => void; | ||
| }; | ||
|
|
||
| export default function ProjectsSection({ isLoading, query, onChangeQuery, projects }: Props) { | ||
| export default function ProjectsSection({ | ||
| isLoading, | ||
| query, | ||
| onChangeQuery, | ||
| projects, | ||
| viewMode, | ||
| onChangeViewMode, | ||
| }: Props) { | ||
| const hasProjects = projects.length > 0; | ||
|
|
||
| if (!isLoading && !hasProjects) return null; | ||
|
|
@@ -26,16 +39,41 @@ | |
| </div> | ||
|
|
||
| {/* 검색 */} | ||
| <ProjectHeader value={query} onChange={onChangeQuery} /> | ||
| <ProjectHeader | ||
| value={query} | ||
| onChange={onChangeQuery} | ||
| viewMode={viewMode} | ||
| onChangeViewMode={onChangeViewMode} | ||
| /> | ||
|
|
||
| {/* 프레젠테이션 목록 */} | ||
| <div className="mt-6 grid grid-cols-2 gap-4 lg:grid-cols-3"> | ||
| {isLoading | ||
| ? Array.from({ length: SKELETON_CARD_COUNT }).map((_, index) => ( | ||
| {viewMode === 'card' ? ( | ||
| isLoading ? ( | ||
| <div className="mt-6 grid grid-cols-2 gap-4 lg:grid-cols-3"> | ||
| {Array.from({ length: SKELETON_CARD_COUNT }).map((_, index) => ( | ||
| <ProjectCardSkeleton key={index} /> | ||
| )) | ||
| : projects.map((project) => <ProjectCard key={project.id} {...project} />)} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) : ( | ||
| <CardView | ||
| items={projects} | ||
| getKey={(item) => item.id} | ||
| className="mt-6 grid grid-cols-2 gap-4 lg:grid-cols-3" | ||
| renderCard={(item) => <ProjectCard item={item} />} | ||
| /> | ||
| ) | ||
| ) : isLoading ? ( | ||
| <div className="mt-6 flex flex-col gap-3"> | ||
| {Array.from({ length: SKELETON_LIST_COUNT }).map((_, index) => ( | ||
| <div | ||
| key={index} | ||
| className="h-20 rounded-2xl border border-gray-200 bg-white p-4 animate-pulse" | ||
| /> | ||
| ))} | ||
| </div> | ||
|
Comment on lines
+65
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) : ( | ||
| <ProjectList items={projects} className="mt-6" /> | ||
| )} | ||
| {/* 프레젠테이션 목록 */} | ||
| </section> | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.