Tweet |
Taking a Moment with a Lightning Component
Looking after yourself
A huge amount of effort nowadays goes in to making people more productive. New AI features on the Salesforce platform figure out the key leads and deals so that reps focus on the right tasks, more information is pushed to employees to help their decision making, and barely 10 minutes goes by without a new listicle being published on Medium promising to teach you life hacks so that you can spend more of your time carrying out that sweet, sweet work. It’s easy to forget that you are more productive if you look after yourself while working. Sitting down staring at a screen for hours on end can cause you real damage, but as it’s not an instant, acute pain more often than not you don’t realise it. This is where the systems that you work with should be helping you, rather than trying to squeeze more out of you.
TakeAMoment (Lighting Component)
When you create a Lightning application in Salesforce, you can add a utility bar. Lightning components in this utility bar have special powers - they persist across the various tabs and pages of the application, unaffected by your navigation. Using the “Load in background when the app opens” setting means that the component can know the point at which you started the application and can make some helpful suggestions after specific periods of time have elapsed.
The TakeAMoment lightning component starts a JavaScript interval timer upon initialisation that fires every minute. When the timer fires, the component then figures out how long it’s been since the user started the application and, if it is a specific amount of time, suggests that the user take a moment to do something to benefit themselves. For example, after 20 minutes the user is advised to blink 10 times to ensure they don’t dry their eyes out. Here’s a video of the component doing it’s thing - note that in time honoured fashion for anything tech related, the sequence has been shortened:
(The ‘Come with me if you want to live’ initial message is because I had The Terminator on in the background while I wrote the component - I thnk it grabs the user’s attention!).
Note that I’m using the variant of the toast message that allows me to include a clickable URL - each suggested activity contains a link to a page on the web explaining why it’s a good idea - at the end of the video I click through to the story in the New York Times that explains why getting up and walking around for 5 minutes every hour is a good thing.
The you can view the component at the github repo shown below - it’s pretty basic at the moment, the timings and messages are all hardcoded, but this has the advantage that there’s no interaction with the server - everything takes place on the client. If you want to use it, create or edit a lightning app (I just added the utility bar component to the standard Sales app) and add the TakeAMoment component to the utility bar. Make sure to check the ‘Load in the background when the app opens’, otherwise the user has to click the component in the utility bar to initialise it.
Obviously as well as looking after my users, this component can also be used for nefarious purposes, typically by my evil co-worker - regular messages telling users they aren’t working hard enough, that winners work through lunch, family dinners are overrated etc. Sadly this is the nature of most if not all technology.
Related Posts
- Github repository
- Build an Instant Notification App - the Trailhead project that got me thinking about some of the other uses of notifications from utility bar components.
- Lightning experience utility bar - add an app for that