Skip to content

Commit

Permalink
Merge pull request #36 from saertna/FortuneInfusion-Cooldown
Browse files Browse the repository at this point in the history
React correctly on Cooldown when Modal still open
  • Loading branch information
saertna committed Nov 5, 2023
2 parents 697b685 + d47a5a3 commit c5ff61b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
22 changes: 13 additions & 9 deletions main.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/MultiSelectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,16 @@ export class MultiSelectModal extends Modal {
stockInfo.innerHTML = ''; // Clear the current content
stockInfo.innerHTML = `${labelText} : (${stock})`;
}
const buttonUse = document.querySelector(`#use-button-${labelText.replace(' ', '-')}`);
const date = this.gamificationInstance.getSettingString(this.getBoosterDateFromName(labelText));
const momentDate = window.moment(date as string, 'YYYY-MM-DD HH:mm:ss');
if (buttonUse && isMinutesPassed(momentDate, this.getBoosterCooldownFromName(labelText)) == false) {
buttonUse.setText(`cooldown ${hoursUntilMinutesPassed(momentDate, this.getBoosterCooldownFromName(labelText))} hours`);
const buttonUse: HTMLButtonElement | null = document.querySelector(`#use-button-${labelText.replace(' ', '-')}`);
if (buttonUse !== null) {
const date = this.gamificationInstance.getSettingString(this.getBoosterDateFromName(labelText));
const momentDate = window.moment(this.gamificationInstance.getSettingString(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss');
if (isMinutesPassed(momentDate, this.getBoosterCooldownFromName(labelText)) == false) {
buttonUse.setText(`cooldown ${hoursUntilMinutesPassed(momentDate, this.getBoosterCooldownFromName(labelText))} hours`);
buttonUse.onclick = () => {
new ModalInformationbox(this.app, `${labelText} is for ${hoursUntilMinutesPassed(momentDate, this.getBoosterCooldownFromName(labelText))} hours in cooldown and can only then be used again.`).open();
}
}
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export default class gamification extends Plugin {
//this.setSettingString('weeklyNoteCreationDate', window.moment().format('DD.MM.YYYY'))
//this.setSettingString('weeklyNoteCreationDate', window.moment().format('DD.MM.YYYY'))
//await this.saveSettings();
//new ModalBooster(this.app, ` `, this).open();
this.updateAvatarPage(this.getSettingString('avatarPageName'))
new ModalBooster(this.app, ` `, this).open();
//this.updateAvatarPage(this.getSettingString('avatarPageName'))
});
}

Expand Down Expand Up @@ -727,10 +727,9 @@ export default class gamification extends Plugin {
let direction = '↕️'
if(this.getSettingNumber('dailyNoteCreationTask')==1){
direction = '➡️';
}
if(this.getSettingBoolean('streakboosterDate')){
} else if(this.getSettingBoolean('streakboosterDate')){
direction = '⬆️';
} else {
} else if(!this.getSettingBoolean('streakboosterDate')){
direction = '⬇️';
}
return direction
Expand Down Expand Up @@ -1300,7 +1299,7 @@ function isOneDayBefore(inputDate: Moment): boolean {

export function isMinutesPassed(inputDate: Moment, minutesPassed: number): boolean {
const minutesAgo = window.moment().subtract(minutesPassed, 'minutes'); // Calculate time 'minutesPassed' minutes ago
return inputDate.isSameOrBefore(minutesAgo);
return inputDate.isSameOrBefore(minutesAgo);
}


Expand Down

0 comments on commit c5ff61b

Please sign in to comment.