insomnia/app/ui/components/modals/CookiesModal.js

144 lines
4.2 KiB
JavaScript
Raw Normal View History

import React, {PropTypes, Component} from 'react';
import Modal from '../base/Modal';
import ModalBody from '../base/ModalBody';
import ModalHeader from '../base/ModalHeader';
import ModalFooter from '../base/ModalFooter';
import CookiesEditor from '../editors/CookiesEditor';
2016-11-10 05:56:23 +00:00
import * as models from '../../../models';
import {trackEvent} from '../../../analytics/index';
class CookiesModal extends Component {
2016-11-26 08:29:16 +00:00
state = {
cookieJar: null,
workspace: null,
filter: ''
};
async _saveChanges () {
const {cookieJar} = this.state;
2016-11-10 01:15:27 +00:00
await models.cookieJar.update(cookieJar);
this._load(this.state.workspace);
}
_handleCookieUpdate (oldCookie, cookie) {
const {cookieJar} = this.state;
const {cookies} = cookieJar;
const index = cookies.findIndex(c => c.domain === oldCookie.domain && c.key === oldCookie.key);
cookieJar.cookies = [
...cookies.slice(0, index),
cookie,
...cookies.slice(index + 1)
];
this._saveChanges(cookieJar);
trackEvent('Cookie', 'Update');
}
_handleCookieAdd (cookie) {
const {cookieJar} = this.state;
const {cookies} = cookieJar;
cookieJar.cookies = [cookie, ...cookies];
this._saveChanges(cookieJar);
trackEvent('Cookie', 'Create');
}
_handleCookieDelete (cookie) {
const {cookieJar} = this.state;
const {cookies} = cookieJar;
// NOTE: This is sketchy because it relies on the same reference
cookieJar.cookies = cookies.filter(c => c !== cookie);
this._saveChanges(cookieJar);
trackEvent('Cookie', 'Delete');
}
_onFilterChange (filter) {
2016-11-10 21:03:12 +00:00
this.setState({filter});
trackEvent('Cookie Editor', 'Filter Change');
}
_getFilteredSortedCookies () {
const {cookieJar, filter} = this.state;
if (!cookieJar) {
// Nothing to do yet.
return [];
}
const {cookies} = cookieJar;
return cookies.filter(c => {
const toSearch = JSON.stringify(c).toLowerCase();
return toSearch.indexOf(filter.toLowerCase()) !== -1;
});
}
async _load (workspace) {
2016-11-10 01:15:27 +00:00
const cookieJar = await models.cookieJar.getOrCreateForWorkspace(workspace);
this.setState({cookieJar, workspace});
}
async show (workspace) {
await this._load(workspace);
this.modal.show();
this.filterInput.focus();
trackEvent('Cookie Editor', 'Show');
}
2016-08-15 22:31:30 +00:00
toggle (workspace) {
this.modal.toggle();
this.filterInput.focus();
this._load(workspace);
}
render () {
const filteredCookies = this._getFilteredSortedCookies();
const {filter} = this.state;
return (
<Modal ref={m => this.modal = m} wide={true} top={true} tall={true} {...this.props}>
<ModalHeader>Manage Cookies</ModalHeader>
2017-01-24 02:52:48 +00:00
<ModalBody className="cookie-editor" noScroll={true}>
<div className="pad">
<div className="form-control form-control--outlined">
<label>Filter Cookies
<input ref={n => this.filterInput = n}
onChange={e => this._onFilterChange(e.target.value)}
type="text"
placeholder="twitter.com"
defaultValue=""/>
</label>
2016-09-22 04:17:38 +00:00
</div>
</div>
<div className="cookie-editor__editor border-top">
<div className="pad-top">
<CookiesEditor
cookies={filteredCookies}
onCookieUpdate={(oldCookie, cookie) => this._handleCookieUpdate(oldCookie, cookie)}
onCookieAdd={cookie => this._handleCookieAdd(cookie)}
onCookieDelete={cookie => this._handleCookieDelete(cookie)}
// Set the domain to the filter so that it shows up if we're filtering
newCookieDomainName={filter || 'domain.com'}
/>
</div>
</div>
</ModalBody>
<ModalFooter>
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
<div className="margin-left faint italic txt-sm tall">
* cookies are automatically sent with relevant requests
</div>
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
<button className="btn" onClick={e => this.modal.hide()}>
Done
</button>
</ModalFooter>
</Modal>
);
}
}
CookiesModal.propTypes = {};
// export CookiesModal;
export default CookiesModal;