@@ -113,6 +113,38 @@ export default function QuizPage() {
113113 setResult ( null ) ;
114114 } ;
115115
116+ const shareText = ( name : string , compat : number ) =>
117+ `I matched with ${ name } (${ compat } % compatible) on AI Agent Love! Which AI agent are you?` ;
118+
119+ const shareUrl = "https://caishengold.github.io/ai-agent-love/quiz" ;
120+
121+ const handleShare = async ( platform : string ) => {
122+ if ( ! result ) return ;
123+ const text = shareText ( result . personality . name , Math . round ( result . score * 100 ) ) ;
124+ const encoded = encodeURIComponent ( text ) ;
125+ const encodedUrl = encodeURIComponent ( shareUrl ) ;
126+
127+ const urls : Record < string , string > = {
128+ twitter : `https://twitter.com/intent/tweet?text=${ encoded } &url=${ encodedUrl } ` ,
129+ reddit : `https://www.reddit.com/submit?title=${ encoded } &url=${ encodedUrl } ` ,
130+ linkedin : `https://www.linkedin.com/sharing/share-offsite/?url=${ encodedUrl } ` ,
131+ copy : "" ,
132+ } ;
133+
134+ if ( platform === "copy" ) {
135+ try {
136+ await navigator . clipboard . writeText ( `${ text } \n${ shareUrl } ` ) ;
137+ setCopied ( true ) ;
138+ setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
139+ } catch { }
140+ return ;
141+ }
142+
143+ window . open ( urls [ platform ] , "_blank" , "noopener,noreferrer" ) ;
144+ } ;
145+
146+ const [ copied , setCopied ] = useState ( false ) ;
147+
116148 if ( result ) {
117149 const { personality, score } = result ;
118150 const compatibility = Math . round ( score * 100 ) ;
@@ -136,9 +168,22 @@ export default function QuizPage() {
136168 < span className = "text-white/60 text-sm" > { personality . interests . join ( ", " ) } </ span >
137169 </ div >
138170 </ div >
171+
172+ < div className = "mt-8 space-y-4" >
173+ < p className = "text-white/40 text-sm uppercase tracking-widest" > Share your result</ p >
174+ < div className = "flex justify-center gap-3" >
175+ < button onClick = { ( ) => handleShare ( "twitter" ) } className = "px-4 py-2 rounded-xl bg-sky-500/20 border border-sky-500/30 text-sky-300 hover:bg-sky-500/30 transition-colors text-sm" > Twitter / X</ button >
176+ < button onClick = { ( ) => handleShare ( "reddit" ) } className = "px-4 py-2 rounded-xl bg-orange-500/20 border border-orange-500/30 text-orange-300 hover:bg-orange-500/30 transition-colors text-sm" > Reddit</ button >
177+ < button onClick = { ( ) => handleShare ( "linkedin" ) } className = "px-4 py-2 rounded-xl bg-blue-500/20 border border-blue-500/30 text-blue-300 hover:bg-blue-500/30 transition-colors text-sm" > LinkedIn</ button >
178+ < button onClick = { ( ) => handleShare ( "copy" ) } className = "px-4 py-2 rounded-xl bg-white/10 border border-white/20 text-white/70 hover:bg-white/20 transition-colors text-sm" >
179+ { copied ? "Copied!" : "Copy link" }
180+ </ button >
181+ </ div >
182+ </ div >
183+
139184 < button
140185 onClick = { handleRestart }
141- className = "mt-8 px-6 py-3 rounded-xl bg-white/10 border border-white/20 text-white hover:bg-white/20 transition-colors"
186+ className = "mt-6 px-6 py-3 rounded-xl bg-white/10 border border-white/20 text-white hover:bg-white/20 transition-colors"
142187 >
143188 Retake quiz
144189 </ button >
0 commit comments