push notification fixed

This commit is contained in:
2019-11-04 16:36:20 +01:00
parent 5e7fabe1ce
commit 6612f91047
5 changed files with 86 additions and 86 deletions
+1 -1
View File
@@ -14,5 +14,5 @@ RUN apk add --no-cache bash
RUN apk add --no-cache yarn
CMD cd /home/app/nextjs && yarn cache dir && yarn cache clean && yarn build && pm2 startOrReload ecosystem.config.js --env production --no-daemon
CMD cd /home/app/nextjs && yarn cache dir && yarn cache clean && yarn install && yarn build && pm2 startOrReload ecosystem.config.js --env production --no-daemon
+79 -81
View File
@@ -35,7 +35,7 @@ class WebPush extends Component {
constructor(props) {
super(props)
}
}
componentDidMount() {
if (swRegistration === null) {
@@ -44,12 +44,12 @@ class WebPush extends Component {
}
UNSAFE_componentWillReceiveProps(nextProps) {
console.log("isUserSubscribedToPush ::: " + nextProps.isUserSubscribedToPush);
if (this.props.subscriveUserEnabled != nextProps.subscriveUserEnabled && nextProps.subscriveUserEnabled) {
this.onSubscribeUser()
}
if(!!nextProps.isUserSubscribedToPush){
this.setState({on: true})
if (!!nextProps.isUserSubscribedToPush) {
this.setState({ on: true })
}
}
@@ -80,99 +80,97 @@ class WebPush extends Component {
}
}
onSubscribeUser = () => {
if (swRegistration == null) {
return
onSubscribeUser = () => {
if (swRegistration == null) {
return
}
swRegistration.pushManager.getSubscription()
.then((subscription) => {
var isSubscribed = !(subscription === null)
if (isSubscribed) {
this.onUpdateSubscriptionOnServer(subscription)
} else {
const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey)
swRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
.then((subscription) => {
console.log('User is subscribed.')
if (this.onUpdateSubscriptionOnServer) {
this.onUpdateSubscriptionOnServer(subscription)
}
})
.catch((err) => {
console.log('Failed to subscribe the user: ', err)
if (onSubscribeFailed) {
this.onSubscriptionFailed(err)
}
});
}
})
}
swRegistration.pushManager.getSubscription()
.then((subscription) => {
var isSubscribed = !(subscription === null)
if (isSubscribed) {
this.onUpdateSubscriptionOnServer(subscription)
} else {
const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey)
swRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
.then((subscription) => {
console.log('User is subscribed.')
if (this.onUpdateSubscriptionOnServer) {
this.onUpdateSubscriptionOnServer(subscription)
}
})
.catch((err) => {
console.log('Failed to subscribe the user: ', err)
if (onSubscribeFailed) {
this.onSubscriptionFailed(err)
}
});
}
})
}
onUnSubscribeUser = () => {
swRegistration.pushManager.getSubscription()
onUnSubscribeUser = () => {
swRegistration.pushManager.getSubscription()
.then((subscription) => {
if (subscription) {
.then((subscription) => {
if (subscription) {
return subscription.unsubscribe();
}
})
.then(() =>
this.setState(({ on }) => ({ on: false })))
//TODO: facultatif update DB
// .then(() => {
// return fetch(//, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(subscription)
// })
// .then((response) => {
// if (!response.ok) {
// throw new Error('Bad status code from server.');
// }
// ///TODO bind UI
// return true;
// })
return subscription.unsubscribe();
}
})
.then(() =>
this.setState(({ on }) => ({ on: false })))
//TODO: facultatif update DB
// .then(() => {
// return fetch(//, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(subscription)
// })
// .then((response) => {
// if (!response.ok) {
// throw new Error('Bad status code from server.');
// }
// ///TODO bind UI
// return true;
// })
// })
.catch((err) => {
console.error('Failed to unsubscribe the user.', err);
// })
.catch((err) => {
console.error('Failed to unsubscribe the user.', err);
});
}
});
}
onRegisterServiceWorker = () => {
navigator.serviceWorker.register('/static/js/Edeclic-service-worker.js')
.then(function (swReg) {
console.info('Service Worker is registered', swReg);
onRegisterServiceWorker = () => {
navigator.serviceWorker.register('/static/js/Edeclic-service-worker.js')
.then(function (swReg) {
console.info('Service Worker is registered', swReg);
swRegistration = swReg;
})
}
swRegistration = swReg;
})
}
render() {
return (<WebPushContext.Provider
value={{ on: this.state.on, toggleSubscription: this.toggleSubscription }}
{...this.props}
/>)
}
render() {
return (<WebPushContext.Provider
value={{ on: this.state.on, toggleSubscription: this.toggleSubscription }}
{...this.props}
/>)
}
}
WebPush.propTypes = {
}
function mapStateToProps(state) {
return {
isUserSubscribedToPush: state.isUserSubscribedToPush
};
isUserSubscribedToPush: state.user.isUserSubscribedToPush
};
}
export default connect(mapStateToProps, { subscribeUserToPushRequest })(WebPush);
+2 -2
View File
@@ -8,7 +8,7 @@
<lastmod>2019-09-17</lastmod>
</url>,<url>
<loc>https://app.talentstube.com/Confidentialite</loc>
<lastmod>2019-10-18</lastmod>
<lastmod>2019-11-04</lastmod>
</url>,<url>
<loc>https://app.talentstube.com/Entreprises</loc>
<lastmod>2019-09-17</lastmod>
@@ -20,7 +20,7 @@
<lastmod>2019-10-14</lastmod>
</url>,<url>
<loc>https://app.talentstube.com/MentionsLegales</loc>
<lastmod>2019-10-18</lastmod>
<lastmod>2019-11-04</lastmod>
</url>,<url>
<loc>https://app.talentstube.com/Offres</loc>
<lastmod>2019-10-16</lastmod>
+1
View File
@@ -69,6 +69,7 @@
"dev": "cross-env PORT=3000 node server.js",
"build": "next build && yarn postExport && yarn copysw && yarn copySiteMap",
"start": "cross-env PORT=8000 NODE_ENV=production node server.js",
"startPreprod": "cross-env PORT=8000 NODE_ENV=preproduction node server.js",
"pm2-prod": "yarn build && pm2 start --name 'next' -- start",
"bs": "yarn build && yarn start",
"test": "yarn cypress run",
+3 -2
View File
@@ -181,19 +181,20 @@ export function user(state = {
return {
...state,
loading: false,
pushSubscribed: true
isUserSubscribedToPush: true
}
case SUBSCRIBE_USER_TO_PUSH_FAILURE:
return {
...state,
loading: false,
pushSubscribed: false,
isUserSubscribedToPush: false,
errors: action.err,
}
case FETCH_USER_SUBSCRIPTION_TO_PUSH_REQUEST:
return {
...state,
loading: true,
isUserSubscribedToPush: false,
}
case FETCH_USER_SUBSCRIPTION_TO_PUSH_SUCCESS:
return {