Skip to content

Commit

Permalink
Fix #30 refresh pages when all resuls are hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamara Robichet committed Jul 10, 2018
1 parent 707c5c7 commit 5e49045
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 453 deletions.
3 changes: 3 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ services:
frontend:
ports:
- 8080:8080
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:9-slim as npm
WORKDIR /usr/src/app
ENV PATH=node_modules/.bin:$PATH
COPY frontend/package*.json ./
COPY frontend/package.json ./
RUN npm install
COPY frontend .
184 changes: 0 additions & 184 deletions frontend/package-lock.json

This file was deleted.

33 changes: 29 additions & 4 deletions frontend/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@ const data = {
}

function getResults() {
const params = new URLSearchParams(location.search)
const page = params.get('page') || 1
const page = getPage()

return fetch(new Request(`http://localhost:3000/results?page=${page}`), {
mode: 'cors',
method: 'get'
}).then(response => response.json())
}

function hideResult() {
return fetch(new Request(`http://localhost:3000/results/${this.dataset.id}/hide`), {
const id = this.dataset.id

return fetch(new Request(`http://localhost:3000/results/${id}/hide`), {
mode: 'cors',
method: 'post'
}).then(() => this.parentNode.parentNode.removeChild(this.parentNode))
})
.then(() => {
const matchingResult = data.results.filter(result => result._id === id)[0]
matchingResult.hidden = true
this.parentNode.parentNode.removeChild(this.parentNode)
})
.then(() => {
const displayedResults = data.results.filter(result => !result.hidden)
if (displayedResults.length === 0) {
setPage(Math.max(1, getPage() - 1))
window.location.reload()
}
})
}

function getPage() {
const params = new URLSearchParams(location.search)
return params.get('page') || 1
}

function setPage(pageNumber) {
const searchParams = new URLSearchParams(window.location.search);
searchParams.set('page', pageNumber);
window.location.search = searchParams.toString();
}

function renderList() {
Expand Down
3 changes: 0 additions & 3 deletions package-lock.json

This file was deleted.

Loading

0 comments on commit 5e49045

Please sign in to comment.