ducky/web
14:275a83e4c02e
Go to Latest
ducky/web/src/components/validation-error.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.
1 import React from 'react'
3 export default React.createClass({
4 displayName: 'ValidationError',
7 let fields = this.props.fields
8 if (this.props.field && !this.props.fields) {
9 fields = [this.props.field]
11 let notFields = this.props.notFields
12 if (this.props.notField && !this.props.notFields) {
13 notFields = [this.props.notField]
15 let params = this.props.params
16 if (this.props.param && !this.props.params) {
17 params = [this.props.param]
19 let notParams = this.props.notParams
20 if (this.props.notParam && !this.props.notParams) {
21 notParams = [this.props.notParam]
23 let headers = this.props.headers
24 if (this.props.header && !this.props.headers) {
25 headers = [this.props.header]
27 let notHeaders = this.props.notHeaders
28 if (this.props.notHeader && !this.props.notHeaders) {
29 notHeaders = [this.props.notHeader]
31 const outputs = this.props.outputs
32 const errors = this.props.errors
35 <div className={errors.length ? '' : 'hidden' }>
36 {errors.map(error => {
38 if (!error.field && !notFields && !error.param && !notParams && !error.header && !notHeaders) {
41 if (fields && error.field && fields.indexOf(error.field) < 0) {
44 if (notFields && error.field && notFields.indexOf(error.field) >= 0) {
47 if (params && error.param && params.indexOf(error.param) < 0) {
50 if (notParams && error.param && notParams.indexOf(error.param) >= 0) {
53 if (headers && error.header && headers.indexOf(error.header) < 0) {
56 if (notHeaders && error.header && notHeaders.indexOf(error.header) >= 0) {
59 if (outputs[error.error] == undefined) {
60 errorString = 'An unknown error occurred. Please contact support. Sorry.'
62 errorString = outputs[error.error]
64 const id = [error.field, error.param, error.header, error.error].join("|")
65 return <div key={id} className="flash-error validation"><span>{errorString}</span></div>