-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guosw
committed
Apr 29, 2020
1 parent
5c80fea
commit 305ca89
Showing
4 changed files
with
135 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { useHistory } from 'react-router-dom' | ||
import { calcCommentsCount } from '@/utils' | ||
|
||
// components | ||
import { Divider } from 'antd' | ||
import SvgIcon from '@/components/SvgIcon' | ||
import ArticleTag from '@/components/ArticleTag' | ||
|
||
const ArticleList = props => { | ||
const history = useHistory() | ||
const { list } = props | ||
|
||
function jumpTo(id) { | ||
history.push(`/article/${id}`) | ||
} | ||
|
||
return ( | ||
<ul className='app-home-list'> | ||
{list.map(item => ( | ||
<li key={item.id} className='app-home-list-item'> | ||
<Divider orientation='left'> | ||
<span className='title' onClick={() => jumpTo(item.id)}> | ||
{item.title} | ||
</span> | ||
<span className='posted-time'>{item.createdAt.slice(0, 10)}</span> | ||
</Divider> | ||
|
||
<div | ||
onClick={() => jumpTo(item.id)} | ||
className='article-detail content' | ||
dangerouslySetInnerHTML={{ __html: item.content }} | ||
/> | ||
|
||
<div className='list-item-others'> | ||
<SvgIcon type='iconcomment' /> | ||
<span style={{ marginRight: 5 }}> {calcCommentsCount(item.comments)}</span> | ||
|
||
<SvgIcon type='iconview' style={{ marginRight: 5 }} /> | ||
<span>{item.viewCount}</span> | ||
|
||
<ArticleTag tagList={item.tags} categoryList={item.categories} /> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} | ||
|
||
export default ArticleList |
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,53 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { Link } from 'react-router-dom' | ||
|
||
import { useMediaQuery } from 'react-responsive' | ||
|
||
// components | ||
import { Icon, Divider, Empty, Drawer, Tag, Spin } from 'antd' | ||
|
||
const title = '快速导航' | ||
|
||
const List = props => { | ||
const { list, showTitle = true } = props | ||
return ( | ||
<ul className='preview'> | ||
{showTitle && <Divider>{title}</Divider>} | ||
{list.map(item => ( | ||
<li key={item.id}> | ||
<Link to={`/article/${item.id}`}>{item.title}</Link> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} | ||
|
||
/** | ||
* article quick link | ||
*/ | ||
const QuickLink = props => { | ||
const isGreaterThan1300 = useMediaQuery({ query: '(min-width: 1300px)' }) | ||
const { list } = props | ||
|
||
const [drawerVisible, setDrawerVisible] = useState(false) | ||
|
||
return isGreaterThan1300 ? <List list={list} /> : ( | ||
<> | ||
<div className='drawer-btn' onClick={e => setDrawerVisible(true)}> | ||
<Icon type='menu-o' className='nav-phone-icon' /> | ||
</div> | ||
<Drawer | ||
title={title} | ||
placement='right' | ||
closable={false} | ||
onClose={e => setDrawerVisible(false)} | ||
visible={drawerVisible} | ||
getContainer={() => document.querySelector('.app-home')}> | ||
<List list={list} showTitle={false} /> | ||
</Drawer> | ||
</> | ||
) | ||
} | ||
|
||
export default QuickLink | ||
|
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