@@ -29,6 +29,8 @@ const Bsky = () => {
2929 )
3030 const [ showDetailsByScore , setShowDetailsByScore ] = useState < boolean > ( false )
3131
32+ const requestFrequency = 100
33+
3234 // Get the "handle" query parameter.
3335 // This should eventually be replaced with a user input field.
3436 // "I / Me" from this point are the perspective of the user, eg. the handle.
@@ -47,8 +49,8 @@ const Bsky = () => {
4749 const data : string [ ] = await response . json ( )
4850 // This is done to prevent the same handles from being recommended in the same order.
4951 const dataRandomized = [ ...new Set ( data . sort ( ( ) => Math . random ( ) - 0.5 ) ) ]
50- setFollowing ( dataRandomized )
51- setMyFollowingCopy ( dataRandomized )
52+ setFollowing ( ( ) => dataRandomized )
53+ setMyFollowingCopy ( ( ) => dataRandomized )
5254 } catch ( error ) {
5355 showError ( setError , error )
5456 }
@@ -57,7 +59,10 @@ const Bsky = () => {
5759 // When you have my followers ...
5860 useEffect ( ( ) => {
5961 if ( Object . keys ( following ) . length !== 0 ) {
60- const timer = setTimeout ( ( ) => handleRecommedationCounts ( ) , 250 )
62+ const timer = setTimeout (
63+ ( ) => handleRecommedationCounts ( ) ,
64+ requestFrequency
65+ )
6166 return ( ) => clearTimeout ( timer )
6267 }
6368 } , [ following ] )
@@ -99,8 +104,8 @@ const Bsky = () => {
99104 reccsCopy [ theirFollowingHandle ] = reccCount
100105 }
101106 } )
102- setReccCount ( reccsCopy )
103- setFollowing ( myFollowingCopy )
107+ setReccCount ( ( ) => reccsCopy )
108+ setFollowing ( ( ) => myFollowingCopy )
104109 } catch ( error ) {
105110 showError ( setError , error )
106111 }
@@ -112,7 +117,10 @@ const Bsky = () => {
112117 Object . keys ( reccCount ) . length != 0 &&
113118 Object . keys ( following ) . length == 0
114119 ) {
115- const timer = setTimeout ( ( ) => handleRecommedationCountSorted ( ) , 250 )
120+ const timer = setTimeout (
121+ ( ) => handleRecommedationCountSorted ( ) ,
122+ requestFrequency
123+ )
116124 return ( ) => clearTimeout ( timer )
117125 }
118126 } , [ following , reccCount ] )
@@ -125,7 +133,7 @@ const Bsky = () => {
125133 // Sort by `(a, b) => b[1] - a[1]` (eg. highest first)
126134 // produces a list dominated by popular people.
127135 //
128- // Sort by `() => Math.random() - 0.5) ` (eg. random)
136+ // Sort by `() => Math.random() - 0.5` (eg. random)
129137 // produces most of less the same output for the "most popular" list,
130138 // but produces dramatically different results for the "percent following" list.
131139 //
@@ -137,8 +145,9 @@ const Bsky = () => {
137145 }
138146 const reccCountSortedCopy : [ string , number ] [ ] = Object . entries (
139147 reccCountCopy
140- ) . sort ( ( ) => Math . random ( ) - 0.5 )
141- setReccCountSorted ( reccCountSortedCopy )
148+ ) . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
149+ console . log ( "reccCountSortedCopy" , reccCountSortedCopy )
150+ setReccCountSorted ( ( ) => reccCountSortedCopy )
142151 setReccCount ( { } )
143152 } catch ( error ) {
144153 showError ( setError , error )
@@ -148,7 +157,7 @@ const Bsky = () => {
148157 // When you have the sorted reccomendation counts ...
149158 useEffect ( ( ) => {
150159 if ( reccCountSorted . length != 0 ) {
151- const timer = setTimeout ( ( ) => handleReccDetails ( ) , 250 )
160+ const timer = setTimeout ( ( ) => handleReccDetails ( ) , requestFrequency )
152161 return ( ) => clearTimeout ( timer )
153162 }
154163 } , [ reccCountSorted ] )
@@ -166,26 +175,29 @@ const Bsky = () => {
166175 if ( ! shiftedItem ) {
167176 console . error ( "No handle found to process." )
168177 reccCountSortedCopy . pop ( )
169- setReccCountSorted ( reccCountSortedCopy )
178+ setReccCountSorted ( ( ) => reccCountSortedCopy )
170179 return
171180 }
172181
173182 const [ handle , myFollowers ] = shiftedItem
174183 if ( ! handle ) {
175184 console . error ( "No handle found to process." )
176185 reccCountSortedCopy . pop ( )
177- setReccCountSorted ( reccCountSortedCopy )
186+ setReccCountSorted ( ( ) => reccCountSortedCopy )
178187 return
179188 }
180189
181190 const tooManyDetails = reccDetailsCopy . length > 250
182191 if ( tooManyDetails ) {
192+ console . log ( "Too many details" )
183193 setReccCountSorted ( [ ] )
184194 return
185195 }
186196
187197 const tooFewFollowers = followingCopy . length / 10 > myFollowers
188198 if ( tooFewFollowers ) {
199+ console . log ( "handle =>" , handle )
200+ console . log ( "Too few followers =>" , followingCopy . length , myFollowers )
189201 setReccCountSorted ( [ ] )
190202 return
191203 }
@@ -201,14 +213,14 @@ const Bsky = () => {
201213
202214 reccDetailsCopy . push ( {
203215 myFollowersCount : myFollowers ,
204- score : myFollowers / ( profile . followersCount ?? 1 ) , // number of my following, divided by number of their followers
216+ score : myFollowers / ( profile . followersCount ?? 1 ) ,
205217 profile : profile ,
206218 folledByMe : followingCopy . includes ( profile . handle ) ,
207219 } )
208220
209221 reccCountSortedCopy . pop ( )
210- setReccCountSorted ( reccCountSortedCopy )
211- setReccDetails ( reccDetailsCopy )
222+ setReccCountSorted ( ( ) => reccCountSortedCopy )
223+ setReccDetails ( ( ) => reccDetailsCopy )
212224 } catch ( error ) {
213225 showError ( setError , error )
214226 }
@@ -217,7 +229,10 @@ const Bsky = () => {
217229 // When you have the reccomendation details ...
218230 useEffect ( ( ) => {
219231 if ( reccCountSorted . length == 0 && reccDetailsByScore . length == 0 ) {
220- const timer = setTimeout ( ( ) => handleSortDetailedByScore ( ) , 250 )
232+ const timer = setTimeout (
233+ ( ) => handleSortDetailedByScore ( ) ,
234+ requestFrequency
235+ )
221236 return ( ) => clearTimeout ( timer )
222237 }
223238 } , [ reccCountSorted , reccDetailsByScore ] )
@@ -227,7 +242,7 @@ const Bsky = () => {
227242 try {
228243 const reccDetailsCopy = [ ...reccDetails ]
229244 reccDetailsCopy . sort ( ( a , b ) => b . score - a . score )
230- setReccDetailsByScore ( reccDetailsCopy )
245+ setReccDetailsByScore ( ( ) => reccDetailsCopy )
231246 } catch ( error ) {
232247 showError ( setError , error )
233248 }
0 commit comments