Skip to content

Commit

Permalink
Switch tab when tab date is today
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed May 17, 2024
1 parent c1192a2 commit e3dba6d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/javascript/controllers/schedule_table_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ export default class extends Controller {
return;
}


if (id === '') {
tables[0].classList.remove('hidden');
buttons[0].classList.add('tab-btn-active');
const current = new Date();
const today = `${current.getFullYear()}-${("0"+(current.getMonth() + 1)).slice(-2)}-${current.getDate()}`;
var index = [...buttons].findIndex((button) => button.value.toString() === today );

if (index === -1) {
index = 0
}

tables[index].classList.remove('hidden');
buttons[index].classList.add('tab-btn-active');

return;
}

Expand Down

0 comments on commit e3dba6d

Please sign in to comment.