feat(timer): add indicator to the tab title
Adds the current time string to the tab title, enclosed by opening and closing brackets.
This commit is contained in:
parent
ecb6527bae
commit
b3c12153c3
@ -43,13 +43,17 @@ class Indicator extends Component {
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { timer } = this.props;
|
||||
const { timer: prevTimer } = prevProps;
|
||||
const { timer, isTimerActive } = this.props;
|
||||
const { timer: prevTimer, isTimerActive: prevTimerActive } = prevProps;
|
||||
|
||||
if (this.shouldPlayMusic()) {
|
||||
this.playMusic();
|
||||
}
|
||||
|
||||
if (!isTimerActive && prevTimerActive) {
|
||||
this.updateTabTitleTimer(true, this.getTime());
|
||||
}
|
||||
|
||||
this.updateInterval(prevTimer, timer);
|
||||
this.updateAlarmTrigger(prevTimer, timer);
|
||||
}
|
||||
@ -301,6 +305,22 @@ class Indicator extends Component {
|
||||
const { current } = this.timeRef;
|
||||
if (current) {
|
||||
current.textContent = this.getTime();
|
||||
this.updateTabTitleTimer(false, current.textContent);
|
||||
}
|
||||
}
|
||||
|
||||
updateTabTitleTimer(deactivation, timeString) {
|
||||
const matchTimerString = /\[[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\]/g;
|
||||
|
||||
if (deactivation) {
|
||||
document.title = document.title.replace(matchTimerString, '');
|
||||
} else {
|
||||
if (RegExp(matchTimerString).test(document.title)) {
|
||||
document.title = document.title.replace(matchTimerString, '');
|
||||
document.title = '[' + timeString + '] ' + document.title;
|
||||
} else {
|
||||
document.title = '[' + timeString + '] ' + document.title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,7 +343,7 @@ class Indicator extends Component {
|
||||
}
|
||||
|
||||
const onClick = running ? TimerService.stopTimer : TimerService.startTimer;
|
||||
|
||||
this.updateTabTitleTimer(false, time);
|
||||
return (
|
||||
<Styled.TimerWrapper>
|
||||
<Styled.Timer>
|
||||
|
Loading…
Reference in New Issue
Block a user