This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add max date for appointment #86
Open
Pistashe
wants to merge
3
commits into
dunglas:main
Choose a base branch
from
Pistashe:date-max-rdv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ class AppStatus { | |
this.injectionType = "fullServiceInjection"; | ||
/** @type {'modernaInjection' | 'pfizerInjection'} vaccin d'injection souhaité par le user */ | ||
this.injectionVaccine = "pfizerInjection"; | ||
/** @type {Date} Date max de recherche de rdv (par défaut aujd + 1 mois) */ | ||
this.dateMaxSearch = new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()); | ||
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été ajouté */ | ||
this.onLocationAddedCb = (job) => {}; | ||
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été supprimée */ | ||
|
@@ -34,6 +36,8 @@ class AppStatus { | |
this.onInjectionTypeCb = (newValue) => {}; | ||
/** @type {'modernaInjection' | 'pfizerInjection'} callback quand injectionVaccine change de valeur */ | ||
this.onInjectionVaccineCb = (newValue) => {}; | ||
/** @type {Date} callback quand maxDateSearch change de valeur */ | ||
this.onDateMaxSearchCb = (newValue) => {}; | ||
|
||
this.onStorageChange = this.onStorageChange.bind(this); | ||
browser.storage.onChanged.addListener(this.onStorageChange); | ||
|
@@ -49,6 +53,7 @@ class AppStatus { | |
autoBook: false, | ||
injectionType: "fullServiceInjection", | ||
injectionVaccine: "pfizerInjection", | ||
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()), | ||
}); | ||
|
||
Object.keys(result.locations).forEach((url) => { | ||
|
@@ -67,6 +72,9 @@ class AppStatus { | |
|
||
this.injectionVaccine = result.injectionVaccine; | ||
this.onInjectionVaccineCb(this.injectionVaccine); | ||
|
||
this.dateMaxSearch = result.dateMaxSearch; | ||
this.onDateMaxSearchCb(this.dateMaxSearch); | ||
} | ||
|
||
getLocations() { | ||
|
@@ -105,6 +113,10 @@ class AppStatus { | |
return this.injectionVaccine; | ||
} | ||
|
||
getDateMaxSearch() { | ||
return this.dateMaxSearch; | ||
} | ||
|
||
/** | ||
* @param {(string) => void} cbAdd callback quand une {@link VaccineLocation} a été ajouté | ||
* @param {(string) => void} cbDelete callback quand une {@link VaccineLocation} a été supprimée | ||
|
@@ -142,6 +154,13 @@ class AppStatus { | |
this.onInjectionVaccineCb = callback; | ||
} | ||
|
||
/** | ||
* @param {(Date) => void} callback quand dateMaxSearch change de valeur | ||
*/ | ||
onDateMaxSearchChange(callback) { | ||
this.onDateMaxSearchCb = callback; | ||
} | ||
|
||
start() { | ||
this.stopped = false; | ||
browser.storage.sync.set({ stopped: this.stopped }); | ||
|
@@ -168,6 +187,15 @@ class AppStatus { | |
browser.storage.sync.set({ injectionType: this.injectionType }); | ||
} | ||
|
||
|
||
/** | ||
* @param {Date} value The new dateMaxSearch value | ||
*/ | ||
setDateMaxSearch(value) { | ||
this.dateMaxSearch = new Date(value.value); | ||
browser.storage.sync.set({ dateMaxSearch: this.dateMaxSearch }); | ||
} | ||
|
||
/** | ||
* @param {'modernaInjection' | 'pfizerInjection'} value The new injectionVaccine value | ||
*/ | ||
|
@@ -193,6 +221,8 @@ class AppStatus { | |
this.onInjectionTypeCb(this.injectionType); | ||
this.injectionVaccine = "pfizerInjection"; | ||
this.onInjectionTypeCb(this.injectionVaccine); | ||
this.dateMaxSearch = new Date((new Date()).getFullYear(), (new Date()).getMonth()+1, (new Date()).getDate()); | ||
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. Ici on rajoute encore |
||
this.onDateMaxSearchCb(this.dateMaxSearch); | ||
} | ||
|
||
/** | ||
|
@@ -209,6 +239,7 @@ class AppStatus { | |
this.onAutoBookChangeCb = null; | ||
this.onInjectionTypeCb = null; | ||
this.onInjectionVaccineCb = null; | ||
this.onDateMaxSearchCb = null; | ||
} | ||
|
||
/** | ||
|
@@ -262,5 +293,10 @@ class AppStatus { | |
|
||
this.onInjectionVaccineCb(this.injectionVaccine); | ||
} | ||
if (change.dateMaxSearch) { | ||
this.dateMaxSearch = change.dateMaxSearch.newValue; | ||
|
||
this.onDateMaxSearchCb(this.dateMaxSearch); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,20 @@ | |
if (currentMonth > selectedMonth) return new Date().getFullYear() + 1; | ||
return new Date().getFullYear(); | ||
} | ||
const MONTHS = { | ||
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. Ce code n'est plus utilisé il me semble :) |
||
'janv.': 1, | ||
'févr.': 2, | ||
'mars': 3, | ||
'avr.': 4, | ||
'mai': 5, | ||
'juin': 6, | ||
'juil.': 7, | ||
'aout': 8, | ||
'sept.': 9, | ||
'oct.': 10, | ||
'nov.': 11, | ||
'déc.': 12, | ||
}; | ||
|
||
async function waitTimeout(timeout) { | ||
await new Promise((r) => setTimeout(r, timeout)); | ||
|
@@ -295,15 +309,18 @@ | |
|
||
let running = false; | ||
async function checkAvailability() { | ||
const { locations, stopped, autoBook, injectionType, injectionVaccine } = | ||
const { locations, stopped, autoBook, injectionType, injectionVaccine, dateMaxSearch } = | ||
await browser.storage.sync.get({ | ||
locations: {}, | ||
stopped: false, | ||
autoBook: false, | ||
injectionType: "fullServiceInjection", | ||
injectionVaccine: "pfizerInjection", | ||
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()), | ||
}); | ||
|
||
const dateMaxSearchDate = typeof(dateMaxSearch) === 'string' ? new Date(dateMaxSearch) : dateMaxSearch; | ||
|
||
if (stopped || !locations[url]) { | ||
running = false; | ||
return; | ||
|
@@ -421,6 +438,8 @@ | |
const parts = slot.title.match( | ||
/([0-9]+)\.? ([\p{Letter}]+)\.? ([0-9]+:[0-9]+)/u | ||
); | ||
// /([0-9]+) [\p{Letter}]+\.? ([0-9]+:[0-9]+)/gu | ||
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. Il y a t'il une raison pour laisser ce code commenté dans le source ou c'est juste un petit oubli? :) 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. Juste un oubli :) |
||
// )[0].split(' '); | ||
if (!parts) { | ||
throw new Error( | ||
browser.i18n.getMessage("slotDateFormatNotFound", slot.title) | ||
|
@@ -434,18 +453,14 @@ | |
const selectedTime = parts[3]; | ||
|
||
const date = new Date( | ||
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}` | ||
); | ||
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`); | ||
|
||
const tomorrow = new Date(); | ||
tomorrow.setHours(23); | ||
tomorrow.setMinutes(59); | ||
tomorrow.setDate(tomorrow.getDate() + 1); | ||
|
||
if (date > tomorrow && date < new Date("2021-05-31T00:20:00")) | ||
if (date > dateMaxSearchDate) { | ||
const formatedDate = dateMaxSearchDate.toLocaleDateString(); | ||
throw new Error( | ||
"Pas de créneau dispo d'ici demain soir ou après le 31 mai" | ||
`Pas de créneau dispo d'ici demain soir ou avant le ${formatedDate}` | ||
); | ||
} | ||
|
||
if (!autoBook) { | ||
browser.runtime.sendMessage({ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ici l'intégration du i18n manque
dateMaxLabel
doit ensuite être défini dans_locales/*/messages.json
.Je suggère comme traduction allemande:
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.
Rajouté ! Merci pour la trad :)