import React, { PureComponent } from 'react'; import * as uuid from 'uuid'; import * as toughCookie from 'tough-cookie'; import { autoBindMethodsForReact } from 'class-autobind-decorator'; import { cookieToString } from 'insomnia-cookies'; import PromptButton from './base/prompt-button'; import RenderedText from './rendered-text'; import type { Cookie } from '../../models/cookie-jar'; import { Dropdown, DropdownButton, DropdownItem } from './base/dropdown/index'; import { AUTOBIND_CFG } from '../../common/constants'; import { HandleRender } from '../../common/render'; export interface CookieListProps { handleCookieAdd: Function; handleCookieDelete: Function; handleDeleteAll: Function; cookies: Cookie[]; newCookieDomainName: string; handleShowModifyCookieModal: (cookie: Cookie) => void; handleRender: HandleRender; } // Use tough-cookie MAX_DATE value // https://github.com/salesforce/tough-cookie/blob/5ae97c6a28122f3fb309adcd8428274d9b2bd795/lib/cookie.js#L77 const MAX_TIME = 2147483647000; @autoBindMethodsForReact(AUTOBIND_CFG) class CookieList extends PureComponent { _handleCookieAdd() { const newCookie: Cookie = { id: uuid.v4(), key: 'foo', value: 'bar', domain: this.props.newCookieDomainName, expires: MAX_TIME, path: '/', secure: false, httpOnly: false, }; this.props.handleCookieAdd(newCookie); } _handleDeleteCookie(cookie: Cookie) { this.props.handleCookieDelete(cookie); } render() { const { cookies, handleDeleteAll, handleShowModifyCookieModal, handleRender } = this.props; return (
{cookies.map((cookie, i) => { const cookieString = cookieToString(toughCookie.Cookie.fromJSON(cookie)); return ( ); })}
Domain Cookie Actions Add Cookie Delete All
{cookie.domain || ''} {cookieString || ''} {}} className="text-right no-wrap"> {' '} this._handleDeleteCookie(cookie)} title="Delete cookie">
{cookies.length === 0 && (

I couldn't find any cookies for you.

)}
); } } export default CookieList;