Skip to content

Commit

Permalink
recurring snooze time fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanb10 committed Aug 1, 2021
1 parent abd8fd3 commit 5acc7df
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 53 deletions.
19 changes: 11 additions & 8 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
PRs and other ideas are welcome.

## Changes ##
**August 2021**
#### 2.5.0
- Recurring Snooze Times!
- Duplicate Sleeping Tabs
- Selected Tabs grouped together
- Keyboard Shortcuts in the Popup
- Hide sections in the Nap Room
- Snooze other extension / add-on pages

**June 2021**
#### 2.4.4.3
- Start sending snooze times to analytics server.
#### 2.4.4.3
- Start sending snooze times to analytics server

#### 2.4.4.2
- New setting to specify what day the week starts on
- Fix keybindings + keyboard navigation in the popup (inlcuding new morning/evening/now dropdowns)
- `12345567890` - each of the 10 preset choices
- `c` - custom
- `t` - tab
- `w` - window
- `s` - selected
- Fix keyboard navigation in the popup (inlcuding new morning/evening/now dropdowns)
- Fix missing "Mon", "Tue" etc in the popup calendar

#### 2.4.4
Expand Down
4 changes: 2 additions & 2 deletions html/nap-room.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<div tabindex="0" data-hover="Settings" class="settings"><img src="../icons/settings.png"></div>
<div class="changelog-overlay">
<div id="changelog">
<div id="changelog"><!-- <div id="changelog" class="disabled"> -->
<div class="changelog-container">
<h2 class="center">Snoozz has been updated <span id="v"></span>&nbsp;🎉</h2>
<p>This version is a huge update that brings in one of the most requested features.</p>
Expand All @@ -32,7 +32,7 @@ <h3>What's new?</h3>
<li>Duplicate sleeping tabs</li>
<p>Use the new overflow menus on each sleeping tab to duplicate it and choose a new time.</p>
<li>Hide sections in the nap room</li>
<p>Don't want to see a fat history section every time you're in the nap room? Hide away</p>
<p> Now you dont have to see a fat history section every time you're in the nap room</p>
</ul>
</div>
</div>
Expand Down
24 changes: 6 additions & 18 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ async function snoozeWindow(snoozeTime, isASelection) {
}

