Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

feat: add max date for appointment #86

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"message": "Auffrischimpfung",
"description": "Text der alle Auffrischimpfungen beschreibt."
},
"maxDateLabel": {
"message": "Termin finden bis zum (DD. MM. YYYY)",
"description": "Bis zu diesem Datum wird nach einem Termin gesucht"
},
"modernaVaccine": {
"message": "Moderna Impfstoff",
"description": "Beschreibung des Moderna Impfstoffes."
Expand Down
4 changes: 4 additions & 0 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"message": "Troisième dose",
"description": "Text qui décrit une injection de rappel au dela de la deuxième dose."
},
" maxDateLabel": {
"message": "Date maximale de recherche (MM/DD/YYYY)",
"description": "Date jusqu'à laquelle un rdv sera cherché"
},
"modernaVaccine": {
"message": "Vaccin Moderna",
"description": "Text qui décrit un vaccin Moderna."
Expand Down
11 changes: 11 additions & 0 deletions browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="date" name="dateMaxSearch" id="dateMax" />
<label for="dateMax" data-i18n="dateMaxLabel"
>Date maximale de recherche (MM/JJ/YYYY)</label
>
</div>
</div>

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="radio" name="autoBook" id="disableAutoBook" checked />
Expand Down
12 changes: 12 additions & 0 deletions browser_action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
document.getElementById(injectionVaccine).checked = true;
}

/** @param {Date} dateMaxSearch La date maximale de recherche de rdv */
function displayDateMaxSearch(dateMaxSearch) {
const date = new Date(dateMaxSearch);
document.getElementById("dateMax").value = date.toISOString().split("T")[0];
}

// Preparation des données
const appStatus = new AppStatus();
const vCLStorage = new VCLocalStorage({
Expand All @@ -118,6 +124,7 @@
appStatus.onAutoBookChange(displayAutoBook);
appStatus.onInjectionTypeChange(displayInjectionType);
appStatus.onInjectionVaccineChange(displayInjectionVaccine);
appStatus.onDateMaxSearchChange(displayDateMaxSearch);

// Initialisation donnée
appStatus.init();
Expand Down Expand Up @@ -150,6 +157,10 @@
appStatus.setInjectionVaccine.bind(appStatus, "modernaInjection");
document.getElementById("pfizerInjection").onclick =
appStatus.setInjectionVaccine.bind(appStatus, "pfizerInjection");
document.getElementById("dateMax").onblur = appStatus.setDateMaxSearch.bind(
appStatus,
document.getElementById("dateMax")
);

document.getElementById("reset").onclick = () => {
if (
Expand All @@ -169,5 +180,6 @@
displayAutoBook(appStatus.getAutoBook());
displayInjectionType(appStatus.getInjectionType());
displayInjectionVaccine(appStatus.getInjectionVaccine());
displayDateMaxSearch(appStatus.getDateMaxSearch());
displayLocations();
})();
47 changes: 47 additions & 0 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ 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 */
Expand All @@ -34,6 +40,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);
Expand All @@ -49,6 +57,11 @@ 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) => {
Expand All @@ -67,6 +80,9 @@ class AppStatus {

this.injectionVaccine = result.injectionVaccine;
this.onInjectionVaccineCb(this.injectionVaccine);

this.dateMaxSearch = result.dateMaxSearch;
this.onDateMaxSearchCb(this.dateMaxSearch);
}

getLocations() {
Expand Down Expand Up @@ -105,6 +121,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
Expand Down Expand Up @@ -142,6 +162,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 });
Expand All @@ -168,6 +195,14 @@ 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
*/
Expand All @@ -193,6 +228,12 @@ class AppStatus {
this.onInjectionTypeCb(this.injectionType);
this.injectionVaccine = "pfizerInjection";
this.onInjectionTypeCb(this.injectionVaccine);
this.dateMaxSearch = new Date(
new Date().getFullYear() + 1,
new Date().getMonth(),
new Date().getDate()
);
this.onDateMaxSearchCb(this.dateMaxSearch);
}

/**
Expand All @@ -209,6 +250,7 @@ class AppStatus {
this.onAutoBookChangeCb = null;
this.onInjectionTypeCb = null;
this.onInjectionVaccineCb = null;
this.onDateMaxSearchCb = null;
}

/**
Expand Down Expand Up @@ -262,5 +304,10 @@ class AppStatus {

this.onInjectionVaccineCb(this.injectionVaccine);
}
if (change.dateMaxSearch) {
this.dateMaxSearch = change.dateMaxSearch.newValue;

this.onDateMaxSearchCb(this.dateMaxSearch);
}
}
}
43 changes: 28 additions & 15 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,30 @@

let running = false;
async function checkAvailability() {
const { locations, stopped, autoBook, injectionType, injectionVaccine } =
await browser.storage.sync.get({
locations: {},
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
});
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;
Expand Down Expand Up @@ -437,15 +453,12 @@
`${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({
Expand Down