Skip to content

Commit d8f4257

Browse files
committed
copy updates
1 parent ca23983 commit d8f4257

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/pages/bsky.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ const Bksy = () => {
4343
throw new Error(`HTTP error! status: ${response.status}`)
4444
}
4545
const data: string[] = await response.json()
46-
setFollowing(data)
47-
setMyFollowingCopy(data)
46+
// This is done to prevent the same handles from being recommended in the same order.
47+
const dataRandomized = [...new Set(data.sort(() => Math.random() - 0.5))]
48+
setFollowing(dataRandomized)
49+
setMyFollowingCopy(dataRandomized)
4850
} catch (error) {
4951
console.error("Error fetching following:", error)
5052
return
5153
}
5254
}
5355

5456
if (Object.keys(following).length != 0) {
55-
setTimeout(() => handleRecommedationCounts(), 100)
57+
setTimeout(() => handleRecommedationCounts(), 250)
5658
}
5759

5860
const handleRecommedationCounts = async () => {
@@ -73,7 +75,7 @@ const Bksy = () => {
7375
// If the handle is already in the recommendations, increment the count.
7476
var recommendationsCopy = { ...recommendationCount }
7577
data.forEach((theirFollowingHandle) => {
76-
const validHandle = !["handle.invalid", ""].includes(
78+
const validHandle = ![myHandle, "handle.invalid", ""].includes(
7779
theirFollowingHandle
7880
)
7981
if (validHandle) {
@@ -96,7 +98,7 @@ const Bksy = () => {
9698
Object.keys(recommendationCount).length != 0 &&
9799
Object.keys(following).length == 0
98100
) {
99-
setTimeout(() => handleRecommedationCountSorted(), 100)
101+
setTimeout(() => handleRecommedationCountSorted(), 250)
100102
}
101103

102104
const handleRecommedationCountSorted = async () => {
@@ -116,7 +118,7 @@ const Bksy = () => {
116118
}
117119

118120
if (recommendationCountSorted.length != 0) {
119-
setTimeout(() => handleRecommendationDetails(), 100)
121+
setTimeout(() => handleRecommendationDetails(), 250)
120122
}
121123

122124
const handleRecommendationDetails = async () => {
@@ -140,6 +142,12 @@ const Bksy = () => {
140142
return
141143
}
142144

145+
const tooManyDetails = recommendationDetailsCopy.length > 250
146+
if (tooManyDetails) {
147+
setRecommendationCountSorted([])
148+
return
149+
}
150+
143151
const tooFewFollowers = followingCopy.length / 10 > myFollowers
144152
if (tooFewFollowers) {
145153
setRecommendationCountSorted([])
@@ -172,10 +180,10 @@ const Bksy = () => {
172180
}
173181

174182
if (
175-
recommendationDetails.length != 0 &&
183+
recommendationCountSorted.length == 0 &&
176184
recommendationDetailsByScore.length == 0
177185
) {
178-
setTimeout(() => handleSortDetailedByScore(), 100)
186+
setTimeout(() => handleSortDetailedByScore(), 250)
179187
}
180188

181189
const handleSortDetailedByScore = async () => {
@@ -193,7 +201,7 @@ const Bksy = () => {
193201
<div>
194202
<h2>Recommendations</h2>
195203
<div>
196-
<h3>Following To Recommendatins From: {following.length}</h3>
204+
<h3>Following To Get Recommendatins From: {following.length}</h3>
197205
<h3>
198206
Recommendations Counted: {Object.keys(recommendationCount).length}
199207
</h3>

0 commit comments

Comments
 (0)