11import React , { useEffect } from 'react' ;
22import dayjs from 'dayjs' ;
33
4- import { useHistory } from 'umi' ;
4+ import { useHistory , useAccess } from 'umi' ;
55import { Avatar , Tag , Space , Divider , Button } from 'antd' ;
66import { useRequest , useReactive } from 'ahooks' ;
77import { ProListMetas } from '@ant-design/pro-list' ;
88import ProList from '@ant-design/pro-list' ;
9- import { ReloadOutlined } from '@ant-design/icons' ;
9+ import { ReloadOutlined , EditOutlined } from '@ant-design/icons' ;
1010
1111import { TABS_MAP } from '@/constants' ;
1212import type { TabType } from '@/constants' ;
@@ -17,6 +17,7 @@ import * as styles from './index.less';
1717interface Props { }
1818
1919const TopicList : React . FC < Props > = ( props ) => {
20+ const access = useAccess ( ) ;
2021 const history = useHistory ( ) ;
2122
2223 const state = useReactive ( {
@@ -76,18 +77,12 @@ const TopicList: React.FC<Props> = (props) => {
7677 const offsetHeight = document . body . offsetHeight ;
7778 const pageYOffset = window . pageYOffset ;
7879
79- console . debug ( '===pageYOffset' , pageYOffset ) ;
80- console . debug ( '===offsetHeight' , offsetHeight ) ;
81- console . debug ( '===scrollHeight' , scrollHeight ) ;
82-
83- // if(pageYOffset) {
84- // console.log('===onReachStart', hasNext, loading);
85- // onReachStart();
86- // return;
87- // }
80+ // console.debug('===pageYOffset', pageYOffset);
81+ // console.debug('===offsetHeight', offsetHeight);
82+ // console.debug('===scrollHeight', scrollHeight);
8883
8984 if ( pageYOffset + offsetHeight === scrollHeight ) {
90- console . log ( '===onReachEnd' , hasNext , loading ) ;
85+ // console.log('===onReachEnd', hasNext, loading);
9186 onReachEnd ( ) ;
9287 }
9388 } ;
@@ -166,6 +161,26 @@ const TopicList: React.FC<Props> = (props) => {
166161 refresh ( ) ;
167162 } ;
168163
164+ const onCreate = ( ) => {
165+ history . push ( '/topic/create' ) ;
166+ } ;
167+
168+ const actions = [
169+ < Button key = "refresh" type = "default" size = "small" onClick = { onRefresh } >
170+ < ReloadOutlined />
171+ 刷新
172+ </ Button > ,
173+ ] ;
174+
175+ if ( access . canPostTopic ) {
176+ actions . push (
177+ < Button key = "create" type = "primary" size = "small" onClick = { onCreate } >
178+ < EditOutlined />
179+ 新建
180+ </ Button > ,
181+ ) ;
182+ }
183+
169184 return (
170185 < div >
171186 < ProList
@@ -187,12 +202,7 @@ const TopicList: React.FC<Props> = (props) => {
187202 } ) ,
188203 onChange : onChangeTabKey ,
189204 } ,
190- actions : [
191- < Button key = "refresh" type = "primary" onClick = { onRefresh } >
192- < ReloadOutlined />
193- 刷新
194- </ Button > ,
195- ] ,
205+ actions,
196206 } }
197207 onRow = { ( record ) => {
198208 return {
@@ -202,17 +212,6 @@ const TopicList: React.FC<Props> = (props) => {
202212 } ,
203213 } ;
204214 } }
205- // request={async (params) => {
206- // state.page = params.current || page;
207- // state.limit = params.pageSize || limit;
208- // return Promise.resolve({});
209- // }}
210- // pagination={{
211- // total: 100,
212- // current: page,
213- // pageSize: limit,
214- // responsive: true,
215- // }}
216215 />
217216 < Divider type = "horizontal" />
218217 { renderFooter ( ) }
0 commit comments