From 72c2952e158064b902e4d5b64ea932f9a984f300 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Mon, 21 May 2018 11:37:12 +0200 Subject: [PATCH] use singular if visitor count == 1. closes #34 --- assets/js/components/Realtime.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assets/js/components/Realtime.js b/assets/js/components/Realtime.js index 5a34bcc..ba88c7d 100644 --- a/assets/js/components/Realtime.js +++ b/assets/js/components/Realtime.js @@ -23,12 +23,19 @@ class Realtime extends Component { clearInterval(this.interval); } + @bind + setDocumentTitle() { + // update document title + let visitorText = this.state.count == 1 ? 'visitor' : 'visitors'; + document.title = ( this.state.count > 0 ? `${this.state.count} current ${visitorText} — Fathom` : 'Fathom' ); + } + @bind fetchData() { Client.request(`stats/site/realtime`) .then((d) => { this.setState({ count: d }) - document.title = ( d > 0 ? d + ' current visitors — Fathom' : 'Fathom' ); + this.setDocumentTitle(); }) .catch((e) => { if(e.message == 401) {