async function snoozeRecurring(target, time, repeat, repeatData) {
var next =
var sleepyObj = {
id: getRandomId(),
timeCreated: dayjs().valueOf(),
Expand All @@ -291,8 +290,11 @@ async function snoozeRecurring(target, time, repeat, repeatData) {
}

if (repeat === 'startup') sleepyObj.startUp = true;
if (repeatData) sleepyObj.gap = repeatData;
sleepyObj.wakeUpTime = await calculateNextSnoozeTime(repeat, time, repeatData);
if (Object.keys(repeatData).length) sleepyObj.gap = repeatData;

var next = await calculateNextSnoozeTime(repeat, time, repeatData);
sleepyObj.wakeUpTime = next.valueOf();
console.log(next.format('DD/MM/YY HH:mm'));

if (validTabs.length === 0) return {};
if (validTabs.length === 1 || target === 'tab') {
Expand Down Expand Up @@ -448,7 +450,7 @@ async function getChoices(which) {
}

async function calculateNextSnoozeTime(repeat, start, data) {
var NOW = dayjs().add(1, 'M'), start = dayjs(start);
var NOW = dayjs(), start = dayjs(start);
if (repeat === 'custom' && data) {
var days = [];
if (data.weekly) {
Expand Down Expand Up @@ -483,27 +485,13 @@ async function calculateNextSnoozeTime(repeat, start, data) {
return NOW.startOf('w').add(isThisWeek ? 0 : 1, 'w').day(1).hour(start.hour()).minute(start.minute());
} else if (repeat === 'weekly') {
var isThisWeek = NOW.day() < start.day() || (NOW.day() === start.day() && (NOW.hour() < start.hour() || (NOW.hour() === start.hour() && NOW.minute() < start.minute())));
console.log(isThisWeek);
return NOW.startOf('w').add(isThisWeek ? 0 : 1, 'w').day(start.day()).hour(start.hour()).minute(start.minute());
} else if (repeat === 'monthly') {
var isThisMonth = NOW.date() < start.date() || (NOW.date() === start.date() && (NOW.hour() < start.hour() ||( NOW.hour() === start.hour() && NOW.minute() < start.minute()))) ? 0 : 1;
var isMonthValid = start.date() <= NOW.daysInMonth(isThisMonth, 'M') ? 0 : 1;
return NOW.startOf('M').add(isThisMonth + isMonthValid, 'M').date(start.date()).hour(start.hour()).minute(start.minute());
}
return false;
// } else if (repeat === 'hourly') {
// var isNextHour = NOW.minute() >= start.minute()
// return dayjs().startOf('h').add(isNextHour ? 1 : 0, 'h').add(start.minute(), 'm')
// } else if (repeat === 'daily' || repeat === 'daily_morning' || repeat === 'daily_evening') {
// var isTomorrow = (NOW.hour() === start.hour() && NOW.minute() >= start.minute()) || NOW.hour() > start.hour();
// return dayjs().startOf('d').add(isTomorrow ? 1 : 0, 'd').add(start.hour(), 'h').add(start.minute(), 'm')
// } else if (repeat === 'weekly' || repeat === 'weekends' || repeat === 'mondays') {
// var isNextWeek = NOW.weekday() === start.weekday() && ((NOW.hour() === start.hour() && NOW.minute() >= start.minute()) || (NOW.hour() > start.hour()));
// return dayjs().startOf('w').add(start.weekday(), 'd').add(isNextWeek ? 1 : 0, 'w').add(start.hour(), 'h').add(start.minute(), 'm')
// } else if (repeat === 'monthly') {
// var isNextMonth = NOW.date() > start.date() || (NOW.date() === start.date() && ((NOW.hour() > start.hour()) || (NOW.hour() === start.hour() && NOW.minute() >= start.minute())));
// return dayjs().startOf('M').add(start.date() - 1, 'd').add(isNextMonth ? 1 : 0, 'M').add(start.hour(), 'h').add(start.minute(), 'm')
// }
}

/* END ASYNC FUNCTIONS */
Expand Down
14 changes: 8 additions & 6 deletions scripts/nap_room.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,14 @@ async function checkForUpdates() {
var p = await new Promise(r => chrome.storage.local.get(['updated'], r));
if (!p || !p.updated) return;

var overlay = document.querySelector('body > .changelog-overlay');
overlay.querySelector('#v').innerText = `to v${chrome.runtime.getManifest().version}`;
overlay.classList.add('open');
bsf.freeze();
overlay.addEventListener('click', closeChangelog, {once: true});
document.addEventListener('keyup', closeChangelog);
if (!document.getElementById('changelog').classList.contains('disabled')) {
var overlay = document.querySelector('body > .changelog-overlay');
overlay.querySelector('#v').innerText = `to v${chrome.runtime.getManifest().version}`;
overlay.classList.add('open');
bsf.freeze();
overlay.addEventListener('click', closeChangelog, {once: true});
document.addEventListener('keyup', closeChangelog);
}

await new Promise(r => chrome.storage.local.remove(['updated'], r));
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ async function snooze(time, choice) {
data.monthly = document.getElementById('monthly')._flatpickr.selectedDates.map(d => dayjs(d).date()).sort(desc);
}
if (id === 'weekly') time = time.subtract(1, 'w')
if (id === 'monthly') time = time.subtract(1, 'M').subtract(2, 'd');
if (id === 'monthly') time = time.subtract(1, 'M');
response = await snoozeRecurring(target.id, time, id, data);
return;
} else {
Expand Down
12 changes: 6 additions & 6 deletions styles/flatpickr.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
cursor: pointer;
}
.numInputWrapper span:hover {
background: rgba(0,0,0,0.1);
background: rgba(0, 0, 0, .1);
}
.numInputWrapper span:active {
background: rgba(0,0,0,0.2);
background: rgba(0, 0, 0, .2);
}
.numInputWrapper span:after {
display: block;
Expand All @@ -107,7 +107,7 @@
top: 40%;
}
.numInputWrapper:hover {
background: rgba(0,0,0,0.05);
background: rgba(0, 0, 0, .05);
}
.numInputWrapper:hover span {
opacity: 1;
Expand Down Expand Up @@ -166,7 +166,7 @@
outline: none;
}
.f-current-month .f-monthDropdown-months:hover {
background: rgba(0,0,0,0.05);
background: rgba(0, 0, 0, .05);
}
.f-current-month .f-monthDropdown-months .f-monthDropdown-month {
color: #000;
Expand Down Expand Up @@ -255,7 +255,7 @@
.f-day.notAllowed,
.f-day.notAllowed.prevMonthDay,
.f-day.notAllowed.nextMonthDay {
color: rgba(57,57,57,0.3);
color: rgba(57, 57, 57, .3);
background: transparent;
border-color: transparent;
cursor: default;
Expand All @@ -267,7 +267,7 @@ body.dark .f-day.nextMonthDay,
body.dark .f-day.notAllowed,
body.dark .f-day.notAllowed.prevMonthDay,
body.dark .f-day.notAllowed.nextMonthDay {
color: rgba(204, 204, 204, 0.3);
color: rgba(204, 204, 204, .3);
}
.f-day.f-disabled,
.f-day.f-disabled:hover {
Expand Down
4 changes: 2 additions & 2 deletions styles/nap-room.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ body.dark .tooltip:focus-within:after, body.dark .tooltip:hover:after {
background-color: var(--bg-color);
z-index: 3;
border-radius: .25rem;
box-shadow: 0 1px 1px rgba(0,0,0,0.12), 0 2px 2px rgba(0,0,0,0.12), 0 4px 4px rgba(0,0,0,0.12), 0 8px 8px rgba(0,0,0,0.12),0 16px 16px rgba(0,0,0,0.12);
box-shadow: 0 1px 1px rgba(0, 0, 0, .12), 0 2px 2px rgba(0, 0, 0, .12), 0 4px 4px rgba(0, 0, 0, .12), 0 8px 8px rgba(0, 0, 0, .12),0 16px 16px rgba(0, 0, 0, .12);
}
.overflow-menu.show {
display: block;
Expand Down Expand Up @@ -488,7 +488,7 @@ body:not(.dark) > p {
left: 0;
height: 100vh;
width: 100vw;
background-color: rgba(0,0,0,.75);
background-color: rgba(0, 0, 0, .75);
justify-content: center;
align-items: center;
flex-direction: column;
Expand Down
23 changes: 13 additions & 10 deletions styles/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ h3 {
cursor: pointer;
}
.day-choice:hover {
background-color: rgba(0,0,0,0.1);
background-color: rgba(0, 0, 0, .1);
}
.day-choice span:before {
content: '';
Expand All @@ -224,10 +224,13 @@ h3 {

height: .6rem;
width: .6rem;
border: 3px solid rgba(0,0,0,0.2);
border: 3px solid rgba(0, 0, 0, .2);
border-radius: .25rem;
transition: all .25s ease-in-out;
}
body.dark .day-choice span:before {
border: 3px solid rgba(255, 255, 255, .2);
}
.day-choice span.active:before {
left: .9rem;
width: .33rem;
Expand Down Expand Up @@ -258,7 +261,7 @@ h3 {
.time-wrapper .f-calendar, .repeat-time-wrapper .f-calendar {
width: 150px;
transform: scale(1.25);
background: rgba(0,0,0,0.1);
background: rgba(0, 0, 0, .1);
}
.quick-actions {
margin-top: 3rem;
Expand All @@ -278,10 +281,10 @@ h3 {
cursor: pointer;
text-align: center;
min-width: 70px;
background: rgba(0,0,0,0.1);
background: rgba(0, 0, 0, .1);
}
.action:not(.disabled):hover {
background: rgba(0,0,0,0.2);
background: rgba(0, 0, 0, .2);
}
.action.disabled {
cursor: not-allowed;
Expand Down Expand Up @@ -415,15 +418,15 @@ body.dark .choice .date {
padding: .5rem;
color: #FFF;
border-radius: .25rem;
background: rgba(0,0,0,.25);
background: rgba(0, 0, 0, .25);
}
.submit-btn:hover {
background: rgba(0,0,0,.4);
background: rgba(0, 0, 0, .4);
}
.submit-btn.disabled {
pointer-events: none;
touch-action: none;
opacity: 0.2;
opacity: .2;
}
.repeat-choice-overlay {
position: absolute;
Expand Down Expand Up @@ -454,7 +457,7 @@ body.dark .choice .date {
}
.choice select:focus:hover {
color: var(--color);
background-color: rgba(0,0,0,.5);
background-color: rgba(0, 0, 0, .5);
}

body.dark #preview, body.dark .choice, body.dark .custom-choice, body.dark .form-overlay {
Expand Down Expand Up @@ -507,7 +510,7 @@ body.dark .upcoming {
width: 1.75em;
}
.settings:before {
top: -0.15em;
top: -.15em;
line-height: 1.4;
font-size: unset;
border-radius: .25em;
Expand Down

0 comments on commit 5acc7df

Please sign in to comment.