Skip to content

Commit

Permalink
✨ implement date
Browse files Browse the repository at this point in the history
  • Loading branch information
boompikachu committed Feb 6, 2021
1 parent 04ccff4 commit 5297e6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/components/AnnouncementDetailWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { makeStyles, Typography } from '@material-ui/core'
import { ReactNode } from 'react'
import { GenEdChip } from '@/components/GenEdChip'
import { GenEdType } from '@thinc-org/chula-courses'
import { format } from 'date-fns'
import { enGB } from 'date-fns/locale'

const useStyles = makeStyles((theme) => ({
wrapper: {
Expand All @@ -20,21 +22,22 @@ interface PropsType {
children: ReactNode
data: {
title: string
updatedTime: string
updatedTime: Date | null
gened: GenEdType
}
}

const AnnouncementDetailWrapper = ({ children, data: { title, updatedTime, gened } }: PropsType) => {
const classes = useStyles()

const date = updatedTime ? format(updatedTime, 'dd/MM/yyyy hh:mm a', { locale: enGB }) : null
return (
<div className={classes.wrapper}>
<Typography variant="h2">{title}</Typography>
<div className={classes.gened}>
<GenEdChip category={gened} />
</div>
<Typography variant="h6" className={classes.update}>
{updatedTime}
{date}
</Typography>
<article>{children}</article>
</div>
Expand Down
7 changes: 3 additions & 4 deletions src/pages/posts/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ interface Props {
}
}

const Post = ({ mdxSource, metaData }: Props) => {
const Post = ({ mdxSource, metaData: { title, updatedTime, gened } }: Props) => {
const content = hydrate(mdxSource)
const date = new Date(updatedTime.trim() + ' GMT+0700')

return (
<AnnouncementDetailWrapper
data={{ title: metaData.title, updatedTime: metaData.updatedTime, gened: metaData.gened }}
>
<AnnouncementDetailWrapper data={{ title: title, updatedTime: isNaN(date.getTime()) ? null : date, gened: gened }}>
{content}
</AnnouncementDetailWrapper>
)
Expand Down
2 changes: 1 addition & 1 deletion src/posts/test.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'เปิดวิชาเรียนใหม่ 0201170 Military Science เสริมสร้างวินัยทหารในตัวคุณ'
updatedTime: 'อัพเดท 22/07/64 17:00'
updatedTime: 'Feb 7 2020 14:02'
gened: 'SO'
---

Expand Down

0 comments on commit 5297e6f

Please sign in to comment.