Skip to content

Commit 1fabe2f

Browse files
authored
chore: weighted tweets (supabase#39917)
* add new tweets and remove old * randomise on sign in * prefer higher weights * single source of truth * additional tweet * clean up extraneous content
1 parent d10001b commit 1fabe2f

File tree

12 files changed

+108
-32
lines changed

12 files changed

+108
-32
lines changed

apps/studio/components/layouts/SignInLayout/SignInLayout.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff 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 (

apps/www/components/Sections/TwitterSocialProof.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
import { range } from 'lib/helpers'
12
import Link from 'next/link'
23
import { useRouter } from 'next/router'
34
import { cn } from 'ui'
45
import { TweetCard } from 'ui-patterns/TweetCard'
5-
import { range } from 'lib/helpers'
66

7-
import tweets from 'shared-data/tweets'
87
import { useBreakpoint } from 'common'
98
import React from 'react'
9+
import { topTweets } from 'shared-data/tweets'
1010

1111
interface Props {
1212
className?: string
1313
}
1414

15+
const tweetsData = topTweets
16+
1517
const 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
<>

apps/www/data/home/content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button } from 'ui'
55
import ProductModules from '../ProductModules'
66

77
import MainProducts from 'data/MainProducts'
8-
import tweets from 'shared-data/tweets'
8+
import { topTweets } from 'shared-data/tweets'
99
import { IconDiscord } from 'ui'
1010

1111
export default () => {
@@ -188,7 +188,7 @@ export default () => {
188188
</Link>
189189
</Button>
190190
),
191-
tweets: tweets.slice(0, 18),
191+
tweets: topTweets,
192192
},
193193
}
194194
}

apps/www/data/solutions/beginners.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121

2222
import { useBreakpoint } from 'common'
2323
import { useSendTelemetryEvent } from 'lib/telemetry'
24-
import { tweets } from 'shared-data'
24+
import { topTweets } from 'shared-data'
2525
import { PRODUCT_SHORTNAMES } from 'shared-data/products'
2626

2727
const 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',
32.6 KB
Loading
-18.9 KB
Binary file not shown.
21.9 KB
Loading
23.4 KB
Loading
32.5 KB
Loading
-14 KB
Binary file not shown.

0 commit comments

Comments
 (0)