@@ -20,6 +20,7 @@ import type {
2020 Language ,
2121 Timezone ,
2222} from './types' ;
23+ import { useDebounce } from '@/hooks/useDebounce' ;
2324import { getExportSnippet , buildQueryParams } from './utils' ;
2425
2526// ─── Main Page ────────────────────────────────────────────────────────────────
@@ -54,6 +55,7 @@ function CustomizePageInner(): ReactElement {
5455 const [ svgState , setSvgState ] = useState < 'idle' | 'loading' | 'loaded' | 'error' > ( 'idle' ) ;
5556 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
5657 const trimmedUsername = username . trim ( ) ;
58+ const debouncedUsername = useDebounce ( trimmedUsername , 400 ) ;
5759 const hasUsername = trimmedUsername . length > 0 ;
5860 const isRandomTheme = theme === 'random' ;
5961
@@ -146,7 +148,32 @@ function CustomizePageInner(): ReactElement {
146148 language,
147149 timezone,
148150 } ) ;
149- const previewSrc = `/api/streak?${ queryString } ` ;
151+
152+ const previewQueryString = buildQueryParams ( {
153+ username : debouncedUsername ,
154+ theme,
155+ bgHex,
156+ accentHex,
157+ textHex,
158+ scale,
159+ speed,
160+ font,
161+ year,
162+ radius,
163+ size,
164+ hideTitle,
165+ hideBackground,
166+ hideStats,
167+ viewMode,
168+ deltaFormat,
169+ badgeWidth,
170+ badgeHeight,
171+ grace,
172+ language,
173+ timezone,
174+ } ) ;
175+
176+ const previewSrc = `/api/streak?${ previewQueryString } ` ;
150177
151178 // On change sync state to URL
152179 useEffect ( ( ) => {
@@ -169,6 +196,13 @@ function CustomizePageInner(): ReactElement {
169196 return ;
170197 }
171198
199+ if ( ! validateGitHubUsername ( debouncedUsername ) ) {
200+ setSvgContent ( '' ) ;
201+ setSvgState ( 'error' ) ;
202+ setErrorMessage ( "That doesn't look like a valid GitHub username" ) ;
203+ return ;
204+ }
205+
172206 setSvgState ( 'loading' ) ;
173207 const controller = new AbortController ( ) ;
174208
@@ -235,7 +269,7 @@ function CustomizePageInner(): ReactElement {
235269 } ) ;
236270
237271 return ( ) => controller . abort ( ) ;
238- } , [ previewSrc , hasUsername , trimmedUsername ] ) ;
272+ } , [ previewSrc , hasUsername , debouncedUsername ] ) ;
239273
240274 const exportSnippet = getExportSnippet ( exportFormat , queryString ) ;
241275
0 commit comments