@@ -7,7 +7,7 @@ import useInterval from 'react-use/lib/useInterval';
7
7
import { filesize } from 'filesize' ;
8
8
9
9
import type { PubkeyType } from 'libsession_util_nodejs' ;
10
- import { chunk } from 'lodash' ;
10
+ import { chunk , toNumber } from 'lodash' ;
11
11
import { Flex } from '../../basic/Flex' ;
12
12
import { SpacerXS } from '../../basic/Text' ;
13
13
import { localize } from '../../../localization/localeTools' ;
@@ -30,6 +30,7 @@ import { ConvoHub } from '../../../session/conversations';
30
30
import { ConversationTypeEnum } from '../../../models/types' ;
31
31
import { ContactsWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface' ;
32
32
import { usePolling } from '../../../hooks/usePolling' ;
33
+ import { SessionInput } from '../../inputs' ;
33
34
34
35
const hexRef = [ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ] ;
35
36
@@ -215,61 +216,6 @@ const ClearOldLogsButton = () => {
215
216
) ;
216
217
} ;
217
218
218
- const dummyContactPerClick = 500 ;
219
-
220
- async function fetchContactsCountAndUpdate ( ) {
221
- const count = ( await ContactsWrapperActions . getAll ( ) ) . length ;
222
- if ( count && Number . isFinite ( count ) ) {
223
- return count ;
224
- }
225
- return 0 ;
226
- }
227
-
228
- function AddDummyContactButton ( ) {
229
- const [ loading , setLoading ] = useState ( false ) ;
230
- const [ addedCount , setAddedCount ] = useState ( 0 ) ;
231
-
232
- const { data : contactsCount } = usePolling (
233
- fetchContactsCountAndUpdate ,
234
- 1000 ,
235
- 'AddDummyContactButton'
236
- ) ;
237
-
238
- return (
239
- < SessionButton
240
- onClick = { async ( ) => {
241
- if ( loading ) {
242
- return ;
243
- }
244
- try {
245
- setLoading ( true ) ;
246
- setAddedCount ( 0 ) ;
247
- const chunkSize = 10 ;
248
- const allIndexes = Array . from ( { length : dummyContactPerClick } ) . map ( ( _unused , i ) => i ) ;
249
- const chunks = chunk ( allIndexes , chunkSize ) ;
250
- for ( let chunkIndex = 0 ; chunkIndex < chunks . length ; chunkIndex ++ ) {
251
- // eslint-disable-next-line no-await-in-loop
252
- await Promise . all ( chunks [ chunkIndex ] . map ( ( ) => generateOneRandomContact ( ) ) ) ;
253
- setAddedCount ( Math . min ( chunkIndex * chunkSize , dummyContactPerClick ) ) ;
254
- }
255
- } finally {
256
- setLoading ( false ) ;
257
- setAddedCount ( 0 ) ;
258
- }
259
- } }
260
- disabled = { loading }
261
- >
262
- { loading ? (
263
- < >
264
- { addedCount } /{ dummyContactPerClick } ...
265
- </ >
266
- ) : (
267
- `Add ${ dummyContactPerClick } contacts (${ contactsCount } )`
268
- ) }
269
- </ SessionButton >
270
- ) ;
271
- }
272
-
273
219
export const DebugActions = ( ) => {
274
220
const dispatch = useDispatch ( ) ;
275
221
@@ -338,12 +284,112 @@ export const DebugActions = () => {
338
284
>
339
285
Open storage profile
340
286
</ SessionButton >
341
- < AddDummyContactButton />
342
287
</ Flex >
343
288
</ >
344
289
) ;
345
290
} ;
346
291
292
+ async function fetchContactsCountAndUpdate ( ) {
293
+ const count = ( await ContactsWrapperActions . getAll ( ) ) . length ;
294
+ if ( count && Number . isFinite ( count ) ) {
295
+ return count ;
296
+ }
297
+ return 0 ;
298
+ }
299
+
300
+ function AddDummyContactButton ( ) {
301
+ const [ loading , setLoading ] = useState ( false ) ;
302
+ const [ addedCount , setAddedCount ] = useState ( 0 ) ;
303
+ const [ countToAdd , setCountToAdd ] = useState ( 500 ) ;
304
+
305
+ const { data : contactsCount } = usePolling (
306
+ fetchContactsCountAndUpdate ,
307
+ 500 ,
308
+ 'AddDummyContactButton'
309
+ ) ;
310
+
311
+ return (
312
+ < div style = { { display : 'flex' , alignItems : 'center' } } >
313
+ < SessionInput
314
+ autoFocus = { false }
315
+ disableOnBlurEvent = { true }
316
+ type = "text"
317
+ value = { `${ countToAdd } ` }
318
+ onValueChanged = { ( value : string ) => {
319
+ const asNumber = toNumber ( value ) ;
320
+ if ( Number . isFinite ( asNumber ) ) {
321
+ setCountToAdd ( asNumber ) ;
322
+ }
323
+ } }
324
+ loading = { loading }
325
+ maxLength = { 10 }
326
+ ctaButton = {
327
+ < SessionButton
328
+ onClick = { async ( ) => {
329
+ if ( loading ) {
330
+ return ;
331
+ }
332
+ try {
333
+ setLoading ( true ) ;
334
+ setAddedCount ( 0 ) ;
335
+ const chunkSize = 10 ;
336
+ const allIndexes = Array . from ( { length : countToAdd } ) . map ( ( _unused , i ) => i ) ;
337
+ const chunks = chunk ( allIndexes , chunkSize ) ;
338
+ for ( let chunkIndex = 0 ; chunkIndex < chunks . length ; chunkIndex ++ ) {
339
+ // eslint-disable-next-line no-await-in-loop
340
+ await Promise . all ( chunks [ chunkIndex ] . map ( ( ) => generateOneRandomContact ( ) ) ) ;
341
+ setAddedCount ( Math . min ( chunkIndex * chunkSize , countToAdd ) ) ;
342
+ }
343
+ } finally {
344
+ setLoading ( false ) ;
345
+ setAddedCount ( 0 ) ;
346
+ }
347
+ } }
348
+ disabled = { loading }
349
+ >
350
+ { loading ? (
351
+ < >
352
+ { addedCount } /{ countToAdd } ...
353
+ </ >
354
+ ) : (
355
+ `Add ${ countToAdd } contacts (current: ${ contactsCount } )`
356
+ ) }
357
+ </ SessionButton >
358
+ }
359
+ />
360
+ </ div >
361
+ ) ;
362
+ }
363
+
364
+ export const DataGenerationActions = ( ) => {
365
+ return (
366
+ < Flex
367
+ $container = { true }
368
+ width = { '100%' }
369
+ $flexDirection = "column"
370
+ $justifyContent = "flex-start"
371
+ $alignItems = "flex-start"
372
+ $flexWrap = "wrap"
373
+ >
374
+ < SpacerXS />
375
+ < Flex $container = { true } width = "100%" $alignItems = "center" $flexGap = "var(--margins-xs)" >
376
+ < h2 > Data generation</ h2 >
377
+ </ Flex >
378
+ < Flex
379
+ $container = { true }
380
+ width = "100%"
381
+ $flexDirection = "column"
382
+ $justifyContent = "space-between"
383
+ $alignItems = "flex-start"
384
+ $flexGap = "var(--margins-xs)"
385
+ >
386
+ < AddDummyContactButton />
387
+ < SpacerXS />
388
+ </ Flex >
389
+ </ Flex >
390
+ ) ;
391
+ } ;
392
+
347
393
export const AboutInfo = ( ) => {
348
394
const environmentStates = [ ] ;
349
395
0 commit comments