11import type { NextPage } from 'next'
2+ import { useState , useEffect } from 'react'
23import Link from 'next/link'
34import PostType from '../../types/post'
45import { getDateFromDateByHour } from '../../lib/helper'
56import ReadMoreAndLess from '../ReadMoreAndLess'
67
78type Props = {
8- post : PostType
9+ post : PostType | undefined
910 readMore ?: boolean
1011}
1112
1213const PostView : NextPage < Props > = ( { post, readMore} ) => {
14+ const [ isReadMoreShown , setReadMoreShown ] = useState ( false )
15+ const toggleBtn = ( ) => {
16+ setReadMoreShown ( prevState => ! prevState )
17+ }
18+ if ( post == undefined ) {
19+ return ( < > </ > )
20+ } else {
1321 return (
1422 < div className = "relative px-2 lg:px-8" >
1523 < div className = "mx-auto max-w-5xl pt-8 pb-8 sm:pt-18 sm:pb-18" >
1624 < div className = "md:px-16 md:py-4 bg-white border border-gray-200 rounded-lg shadow-lg dark:bg-gray-800 dark:border-gray-700" >
17- { post . image_url &&
18- < Link href = { "/chia-se/thu-muc-vu/" + post . slug } legacyBehavior >
25+ { post . post_meta . image_url ?
26+ < Link href = { "/chia-se/thu-muc-vu/" + post . post_meta . slug } legacyBehavior >
1927 < a >
20- < img className = "rounded-t-lg" src = { post . image_url } alt = { post . title } />
28+ < img className = "rounded-t-lg" src = { post . post_meta . image_url } alt = { post . post_meta . title } />
2129 </ a >
22- </ Link >
30+ </ Link > : ""
2331 }
2432 < div className = "p-4" >
2533 < h1 className = "text-3xl font-serif font-bold tracking-tight sm:text-center sm:text-4xl" >
26- { post . title }
34+ { post . post_meta . title }
2735 </ h1 >
2836
2937 < div className = "mt-2 flex items-center space-x-4" >
3038 < div className = "flex-shrink-0" >
31- < img className = "w-8 h-8 rounded-full" src = { post . author . image } alt = { post . title } />
39+ < img className = "w-8 h-8 rounded-full" src = { post . post_meta . author . image } alt = { post . post_meta . title } />
3240 </ div >
3341 < div className = "flex-1 min-w-0" >
3442 < p className = "text-sm font-medium text-gray-900 truncate dark:text-white" >
35- { post . author . saint_name } { post . author . full_name }
43+ { post . post_meta . author . saint_name } { post . post_meta . author . full_name }
3644 </ p >
3745 < p className = "text-sm text-gray-500 truncate dark:text-gray-400" >
38- { post . author . email }
46+ { post . post_meta . author . email }
3947 </ p >
4048 </ div >
4149 </ div >
42- < span className = "text-sm mt-4 text-gray-500 dark:text-gray-400" > { getDateFromDateByHour ( post . created_on , 0 ) } </ span >
43- < ReadMoreAndLess content = { '<div id="post_content_sub" className="space-y-2">' + post . content + '</div>' } >
44- </ ReadMoreAndLess >
50+ < span className = "text-sm mt-4 text-gray-500 dark:text-gray-400" > { getDateFromDateByHour ( post . post_meta . created_on , 0 ) } </ span >
51+ { post . post_meta . audio_link &&
52+ < div className = "mt-8 justify-center items-start h-full max-h-full w-full max-w-full border-gray-200 dark:border-gray-700" >
53+ < iframe className = "w-full h-full" src = { post . post_meta . audio_link } title = "Vietcatholicjp" > </ iframe >
54+ </ div >
55+ }
56+ < div className = "my-2" >
57+ {
58+ isReadMoreShown ?
59+ post . content . map ( ( chapter , idx ) => (
60+ < div key = { idx } >
61+ < h2 className = "relative group my-4 text-lg md:text-xl font-bold" > { chapter . chapter_title }
62+ < span id = { chapter . slug } className = "absolute -top-[140px]" > </ span >
63+ < a className = "ml-2 text-blue-700 opacity-0 transition-opacity dark:text-blue-500 group-hover:opacity-100" href = "#leading-paragraph" aria-label = "Link to this section: Leading paragraph" >
64+ #
65+ </ a >
66+ </ h2 >
67+ < div className = "space-y-2" dangerouslySetInnerHTML = { { __html : chapter . content ?chapter . content :"" } } />
68+ </ div >
69+ ) ) :< div >
70+ < h2 className = "relative group my-4 text-lg md:text-xl font-bold" > { post . content [ 0 ] . chapter_title }
71+ < span id = { post . content [ 0 ] . slug } className = "absolute -top-[140px]" > </ span >
72+ < a className = "ml-2 text-blue-700 opacity-0 transition-opacity dark:text-blue-500 group-hover:opacity-100" href = "#leading-paragraph" aria-label = "Link to this section: Leading paragraph" >
73+ #
74+ </ a >
75+ </ h2 >
76+ < div className = "space-y-2" dangerouslySetInnerHTML = { { __html : post . content [ 0 ] . content ?post . content [ 0 ] . content :"" } } />
77+ </ div >
78+ }
79+ </ div >
80+ < button id = "continue"
81+ type = "button"
82+ className = "inline-flex justify-center rounded-md border border-transparent bg-blue-100 px-4 py-2 text-sm font-medium text-blue-900 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
83+ onClick = { toggleBtn }
84+ >
85+ { isReadMoreShown ?'Thu nhỏ' :'Đọc tiếp' }
86+ </ button >
4587 </ div >
4688 </ div >
4789 </ div >
4890 </ div >
4991 )
92+ }
5093}
5194
5295export default PostView
0 commit comments