Skip to content

Commit 35f67d5

Browse files
authored
Merge pull request #152 from vedansh-5/dateSelect
Improved date selection logic
2 parents 4821275 + 3418594 commit 35f67d5

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

src/popup.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ <h4>Your Github Username</h4>
7474
<p class="text-sm">Fetch your contributions between:</p>
7575
<div class="flex justify-between items-center my-2 mx-4">
7676
<div class="flex items-center gap-2">
77-
<input type="radio" id="lastWeekContribution" name="timeframe" class="form-radio"
78-
onclick="toggleRadio(this)">
77+
<input type="radio" id="lastWeekContribution" name="timeframe" class="form-radio">
7978
<label for="lastWeekContribution">Last 7 days</label>
8079
</div>
8180
<div class="flex items-center gap-2">
82-
<input type="radio" id="yesterdayContribution" name="timeframe" class="form-radio"
83-
onclick="toggleRadio(this)">
81+
<input type="radio" id="yesterdayContribution" name="timeframe" class="form-radio">
8482
<label for="yesterdayContribution">Last 1 day</label>
8583
</div>
8684
</div>

src/scripts/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ function handleLastWeekContributionChange() {
124124
let value = lastWeekContributionElement.checked;
125125
let labelElement = document.querySelector("label[for='lastWeekContribution']");
126126
if (value) {
127-
startingDateElement.disabled = true;
128-
endingDateElement.disabled = true;
129-
endingDateElement.value = getToday();
130-
startingDateElement.value = getLastWeek();
131-
handleEndingDateChange();
132-
handleStartingDateChange();
133-
labelElement.classList.add("selectedLabel");
134-
labelElement.classList.remove("unselectedLabel");
127+
startingDateElement.readOnly = true;
128+
endingDateElement.readOnly = true;
129+
endingDateElement.value = getToday();
130+
startingDateElement.value = getLastWeek();
131+
handleEndingDateChange();
132+
handleStartingDateChange();
133+
labelElement.classList.add("selectedLabel");
134+
labelElement.classList.remove("unselectedLabel");
135135
} else {
136-
startingDateElement.disabled = false;
137-
endingDateElement.disabled = false;
138-
labelElement.classList.add("unselectedLabel");
139-
labelElement.classList.remove("selectedLabel");
136+
startingDateElement.readOnly = false;
137+
endingDateElement.readOnly = false;
138+
labelElement.classList.add("unselectedLabel");
139+
labelElement.classList.remove("selectedLabel");
140140
}
141141

142142
chrome.storage.local.set({ lastWeekContribution: value });
@@ -147,17 +147,17 @@ function handleYesterdayContributionChange() {
147147
let labelElement = document.querySelector("label[for='yesterdayContribution']");
148148

149149
if (value) {
150-
startingDateElement.disabled = true;
151-
endingDateElement.disabled = true;
150+
startingDateElement.readOnly = true;
151+
endingDateElement.readOnly = true;
152152
endingDateElement.value = getToday();
153153
startingDateElement.value = getYesterday();
154154
handleEndingDateChange();
155155
handleStartingDateChange();
156156
labelElement.classList.add("selectedLabel");
157157
labelElement.classList.remove("unselectedLabel");
158158
} else {
159-
startingDateElement.disabled = false;
160-
endingDateElement.disabled = false;
159+
startingDateElement.readOnly = false;
160+
endingDateElement.readOnly = false;
161161
labelElement.classList.add("unselectedLabel");
162162
labelElement.classList.remove("selectedLabel");
163163
}

src/scripts/popup.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ document.addEventListener('DOMContentLoaded', function () {
256256

257257
const startDateInput = document.getElementById('startingDate');
258258
const endDateInput = document.getElementById('endingDate');
259-
startDateInput.disabled = false;
260-
endDateInput.disabled = false;
259+
startDateInput.readOnly = false;
260+
endDateInput.readOnly = false;
261261

262262
chrome.storage.local.set({
263263
lastWeekContribution: false,
@@ -294,9 +294,8 @@ document.addEventListener('DOMContentLoaded', function () {
294294
startDateInput.value = getYesterday();
295295
endDateInput.value = getToday();
296296
}
297-
298-
startDateInput.disabled = endDateInput.disabled = true;
299-
297+
startDateInput.readOnly = endDateInput.readOnly = true;
298+
300299
chrome.storage.local.set({
301300
startingDate: startDateInput.value,
302301
endingDate: endDateInput.value,
@@ -485,8 +484,8 @@ document.querySelectorAll('input[name="timeframe"]').forEach(radio => {
485484

486485
const startDateInput = document.getElementById('startingDate');
487486
const endDateInput = document.getElementById('endingDate');
488-
startDateInput.disabled = false;
489-
endDateInput.disabled = false;
487+
startDateInput.readOnly = false;
488+
endDateInput.readOnly = false;
490489

491490
chrome.storage.local.set({
492491
lastWeekContribution: false,
@@ -558,7 +557,7 @@ function toggleRadio(radio) {
558557
endDateInput.value = getToday();
559558
}
560559

561-
startDateInput.disabled = endDateInput.disabled = true;
560+
startDateInput.readOnly = endDateInput.readOnly = true;
562561

563562
chrome.storage.local.set({
564563
startingDate: startDateInput.value,

0 commit comments

Comments
 (0)