Skip to content

Commit

Permalink
mobile phone close modals on back button
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanistHere committed Jul 16, 2021
1 parent 6ca709d commit a20fce5
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion back-end/controllers/geo.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ exports.geo_add = async (req, res, next) => {
type: "Point" ,
coordinates: [ ...body.location.coordinates ]
},
$maxDistance: 700
$maxDistance: 400
}
}
})
Expand Down
7 changes: 4 additions & 3 deletions back-end/routes/user.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const rateLimit = require("express-rate-limit");

const user_controller = require('../controllers/user.controller');

const dev_db_url = `${process.env.MONGODB_URI}`;
const dev_db_url = process.env.DEV_DB_PATH;
const mongoDB = process.env.MONGODB_URI || dev_db_url;

const mediumLimiter = rateLimit({
store: new MongoLimitStore({
uri: dev_db_url,
uri: mongoDB,
expireTimeMs: 20 * 60 * 1000,
collectionName: 'expressRateUser',
errorHandler: console.error.bind(null, 'rate-limit-mongo')
Expand All @@ -23,7 +24,7 @@ const mediumLimiter = rateLimit({

const hardLimiter = rateLimit({
store: new MongoLimitStore({
uri: dev_db_url,
uri: mongoDB,
expireTimeMs: 20 * 60 * 1000,
collectionName: 'expressRateUser',
errorHandler: console.error.bind(null, 'rate-limit-mongo')
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<script defer src="js/login.js"></script>
<script defer src="js/sidebar.js"></script>
<script defer src="js/quiz.js"></script>
<script defer src="js/afterLoad.js"></script>

<script defer data-domain="measureland.org" src="https://plausible.io/js/plausible.js"></script>

Expand Down
8 changes: 8 additions & 0 deletions js/afterLoad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
window.addEventListener('popstate', () => {
hideAllSides()

const url = new URL(window.location.href)
url.searchParams.delete('showRating')
url.searchParams.delete('openModal')
window.history.replaceState(null, null, url)
})
4 changes: 4 additions & 0 deletions js/critical.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ const checkIsLaunchFirst = () => {
state.flow.push('ftv')
positionStartScreen()
}

const url = new URL(window.location.href)
url.searchParams.delete('openModal')
window.history.replaceState(null, null, url)
}

checkIsLaunchFirst()
7 changes: 7 additions & 0 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,10 @@ const showError = (key, error = null) => {
console.warn(error)
return alert(message)
}

const addToUrlOpenModalFlag = () => {
const url = new URL(window.location.href)
url.searchParams.set('openModal', true)

window.history.pushState(null, null, url)
}
17 changes: 9 additions & 8 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const initQuizPopup = (latlng) => {
$('.ratingPopup1').focus()

state = { ...state, corrdsToSave: [roundToFifthDecimal(latlng.lat), roundToFifthDecimal(latlng.lng)] }
addToUrlOpenModalFlag()
}

const onMapClick = e => {
Expand Down Expand Up @@ -132,14 +133,14 @@ const initMap = () => {

const { map, geocoder } = initMap()

if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker
.register("/service-worker.js")
.then()
.catch(err => console.warn("service worker not registered", err))
})
}
// if ("serviceWorker" in navigator) {
// window.addEventListener("load", function() {
// navigator.serviceWorker
// .register("/service-worker.js")
// .then()
// .catch(err => console.warn("service worker not registered", err))
// })
// }

// document.addEventListener('visibilitychange', () => {
// if (document.visibilityState === 'hidden') {
Expand Down
1 change: 1 addition & 0 deletions js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const changeLoginScreen = (stage = 'login') => {
const openLoginForm = stage => {
changeLoginScreen(stage)
addClass(loginForm, 'rating-active')
addToUrlOpenModalFlag()
}

const closeLoginForm = () => {
Expand Down
1 change: 1 addition & 0 deletions js/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const initPlaces = async () => {
})
}

addToUrlOpenModalFlag()
hideSpinner('.places__spinner')
}

Expand Down
1 change: 1 addition & 0 deletions js/showRatings.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const initRatingPopup = async ({ latlng }) => {
addClass($('.rate__rated_btn'), 'btn-hide')
}

addToUrlOpenModalFlag()
hideSpinner('.rate__spinner')
}

Expand Down
1 change: 1 addition & 0 deletions js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const openSideBar = (className = 'settings') => {

addClass(document.body, 'sidebar-open')
state.flow.push('os')
addToUrlOpenModalFlag()
}

const closeSideBar = () => {
Expand Down
1 change: 1 addition & 0 deletions ru/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<script defer src="../js/login.js"></script>
<script defer src="../js/sidebar.js"></script>
<script defer src="../js/quiz.js"></script>
<script defer src="../js/afterLoad.js"></script>

<script defer data-domain="measureland.org" src="https://plausible.io/js/plausible.js"></script>

Expand Down

0 comments on commit a20fce5

Please sign in to comment.