11import styles from './index.module.less' ;
22import { useFetch } from '../../hook/useFetch' ;
3+ import { useState } from 'react' ;
4+ import { useMemo } from 'react' ;
35
46type ContributorsProps = {
57 path ?: string ;
68} ;
79
810export default function Contributors ( props : ContributorsProps ) {
911 const { path } = props ;
10- if ( ! path ) return null ;
11- let editPath = path ;
12- if ( ! / ^ ( h t t p s ? : \/ \/ ) / . test ( editPath ) ) {
13- editPath = `https://github.com/uiwjs/react-native-uiw/edit/master/${ path . replace ( / ^ \/ / , '' ) } ` ;
14- }
12+ const [ editPath , setEditPath ] = useState < string > ( ) ;
13+ useMemo ( ( ) => {
14+ if ( ! path ) return null ;
15+ if ( ! / ^ ( h t t p s ? : \/ \/ ) / . test ( path ) ) {
16+ setEditPath ( `https://github.com/uiwjs/react-native-uiw/edit/master/${ path . replace ( / ^ \/ / , '' ) } ` ) ;
17+ }
18+ } , [ path ] ) ;
1519 return (
1620 < div className = { styles . warpper } >
17- < a className = { styles . edit } href = { editPath } target = "__blank" >
18- < svg viewBox = "0 0 1024 1024" width = "14" height = "14" fill = "#757575" >
19- < path d = "M837.818182 0H186.181818C134.981818 0 93.090909 41.890909 93.090909 93.090909v837.818182c0 51.2 41.890909 93.090909 93.090909 93.090909h651.636364c51.2 0 93.090909-41.890909 93.090909-93.090909V93.090909c0-51.2-41.890909-93.090909-93.090909-93.090909z m46.545454 912.290909c0 37.236364-27.927273 65.163636-65.163636 65.163636H204.8c-37.236364 0-65.163636-27.927273-65.163636-65.163636V111.709091C139.636364 74.472727 167.563636 46.545455 204.8 46.545455h614.4c37.236364 0 65.163636 27.927273 65.163636 65.163636v800.581818z" />
20- < path d = "M256 139.636364h418.909091c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-418.909091c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727zM256 279.272727h279.272727c13.963636 0 23.272727 9.309091 23.272728 23.272728s-9.309091 23.272727-23.272728 23.272727h-279.272727c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272728zM256 418.909091h139.636364c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-139.636364c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
21- < path d = "M256 581.818182m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" />
22- < path d = "M721.454545 558.545455h46.545455c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-46.545455c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
23- < path d = "M404.945455 768l-102.4-97.745455L781.963636 190.836364c27.927273-27.927273 69.818182-27.927273 97.745455 0s27.927273 69.818182 0 97.745454" />
24- < path d = "M339.781818 833.163636l-116.363636 18.618182 18.618182-116.363636 32.581818-32.581818L372.363636 800.581818" />
25- </ svg >
26- 在 GitHub 上编辑此页
27- </ a >
21+ { editPath && (
22+ < a className = { styles . edit } href = { editPath } target = "__blank" >
23+ < svg viewBox = "0 0 1024 1024" width = "14" height = "14" fill = "#757575" >
24+ < path d = "M837.818182 0H186.181818C134.981818 0 93.090909 41.890909 93.090909 93.090909v837.818182c0 51.2 41.890909 93.090909 93.090909 93.090909h651.636364c51.2 0 93.090909-41.890909 93.090909-93.090909V93.090909c0-51.2-41.890909-93.090909-93.090909-93.090909z m46.545454 912.290909c0 37.236364-27.927273 65.163636-65.163636 65.163636H204.8c-37.236364 0-65.163636-27.927273-65.163636-65.163636V111.709091C139.636364 74.472727 167.563636 46.545455 204.8 46.545455h614.4c37.236364 0 65.163636 27.927273 65.163636 65.163636v800.581818z" />
25+ < path d = "M256 139.636364h418.909091c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-418.909091c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727zM256 279.272727h279.272727c13.963636 0 23.272727 9.309091 23.272728 23.272728s-9.309091 23.272727-23.272728 23.272727h-279.272727c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272728zM256 418.909091h139.636364c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-139.636364c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
26+ < path d = "M256 581.818182m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" />
27+ < path d = "M721.454545 558.545455h46.545455c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-46.545455c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
28+ < path d = "M404.945455 768l-102.4-97.745455L781.963636 190.836364c27.927273-27.927273 69.818182-27.927273 97.745455 0s27.927273 69.818182 0 97.745454" />
29+ < path d = "M339.781818 833.163636l-116.363636 18.618182 18.618182-116.363636 32.581818-32.581818L372.363636 800.581818" />
30+ </ svg >
31+ 在 GitHub 上编辑此页
32+ </ a >
33+ ) }
2834 < AvatarList path = { path } />
2935 </ div >
3036 ) ;
@@ -35,25 +41,25 @@ type Response = Array<{
3541 url : string ;
3642} > ;
3743
38- function AvatarList ( props : { path : string } ) {
39- const { path } = props ;
44+ function AvatarList ( props : { path ? : string } ) {
45+ const { path = '' } = props ;
4046 const fetchurl = `https://proapi.azurewebsites.net/doc/getAvatarList?filename=${ path . replace (
4147 / ^ \/ / ,
4248 '' ,
4349 ) } &owner=uiwjs&repo=react-native-uiw`;
4450 const res = useFetch < Response > ( fetchurl ) ;
45- if ( ! res . response ) {
46- return < span className = { styles . avatar } /> ;
51+ if ( res . response ) {
52+ return (
53+ < span className = { styles . avatar } >
54+ { res . response . map ( ( item , idx ) => {
55+ return (
56+ < a href = { `https://github.com/${ item . username } ` } key = { idx } target = "__blank" >
57+ < img src = { item . url } alt = { item . username } />
58+ </ a >
59+ ) ;
60+ } ) }
61+ </ span >
62+ ) ;
4763 }
48- return (
49- < span className = { styles . avatar } >
50- { res . response . map ( ( item , idx ) => {
51- return (
52- < a href = { `https://github.com/${ item . username } ` } key = { idx } target = "__blank" >
53- < img src = { item . url } alt = { item . username } />
54- </ a >
55- ) ;
56- } ) }
57- </ span >
58- ) ;
64+ return < span className = { styles . avatar } /> ;
5965}
0 commit comments