aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/note.js
blob: f55c307d94d81b827c7c2b4a6c6e5e172bb1a3c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * A line said once and gone, in the playlists' note (style.css
 * `.playlist-note`): "Link copied", "2 groups unreachable". Not a dialog —
 * nothing here is anyone's to dismiss.
 *
 * Appended to the body rather than rendered by a view, because the views that
 * speak include modals and a context menu that has already closed. One note
 * at a time: a second replaces the first and restarts the clock.
 */

let _note = null;
let _timer = null;

export function say(text, ms = 2500) {
  if (!_note) {
    _note = document.createElement('div');
    _note.className = 'playlist-note page-note';
    _note.setAttribute('role', 'status');
  }
  _note.textContent = text;
  document.body.appendChild(_note);
  clearTimeout(_timer);
  _timer = setTimeout(() => { if (_note) _note.remove(); }, ms);
}