on master help sign in
feat: only blink blinky after 2.5s of waiting
0e6fe7aMatt Condon (shrugs)
src/components/Blinky.js+10−2
@@ -1,10 +1,11 @@
1−import React, { useState } from 'react';
1+import React, { useState, useRef } from 'react';
2
2
3import useInterval from 'lib/useInterval';
3import useInterval from 'lib/useInterval';
4
4
5// TODO: make these characters display as the same width
5// TODO: make these characters display as the same width
6export const kLoadingCharacter = '▓';
6export const kLoadingCharacter = '▓';
7export const kInterstitialCharacter = '░';
7export const kInterstitialCharacter = '░';
8+const kBlinkAfterMs = 2500; // ms
8
9
9export const matchBlinky = obj =>
10export const matchBlinky = obj =>
10 obj.matchWith({
11 obj.matchWith({
@@ -17,7 +18,14 @@ export default function Blinky({
17 b = kInterstitialCharacter,
18 b = kInterstitialCharacter,
18}) {
19}) {
19 const [value, setValue] = useState(true);
20 const [value, setValue] = useState(true);
21+ const now = useRef(new Date());
22+
23+ useInterval(() => {
24+ // only start blinking if we've elapsed enough time
25+ if (new Date() - now.current > kBlinkAfterMs) {
20− useInterval(() => setValue(val => !val), 1000);
26+ setValue(val => !val);
27+ }
28+ }, 1000);
21
29
22 return value ? a : b;
30 return value ? a : b;
23}
31}