Skip to content

Commit

Permalink
Make timer name case insesnsitive, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
snazzyfox committed Sep 18, 2023
1 parent 3bb3214 commit 7fb17e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/pages/TimerConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
</p>

<p>
If a timer with the given title already exists, it will be updated. You can also place
a plus (&plus;) or minus (&minus;) before the time to add or subtract time to the
existing timer instead of overwriting it with a new time.
If a timer with the given title already exists, it will be updated. The title of
timers are matched case insensitively. You can also place a plus (&plus;) or minus
(&minus;) before the time to add or subtract time to the existing timer instead of
overwriting it with a new time.
</p>
</q-item-label>
</q-item-section>
Expand Down
10 changes: 8 additions & 2 deletions src/pages/TimerWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,14 @@ function formatTime(milliseconds: number) {
}
}
function getTimerIndex(title: string) {
return timerData.value.findIndex(
(timer) => timer.title.trim().toLowerCase() === title.trim().toLowerCase()
);
}
function addTimer(duration: string, title: string) {
const existingIndex = timerData.value.findIndex((t) => t.title === title);
const existingIndex = getTimerIndex(title);
if (duration === 'up') {
const newTimer: TimerData = { time: Date.now(), direction: 'up', title };
if (existingIndex > -1) {
Expand Down Expand Up @@ -204,7 +210,7 @@ function addTimer(duration: string, title: string) {
function removeTimer(title: string) {
// See if a timer with the given title can be found
let index = timerData.value.findIndex((timer) => timer.title === title);
let index = getTimerIndex(title);
if (index === -1) {
index = parseInt(title[0]) - 1;
}
Expand Down

0 comments on commit 7fb17e9

Please sign in to comment.