File tree Expand file tree Collapse file tree 12 files changed +108
-32
lines changed
studio/components/layouts/SignInLayout Expand file tree Collapse file tree 12 files changed +108
-32
lines changed Original file line number Diff line number Diff line change @@ -86,9 +86,24 @@ const SignInLayout = ({
8686 } | null > ( null )
8787
8888 useEffect ( ( ) => {
89- const randomQuote = tweets [ Math . floor ( Math . random ( ) * tweets . length ) ]
90-
91- setQuote ( randomQuote )
89+ // Weighted random selection
90+ // Calculate total weight (default weight is fallbackWeight for tweets without weight specified)
91+ const fallbackWeight = 1
92+ const totalWeight = tweets . reduce ( ( sum , tweet ) => sum + ( tweet . weight ?? fallbackWeight ) , 0 )
93+
94+ // Generate random number between 0 and totalWeight
95+ const random = Math . random ( ) * totalWeight
96+
97+ // Find the selected tweet based on cumulative weights
98+ let accumulatedWeight = 0
99+ for ( const tweet of tweets ) {
100+ const weight = tweet . weight ?? fallbackWeight
101+ accumulatedWeight += weight
102+ if ( random <= accumulatedWeight ) {
103+ setQuote ( tweet )
104+ break
105+ }
106+ }
92107 } , [ ] )
93108
94109 return (
Original file line number Diff line number Diff line change 1+ import { range } from 'lib/helpers'
12import Link from 'next/link'
23import { useRouter } from 'next/router'
34import { cn } from 'ui'
45import { TweetCard } from 'ui-patterns/TweetCard'
5- import { range } from 'lib/helpers'
66
7- import tweets from 'shared-data/tweets'
87import { useBreakpoint } from 'common'
98import React from 'react'
9+ import { topTweets } from 'shared-data/tweets'
1010
1111interface Props {
1212 className ?: string
1313}
1414
15+ const tweetsData = topTweets
16+
1517const TwitterSocialProof : React . FC < Props > = ( { className } ) => {
1618 const { basePath } = useRouter ( )
1719 const isSm = useBreakpoint ( )
1820 const isMd = useBreakpoint ( 1024 )
19- const tweetsData = tweets . slice ( 0 , 18 )
2021
2122 return (
2223 < >
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { Button } from 'ui'
55import ProductModules from '../ProductModules'
66
77import MainProducts from 'data/MainProducts'
8- import tweets from 'shared-data/tweets'
8+ import { topTweets } from 'shared-data/tweets'
99import { IconDiscord } from 'ui'
1010
1111export default ( ) => {
@@ -188,7 +188,7 @@ export default () => {
188188 </ Link >
189189 </ Button >
190190 ) ,
191- tweets : tweets . slice ( 0 , 18 ) ,
191+ tweets : topTweets ,
192192 } ,
193193 }
194194}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import {
2121
2222import { useBreakpoint } from 'common'
2323import { useSendTelemetryEvent } from 'lib/telemetry'
24- import { tweets } from 'shared-data'
24+ import { topTweets } from 'shared-data'
2525import { PRODUCT_SHORTNAMES } from 'shared-data/products'
2626
2727const AuthVisual = dynamic ( ( ) => import ( 'components/Products/AuthVisual' ) )
@@ -495,7 +495,7 @@ const data: () => {
495495 </ Link >
496496 </ Button >
497497 ) ,
498- tweets : tweets . slice ( 0 , 18 ) ,
498+ tweets : topTweets ,
499499 } ,
500500 platformStarterSection : {
501501 id : 'platform-starter' ,
You can’t perform that action at this time.
0 commit comments