11import { SolutionAdminInfo } from '../../../interface' ;
22import React , { useEffect , useRef , useState } from 'react' ;
3- import { ArctleViewer } from './articleViewer' ;
3+ import ArticleViewer from './articleViewer' ;
44import {
55 Button ,
66 Field ,
@@ -13,8 +13,7 @@ import {
1313 InfoLabel ,
1414 Popover ,
1515 PopoverTrigger ,
16- PopoverSurface ,
17- Label
16+ PopoverSurface
1817} from '@fluentui/react-components' ;
1918import { getArticle , submitArticleCheckResult } from '../../../fetch' ;
2019import { ErrorDiv , InputDateTime , UserName } from '../../utils' ;
@@ -23,6 +22,7 @@ import emptyQueueImage from 'assets/emptyQueue.webp';
2322import './style.css' ;
2423import { useNotUndefinedContext } from '../../../notUndefinedContext' ;
2524import { MyInfoContext } from '../../contexts' ;
25+ import { isCancel } from 'axios' ;
2626
2727export default function Article ( ) {
2828 const [ status , setStatus ] = useState < {
@@ -34,6 +34,7 @@ export default function Article() {
3434 const [ skipBefore , setSkipBefore ] = useState < number > ( 0 ) ;
3535 const [ otherRefuseCommit , setOtherRefuseCommit ] = useState ( '' ) ;
3636 const [ showAdminInfo , setShowAdminInfo ] = useState ( true ) ;
37+ const [ viewSourceCode , setViewSourceCode ] = useState ( false ) ;
3738 const myProfile = useNotUndefinedContext ( MyInfoContext ) ;
3839
3940 let refuseCommit = otherRefuseCommit ;
@@ -42,18 +43,19 @@ export default function Article() {
4243 refuseCommit += `。审核管理员:${ myProfile . name } ,对审核结果有疑问请私信交流` ;
4344
4445 useEffect ( ( ) => {
45- let ignore = false ;
46- getArticle ( skipBefore / 1000 )
46+ const cancel = new AbortController ( ) ;
47+ getArticle ( skipBefore / 1000 , { signal : cancel . signal } )
4748 . then ( v => {
48- if ( ! ignore )
49- setStatus ( { details : v } ) ,
50- v . article && setSkipBefore ( v . article . promoteResult . updateAt * 1000 ) ;
49+ console . log ( v ) ;
50+ setStatus ( { details : v } ) ,
51+ v . article && setSkipBefore ( v . article . promoteResult . updateAt * 1000 ) ;
5152 } )
5253 . catch ( e => {
53- if ( ! ignore )
54- console . error ( 'Error in feature Article' , e ) , setFetchError ( e ) ;
54+ console . log ( e ) ;
55+ if ( isCancel ( e ) ) return ;
56+ console . error ( 'Error in feature Article' , e ) , setFetchError ( e ) ;
5557 } ) ;
56- return ( ) => void ( ignore = true ) ;
58+ return ( ) => void cancel . abort ( ) ;
5759 } , [ ] ) ;
5860 function updateArticle ( ) {
5961 setStatus ( null ) ;
@@ -79,9 +81,20 @@ export default function Article() {
7981 < div className = "articleFeature" >
8082 { details ? (
8183 details . article ? (
82- < ArctleViewer className = "articleViewer" >
83- { details . article . content }
84- </ ArctleViewer >
84+ < >
85+ < pre
86+ className = "articleViewer"
87+ style = { { display : viewSourceCode ? 'block' : 'none' } }
88+ >
89+ < code > { details . article . content } </ code >
90+ </ pre >
91+ < div
92+ className = "articleViewer"
93+ style = { { display : viewSourceCode ? 'none' : 'block' } }
94+ >
95+ < ArticleViewer > { details . article . content } </ ArticleViewer >
96+ </ div >
97+ </ >
8598 ) : (
8699 < div className = { 'articleViewer articleQueueEmpty' } >
87100 < img src = { emptyQueueImage } width = { 300 } />
@@ -147,6 +160,11 @@ export default function Article() {
147160 ) : undefined }
148161 </ div >
149162 < div className = "articleOperator" >
163+ < Switch
164+ label = "显示 MarkDown 源代码"
165+ checked = { viewSourceCode }
166+ onChange = { ( e , x ) => setViewSourceCode ( x . checked ) }
167+ />
150168 < Field label = "其他原因:" >
151169 < Textarea
152170 className = "otherReasons"
@@ -157,7 +175,7 @@ export default function Article() {
157175 < Switch
158176 label = "显示审核员身份"
159177 checked = { showAdminInfo }
160- onChange = { ( e , x ) => setShowAdminInfo ( ! ! x . checked ) }
178+ onChange = { ( e , x ) => setShowAdminInfo ( x . checked ) }
161179 />
162180 < Field label = "预览:" >
163181 < Text as = "span" className = "viewOperatorCommit" >
0 commit comments