import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import autobind from 'autobind-decorator'; import {Cookie} from 'tough-cookie'; import PromptButton from '../base/prompt-button'; import CookieInput from '../cookie-input'; import {cookieToString} from '../../../common/cookies'; import {DEBOUNCE_MILLIS} from '../../../common/constants'; @autobind class CookiesEditor extends PureComponent { _handleCookieAdd () { const newCookie = new Cookie({ key: 'foo', value: 'bar', domain: this.props.newCookieDomainName, path: '/' }); this.props.onCookieAdd(newCookie); } _handleCookieUpdate (cookie, cookieStr) { clearTimeout(this._cookieUpdateTimeout); this._cookieUpdateTimeout = setTimeout(() => { const newCookie = Cookie.parse(cookieStr); this.props.onCookieUpdate(cookie, newCookie); }, DEBOUNCE_MILLIS * 2); } _handleDeleteCookie (cookie) { this.props.onCookieDelete(cookie); } shouldComponentUpdate (nextProps, nextState) { return nextProps.cookies !== this.props.cookies; } render () { const {cookies} = this.props; return (
{cookies.map((cookie, i) => { const cookieString = cookieToString(Cookie.fromJSON(JSON.stringify(cookie))); return ( ); })}
Domain Cookie
{cookie.domain}
this._handleCookieUpdate(cookie, value)} />
this._handleDeleteCookie(cookie)} title="Delete cookie">
{cookies.length === 0 && (

I couldn't find any cookies for you.

)}
); } } CookiesEditor.propTypes = { onCookieUpdate: PropTypes.func.isRequired, onCookieAdd: PropTypes.func.isRequired, onCookieDelete: PropTypes.func.isRequired, cookies: PropTypes.array.isRequired, newCookieDomainName: PropTypes.string.isRequired }; export default CookiesEditor;