import { Email, Link, Phone } from '@mui/icons-material'; import { ListItem, Section as SectionType } from 'schema'; import get from 'lodash/get'; import isArray from 'lodash/isArray'; import isEmpty from 'lodash/isEmpty'; import { useMemo } from 'react'; import Markdown from '@/components/shared/Markdown'; import { useAppSelector } from '@/store/hooks'; import { SectionProps } from '@/templates/sectionMap'; import DataDisplay from '@/templates/shared/DataDisplay'; import { formatDateString } from '@/utils/date'; import { addHttp, parseListItemPath } from '@/utils/template'; import BadgeDisplay from './BadgeDisplay'; import Heading from './Heading'; const Section: React.FC = ({ path, titlePath = 'title', subtitlePath = 'subtitle', headlinePath = 'headline', keywordsPath = 'keywords', }) => { const section: SectionType = useAppSelector((state) => get(state.resume.present, path, {} as SectionType)); const dateFormat: string = useAppSelector((state) => get(state.resume.present, 'metadata.date.format')); const primaryColor: string = useAppSelector((state) => get(state.resume.present, 'metadata.theme.primary')); const sectionId = useMemo(() => section.id || path.replace('sections.', ''), [path, section]); if (!section.visible) return null; if (isArray(section.items) && isEmpty(section.items)) return null; return (
{section.name}
{section.items.map((item: ListItem) => { const id = item.id, title = parseListItemPath(item, titlePath), subtitle = parseListItemPath(item, subtitlePath), headline = parseListItemPath(item, headlinePath), keywords: string[] = get(item, keywordsPath), url: string = get(item, 'url', ''), level: string = get(item, 'level', ''), phone: string = get(item, 'phone', ''), email: string = get(item, 'email', ''), summary: string = get(item, 'summary', ''), levelNum: number = get(item, 'levelNum', 0), date = formatDateString(get(item, 'date', ''), dateFormat); return (
{title && {title}} {subtitle && {subtitle}}
{date &&
({date})
} {headline && {headline}}
{(level || levelNum > 0) && (
{level && {level}} {levelNum > 0 && (
)}
)} {summary && {summary}} {url && ( } link={addHttp(url)}> {url} )} {keywords && } {(phone || email) && (
{phone && ( } link={`tel:${phone}`}> {phone} )} {email && ( } link={`mailto:${email}`}> {email} )}
)}
); })}
); }; export default Section;