-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: support 30 min streak offsets (@large-r0dent) #7269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
676a094
ced0876
dd4e587
000d643
293705b
db5ea94
4f83611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import { Snapshot } from "../constants/default-snapshot"; | |
|
|
||
| export function show(): void { | ||
| if (!ConnectionState.get()) { | ||
| Notifications.add("You are offline", 0, { | ||
| Notifications.add("You are offline :(", 0, { | ||
| duration: 2, | ||
| }); | ||
| return; | ||
|
|
@@ -24,7 +24,7 @@ export function show(): void { | |
| modalEl.querySelector(".preview")?.remove(); | ||
| modalEl.querySelector("button")?.remove(); | ||
| (modalEl.querySelector(".text") as HTMLElement).textContent = | ||
| "You have already set your streak hour offset."; | ||
| "You have already set your streak time offset."; | ||
| } else { | ||
| (modalEl.querySelector("input") as HTMLInputElement).value = "0"; | ||
| updatePreview(); | ||
|
|
@@ -34,26 +34,24 @@ export function show(): void { | |
| } | ||
|
|
||
| function updatePreview(): void { | ||
| const inputValue = parseInt( | ||
| const inputValue = parseFloat( | ||
| // parse float to support fractional stuff | ||
| modal.getModal().querySelector("input")?.value as string, | ||
| 10, | ||
| ); | ||
|
|
||
| const preview = modal.getModal().querySelector(".preview") as HTMLElement; | ||
|
|
||
| const date = new Date(); | ||
| date.setUTCHours(0); | ||
| date.setUTCMinutes(0); | ||
| date.setUTCSeconds(0); | ||
| date.setUTCMilliseconds(0); | ||
| date.setUTCHours(0, 0, 0, 0); | ||
|
|
||
| const newDate = new Date(); | ||
| newDate.setUTCHours(0); | ||
| newDate.setUTCMinutes(0); | ||
| newDate.setUTCSeconds(0); | ||
| newDate.setUTCMilliseconds(0); | ||
| newDate.setUTCHours(0, 0, 0, 0); | ||
|
|
||
| newDate.setHours(newDate.getHours() - -1 * inputValue); //idk why, but it only works when i subtract (so i have to negate inputValue) | ||
| const hours = Math.floor(inputValue); | ||
| const minutes = (inputValue % 1) * 60; | ||
|
|
||
| newDate.setUTCHours(newDate.getUTCHours() + hours); | ||
| newDate.setUTCMinutes(newDate.getUTCMinutes() + minutes); | ||
|
|
||
| preview.innerHTML = ` | ||
| <div class="row"><div>Current local reset time:</div><div>${date.toLocaleTimeString()}</div></div> | ||
|
|
@@ -66,18 +64,21 @@ function hide(): void { | |
| } | ||
|
|
||
| async function apply(): Promise<void> { | ||
| const value = parseInt( | ||
| const value = parseFloat( | ||
| // parse float again | ||
| modal.getModal().querySelector("input")?.value as string, | ||
| 10, | ||
| ); | ||
|
|
||
| if (isNaN(value)) { | ||
| Notifications.add("Streak hour offset must be a number", 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we call it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think i would revert the change to "time" and just keep it "hour" everywhere. Half hours are still hours.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Miodec |
||
| return; | ||
| } | ||
|
|
||
| if (value < -11 || value > 12) { | ||
| Notifications.add("Streak hour offset must be between -11 and 12", 0); | ||
| if (value < -11 || value > 12 || (value % 1 !== 0 && value % 1 !== 0.5)) { | ||
Miodec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Notifications.add( | ||
| "Streak offset must be between -11 and 12. Times ending in .5 can be used for 30-minute increments.", | ||
| 0, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -87,11 +88,13 @@ async function apply(): Promise<void> { | |
| body: { hourOffset: value }, | ||
| }); | ||
| Loader.hide(); | ||
|
|
||
| if (response.status !== 200) { | ||
| Notifications.add("Failed to set streak hour offset", -1, { response }); | ||
| } else { | ||
| Notifications.add("Streak hour offset set", 1); | ||
| const snap = getSnapshot() as Snapshot; | ||
|
|
||
| snap.streakHourOffset = value; | ||
| setSnapshot(snap); | ||
| hide(); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert?