Skip to content

Commit

Permalink
feat: add feedback after click on try button
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Mar 11, 2024
1 parent 2885c42 commit 1d7520a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [ ] UX - Modale de fin - Ajouter le chemin le plus court et le chemin du joueur
- [ ] UX - Ajouter les stations du joueur en dessous de la carte
- [ ] UX - Pouvoir activer/désactiver des stations
- [ ] UX - Search Input - Retirer les stations déjà ajoutées
- [x] UX - Search Input - Retirer les stations déjà ajoutées
- [x] UX - Search Input - Ajouter un feedback si la station n'existe pas
- [ ] UX - Afficher les lignes de métro dans la bonne couleur
- [x] Script - Merge-duplicate-station - Ne pas prendre compte les accents dans les noms
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,19 @@ <h1>Métro travel</h1>
<p id="instruction"></p>
<svg id="carte"></svg>
<div class="dropdown">
<label for="station" class="form-label">Nom d'une station</label>
<input
id="station"
class="form-control"
type="text"
placeholder="Rechercher une station à ajouter"
data-bs-toggle="dropdown"
aria-expanded="false"
aria-describedby="station-validation"
/>
<div id="station-validation" class="invalid-feedback">
Le nom de station doit être valide.
</div>
<ul id="stations" class="dropdown-menu"></ul>
</div>
<button id="try" class="btn btn-primary">Essayer</button>
Expand Down
14 changes: 10 additions & 4 deletions src/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import linesData from '../assets/lines.geojson';
import { ParisMap } from './map.js';
import { getSeededRandomStations, pickStations } from './pick-stations.js';
import { verifyIfConnected } from './graph.js';
import { searchStations } from './utils.front.js';
import { searchStations, stationExists } from './utils.front.js';

const stations = stationsData.features.filter((s) => {
return s.properties.adjacentStations && s.properties.name;
Expand All @@ -25,6 +25,7 @@ function createEventsForStationsList() {
handleDropDownVisibility(input, dropdown);
});
input.addEventListener('input', () => {
input.classList.remove('is-invalid');
handleDropDownVisibility(input, dropdown);
});
}
Expand Down Expand Up @@ -97,9 +98,14 @@ function handleClickOnTryButton({ pick }) {
document.getElementById('try').addEventListener('click', () => {
const input = document.getElementById('station');
const stationName = input.value;
addStation({ stationName });
input.value = '';
isFinished({ addedStations, pick });
if (stationExists(stations, stationName)) {
addStation({ stationName });
input.value = '';
isFinished({ addedStations, pick });
}
else {
input.classList.add('is-invalid');
}
});
}
function isFinished({ addedStations, pick }) {
Expand Down
7 changes: 7 additions & 0 deletions src/utils.front.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ function searchStations(search, stations) {
});
}

function stationExists(stations, stationName) {
return stations.some((station) => {
return station.properties.name === stationName;
});
}

export {
searchStations,
stationExists,
};
7 changes: 0 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ function getStations() {
});
}

function stationExists(stations, stationName) {
return stations.some((station) => {
return station.properties.name === stationName;
});
}

export {
getStations,
stationExists,
};

0 comments on commit 1d7520a

Please sign in to comment.