@@ -5,6 +5,7 @@ import { useRouter } from 'next/router';
55import { Trans , useTranslation } from 'next-i18next' ;
66import { serverSideTranslations } from 'next-i18next/serverSideTranslations' ;
77import { useEffect , useState } from 'react' ;
8+ import { FaGithub } from 'react-icons/fa' ;
89
910import { useLoginContext } from '@/hooks/useLoginContext' ;
1011
@@ -20,7 +21,7 @@ import { API_HOST, API_ROOT_PATH } from '@/utils/api';
2021
2122const EmbedPage : NextPage = ( ) => {
2223 const router = useRouter ( ) ;
23- const { rid } = router . query ;
24+ const { rid, full_name } = router . query ;
2425 const { t } = useTranslation ( 'claim' ) ;
2526
2627 const [ url , setUrl ] = useState ( '' ) ;
@@ -31,6 +32,7 @@ const EmbedPage: NextPage = () => {
3132 const [ isLoading , setIsLoading ] = useState ( false ) ; // 状态:是否在提交中
3233 const [ theme , setTheme ] = useState < string > ( 'neutral' ) ;
3334 const [ svgFile , setSVGFile ] = useState < string > ( '' ) ;
35+ const [ fullName , setFullName ] = useState ( '' ) ;
3436
3537 const generateBadge = ( ) => {
3638 if ( ! repoID ) return ;
@@ -45,11 +47,12 @@ const EmbedPage: NextPage = () => {
4547
4648 useEffect ( ( ) => {
4749 if ( rid ) setRepoID ( rid as string ) ;
48- } , [ rid ] ) ;
50+ if ( full_name ) setFullName ( full_name as string ) ;
51+ } , [ rid , full_name ] ) ;
4952
5053 useEffect ( ( ) => {
5154 if ( repoID ) generateBadge ( ) ;
52- } , [ repoID , userInfo ] ) ;
55+ } , [ userInfo , repoID ] ) ;
5356
5457 const themeClassName = ( themeName : string ) =>
5558 classNames ( 'px-2 py-1 text-xs' , {
@@ -76,6 +79,7 @@ const EmbedPage: NextPage = () => {
7679 return Message . error ( t ( 'submit.check_fail4' ) ) ;
7780 case 3 :
7881 setRepoID ( info_res . data . rid ) ;
82+ setFullName ( info_res . data . full_name ) ;
7983 break ;
8084 case 4 :
8185 return Message . error ( t ( 'submit.check_fail5' ) ) ;
@@ -86,7 +90,7 @@ const EmbedPage: NextPage = () => {
8690
8791 const handleCopy = ( ) => {
8892 if ( ! isLogin ) return login ( ) ;
89- const pageURL = `https://hellogithub.com/repository/${ repoID } ` ;
93+ const pageURL = `https://hellogithub.com/repository/${ fullName } ` ;
9094 const text =
9195 theme === 'small'
9296 ? `<a href="${ pageURL } " target="_blank"><img src="${ svgFile } " alt="Featured|HelloGitHub" /></a>`
@@ -174,49 +178,60 @@ const EmbedPage: NextPage = () => {
174178 { t ( 'generate.title' ) }
175179 </ h3 >
176180 { repoID ? (
177- < div className = 'flex flex-col rounded-lg bg-gray-100 dark:bg-gray-700' >
178- < div className = 'flex rounded-t-lg bg-gray-200 dark:bg-slate-900' >
179- < div className = 'p-2' >
180- < div className = 'flex cursor-pointer rounded-full bg-gray-50 dark:bg-gray-600' >
181- < div
182- className = { themeClassName ( 'neutral' ) }
183- onClick = { ( ) => handleTheme ( 'neutral' ) }
184- >
185- { t ( 'badge_theme_neutral' ) }
186- </ div >
187- < div
188- className = { themeClassName ( 'dark' ) }
189- onClick = { ( ) => handleTheme ( 'dark' ) }
190- >
191- { t ( 'badge_theme_dark' ) }
181+ < >
182+ < div className = 'flex flex-col rounded-lg bg-gray-100 dark:bg-gray-700' >
183+ < div className = 'flex rounded-t-lg bg-gray-200 dark:bg-slate-900' >
184+ < div className = 'p-2' >
185+ < div className = 'flex cursor-pointer rounded-full bg-gray-50 dark:bg-gray-600' >
186+ < div
187+ className = { themeClassName ( 'neutral' ) }
188+ onClick = { ( ) => handleTheme ( 'neutral' ) }
189+ >
190+ { t ( 'badge_theme_neutral' ) }
191+ </ div >
192+ < div
193+ className = { themeClassName ( 'dark' ) }
194+ onClick = { ( ) => handleTheme ( 'dark' ) }
195+ >
196+ { t ( 'badge_theme_dark' ) }
197+ </ div >
198+ < div
199+ className = { themeClassName ( 'small' ) }
200+ onClick = { ( ) => handleTheme ( 'small' ) }
201+ >
202+ { t ( 'badge_theme_small' ) }
203+ </ div >
192204 </ div >
193- < div
194- className = { themeClassName ( 'small' ) }
195- onClick = { ( ) => handleTheme ( 'small' ) }
205+ </ div >
206+ < div className = 'shrink grow' />
207+ < div className = 'p-1.5' >
208+ < Button
209+ onClick = { handleCopy }
210+ className = 'cursor-pointer rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 dark:bg-gray-600'
196211 >
197- { t ( 'badge_theme_small ' ) }
198- </ div >
212+ { t ( 'copy.text ' ) }
213+ </ Button >
199214 </ div >
200215 </ div >
201- < div className = 'shrink grow' />
202- < div className = 'p-1.5' >
203- < Button
204- onClick = { handleCopy }
205- className = 'cursor-pointer rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 dark:bg-gray-600'
206- >
207- { t ( 'copy.text' ) }
208- </ Button >
209- </ div >
210- </ div >
211216
212- < div className = 'my-8 flex justify-center' >
213- { svgFile ? (
214- < img className = 'w-max-full' src = { svgFile } />
215- ) : (
216- < Loading />
217- ) }
217+ < div className = 'my-8 flex justify-center' >
218+ { svgFile ? (
219+ < img className = 'w-max-full' src = { svgFile } />
220+ ) : (
221+ < Loading />
222+ ) }
223+ </ div >
218224 </ div >
219- </ div >
225+ { fullName && (
226+ < div
227+ className = 'mx-auto mt-1 mb-4 flex max-w-full select-text items-center justify-center gap-1 overflow-hidden truncate whitespace-nowrap text-center text-xs font-normal not-italic leading-tight text-gray-400 dark:text-gray-500 md:max-w-xl md:text-sm'
228+ title = { fullName }
229+ >
230+ < FaGithub className = 'inline-block text-base' />
231+ { fullName }
232+ </ div >
233+ ) }
234+ </ >
220235 ) : (
221236 < div className = 'flex items-center space-x-4 rounded-lg bg-gray-100 p-4 dark:bg-gray-700' >
222237 < input
0 commit comments