Skip to content

Commit

Permalink
Bugfix: rich notifications config.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomeandrey committed May 15, 2019
1 parent dd56ccb commit bdfbf1c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import AppContext from "../../../../../../../../../model/services/context/AppContext";
import ApplicationEvents from "../../../../../../../../../model/application-events";
import Spinner from "@salesforce/design-system-react/module/components/spinner";
import Input from "@salesforce/design-system-react/module/components/input";
Expand Down Expand Up @@ -54,30 +53,27 @@ class ProfileInfo extends React.Component {
};

render() {
const {user} = this.props, {loading, name} = this.state;
const {user} = this.props, {loading, name} = this.state,
richNotificationsEnabled = LocalStorage.getItem(LocalEntities.RICH_NOTIFICATIONS);
return (
<AppContext.Consumer>
{context => (
<div className="slds-form--stacked slds-p-horizontal--small">
<MaskedInput label="Name" placeholder="Enter your name"
iconRight={<InputIcon name="user" category="utility"/>}
disabled={loading} required
value={name} pattern={InputPatterns.NAME}
onChange={name => this.setState({name})}
onBlur={this.handleChangeName}/>
<Input label="Username" disabled
value={Utility.decorateUsername(user.username)}
iconRight={<InputIcon name="fallback" category="utility"/>}/>
{serviceWorkerAllowed && <Checkbox label="Rich notifications"
className="slds-m-top_small"
defaultChecked={context.richNotificationsEnabled}
onChange={this.handleChangeNotifications}/>}
{loading && <div className="slds-float_left slds-is-relative slds-p-vertical--large slds-p-left_large">
<Spinner variant="brand" size="small"/>
</div>}
</div>
)}
</AppContext.Consumer>
<div className="slds-form--stacked slds-p-horizontal--small">
<MaskedInput label="Name" placeholder="Enter your name"
iconRight={<InputIcon name="user" category="utility"/>}
disabled={loading} required
value={name} pattern={InputPatterns.NAME}
onChange={name => this.setState({name})}
onBlur={this.handleChangeName}/>
<Input label="Username" disabled
value={Utility.decorateUsername(user.username)}
iconRight={<InputIcon name="fallback" category="utility"/>}/>
{serviceWorkerAllowed && <Checkbox label="Rich notifications"
className="slds-m-top_small"
defaultChecked={richNotificationsEnabled}
onChange={this.handleChangeNotifications}/>}
{loading && <div className="slds-float_left slds-is-relative slds-p-vertical--large slds-p-left_large">
<Spinner variant="brand" size="small"/>
</div>}
</div>
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/model/api/streaming/services/ServiceWorkerRegistrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {CustomEvents} from "../../../services/utility/EventsService";
import {PUBLIC_VAPID_KEY} from "../../../constants";
import {Utility} from "../../../services/utility/UtilityService";
import {getToken} from "../../rest/secureApi";
import {LocalEntities, LocalStorage} from "../../../services/utility/StorageService";

const _serviceWorkerUrlPath = "service-worker.js"
, _urlBase64ToUint8Array = (base64String) => {
Expand Down Expand Up @@ -50,6 +51,8 @@ export const registerServiceWorker = _ => {
return Notification.requestPermission();
}).then(result => {
console.log(`Notifications permission - ${result}.`);
const richNotificationsEnabled = LocalStorage.getItem(LocalEntities.RICH_NOTIFICATIONS);
postMessageToServiceWorker({richNotificationsEnabled});
}).catch(error => {
console.error("Error when registering service worker.", error);
});
Expand Down
5 changes: 0 additions & 5 deletions src/model/services/context/AppContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {subscribeFromClient} from "../../api/streaming/services/TopicsManager";
import {UserService} from "../core/UserService";
import {CustomEvents} from "../utility/EventsService";
import {serviceWorkerAllowed, postMessageToServiceWorker} from "../../api/streaming/services/ServiceWorkerRegistrator";
import {LocalEntities, LocalStorage} from "../utility/StorageService";

class AppContextProvider extends Component {
constructor(props) {
super(props);
this.state = {
user: null,
richNotificationsEnabled: LocalStorage.getItem(LocalEntities.RICH_NOTIFICATIONS),
indicatorsMap: new Map()
};
}
Expand All @@ -39,9 +37,6 @@ class AppContextProvider extends Component {
* Intended for browsers which do not support service workers and mobile devices.
*/
subscribeFromClient();
} else {
const {richNotificationsEnabled} = this.state;
postMessageToServiceWorker({richNotificationsEnabled});
}
this.loadUser();
}
Expand Down

0 comments on commit bdfbf1c

Please sign in to comment.