ducky/web

Paddy 2015-06-30 Parent:99a43a6d1d30

14:275a83e4c02e Go to Latest

ducky/web/src/pages/onboard.jsx

Persist session data to localStorage. Create a helper library that figures out whether to write to chrome.storage.local or window.localStorage, and unifies their two APIs. Update the Me model to use the getOrFetch method for the profiles collection when retrieving the user's profile. This, unfortunately, makes it an async call (because we may need to fetch data from the server), so we can no longer have it be a derived property, which is a shame. It instead must just be the me.profile() function. Separate out the logic to determine when an access token expires, and turn it into the tokenExpires function. Fill the writeToCache placeholder with the logic to store the current session in either window.localStorage or chrome.storage.local, whichever is the more appropriate, using the helper library. Create the load helper function that will attempt to read session data from localStorage or chrome.storage.local, whichever the library decides is available, and updates the session based on it. Implement the logout function, which just uses the helper library to remove the session data from window.localStorage or chrome.storage.local. We should also be resetting the app.me variable, however. Create a debouncedWriteToCache function that will only write to the cache once every 250 ms, to avoid rushes on the cache. When instantiating our app.me variable, load it in from localStorage or chrome.storage.local if we can. Also, listen for changes to app.me, and persist them to chrome.storage.local or localStorage.

History
paddy@0 1 import app from 'ampersand-app'
paddy@0 2 import React from 'react'
paddy@0 3 import localLinks from 'local-links'
paddy@0 4 import HeroUnit from '../components/hero'
paddy@0 5 import onboardStyles from '../styles/onboarding.scss'
paddy@0 6
paddy@0 7 export default React.createClass({
paddy@0 8 displayName: 'OnboardingPage',
paddy@0 9
paddy@0 10 onLoginClick (event) {
paddy@0 11 event.preventDefault()
paddy@0 12 app.router.navigate('/login')
paddy@0 13 },
paddy@0 14
paddy@0 15 onRegisterClick (event) {
paddy@0 16 event.preventDefault()
paddy@0 17 app.router.navigate('/register')
paddy@0 18 },
paddy@0 19
paddy@0 20 render () {
paddy@0 21 return (
paddy@0 22 <div className='container'>
paddy@0 23 <HeroUnit title='Welcome to Ducky' settings='true'>Let’s get our ducks in a row.</HeroUnit>
paddy@0 24 <article className='onboarding'>
paddy@0 25 <p>We’re just as excited as you are, but we need some more information before we can do anything. Don’t worry, this won’t take long</p>
paddy@0 26 <p>First of all, who <em>are</em> you? If you have a Ducky account already, we need you to sign in. If you don’t have one, don’t sweat it. Click that fancy “Register” button below.</p>
paddy@0 27 <div className='actionbuttons'>
paddy@0 28 <button onClick={this.onLoginClick}>Sign in</button>
paddy@0 29 <button onClick={this.onRegisterClick}>Register</button>
paddy@0 30 </div>
paddy@0 31 </article>
paddy@0 32 </div>
paddy@0 33 )
paddy@0 34 }
paddy@0 35 })