1import React, { useState, useRef } from 'react';
2import { times } from 'lodash';
4import useInterval from 'lib/useInterval';
5import { formatDots } from 'lib/dateFormat';
7// TODO: make these characters display as the same width
8export const LOADING_CHARACTER = '▓';
9export const INTERSTITIAL_CHARACTER = '░';
10const BLINK_AFTER_MS = 2500; // ms
12const buildDate = char =>
13 [4, 2, 2].map(t => times(t, () => char).join('')).join('.');
14const DATE_A = buildDate(LOADING_CHARACTER);
15const DATE_B = buildDate(INTERSTITIAL_CHARACTER);
17export const matchBlinky = obj =>
19 Nothing: () => <Blinky delayed />,
23export const matchBlinkyDate = obj =>
25 Nothing: () => <Blinky a={DATE_A} b={DATE_B} delayed />,
26 Just: p => formatDots(p.value),
29export const blinkIf = (test, right) => (test ? <Blinky /> : right);
31export default function Blinky({
32 a = LOADING_CHARACTER,
33 b = INTERSTITIAL_CHARACTER,
36 const [value, setValue] = useState(true);
37 const now = useRef(new Date());
40 // only start blinking if we've elapsed enough time and want to delay
41 if (!delayed || new Date() - now.current > BLINK_AFTER_MS) {
42 setValue(val => !val);
46 return <span className="arial">{value ? a : b}</span>;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list