This repository has been archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
688 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const c = require("lib/constants"); | ||
const {request, receive} = require("lib/utils"); | ||
const userDatabase = require("lib/userDatabase"); | ||
const blockedLinks = require("lib/blockedLinks"); | ||
const async = require("lib/async"); | ||
|
||
module.exports = { | ||
initUserDatabase() { | ||
return async(function* (dispatch) { | ||
dispatch(request(c.REQUEST_INIT_USER_DATABASE)); | ||
yield userDatabase.init(); | ||
yield blockedLinks.init(userDatabase); | ||
dispatch(receive(c.REQUEST_INIT_USER_DATABASE_COMPLETE)); | ||
}, this); | ||
}, | ||
|
||
setUndoDialogVisibility(isVisible, blockedURL) { | ||
return receive(c.REQUEST_UNDO_DIALOG_VISIBILITY, { | ||
visible: isVisible, | ||
blockedURL: blockedURL | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const React = require("react"); | ||
const {connect} = require("react-redux"); | ||
const actions = require("actions/index"); | ||
const blockedLinks = require("lib/blockedLinks"); | ||
|
||
const Block = React.createClass({ | ||
/** | ||
* The undo dialog's timeout in miliseconds. | ||
*/ | ||
HIDE_TIMEOUT_MS: 15000, | ||
_timeout: 0, | ||
|
||
/** | ||
* Hides the undo dialog. | ||
*/ | ||
hide() { | ||
this.props.dispatch(actions.setUndoDialogVisibility(false)); | ||
clearTimeout(this._timeout); | ||
this._timeout = 0; | ||
}, | ||
|
||
undo() { | ||
blockedLinks.unblock(this.props.blockedURL); | ||
this.props.dispatch(actions.setUndoDialogVisibility(false)); | ||
this.props.dispatch(actions.updateSites(this.props.url)); | ||
}, | ||
|
||
undoAll() { | ||
blockedLinks.reset(); | ||
this.props.dispatch(actions.setUndoDialogVisibility(false)); | ||
this.props.dispatch(actions.updateSites(this.props.url)); | ||
}, | ||
|
||
render: function () { | ||
if (this.timeout) { | ||
clearTimeout(this._timeout); | ||
this._timeout = 0; | ||
} | ||
this._timeout = setTimeout(this.hide, this.HIDE_TIMEOUT_MS); | ||
return (<div className="undo" hidden={!this.props.visible}> | ||
<label id="undo-label">Thumbnail removed.</label> | ||
<button id="undo-button" className="undo-button" onClick={e => this.undo(e)}>Undo.</button> | ||
<button id="restore-button" className="undo-button" onClick={e => this.undoAll(e)}>Restore All.</button> | ||
<div id="undo-close-button" className="close-icon tabbable" | ||
data-tooltiptext="CLOSE" onClick={e => this.hide(e)}></div> | ||
</div>); | ||
} | ||
}); | ||
|
||
Block.propTypes = { | ||
visible: React.PropTypes.bool, | ||
blockedURL: React.PropTypes.string | ||
}; | ||
|
||
function select(state) { | ||
return { | ||
Block: state.Block | ||
}; | ||
} | ||
|
||
module.exports = connect(select)(Block); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.undo { | ||
align-items: center; | ||
justify-content: center; | ||
display: flex; | ||
left: 6px; | ||
position: absolute; | ||
top: 6px; | ||
z-index: 1; | ||
padding: 4px 3px; | ||
border: 1px solid; | ||
border-color: rgba(8,22,37,.12) rgba(8,22,37,.14) rgba(8,22,37,.16); | ||
background-color: rgba(255,255,255,.4); | ||
color: #525e69; | ||
font-size: 11px; | ||
|
||
#undo-label { | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
} | ||
|
||
.undo-button { | ||
appearance: none; | ||
cursor: pointer; | ||
padding: 0; | ||
margin: 0 4px; | ||
border: 0; | ||
background: transparent; | ||
text-decoration: none; | ||
min-width: 0; | ||
color: rgb(20,79,174); | ||
} | ||
|
||
.undo-button:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
.undo-button:-moz-focusring { | ||
outline: 1px dotted; | ||
} | ||
|
||
#undo-close-button { | ||
appearance: none; | ||
padding: 0; | ||
border: none; | ||
height: 16px; | ||
width: 16px; | ||
float: right; | ||
right: 0; | ||
background-image: -moz-image-rect(url(../img/close.png), 0, 16, 16, 0); | ||
background-color: transparent; | ||
} | ||
|
||
#undo-close-button:hover { | ||
background-image: -moz-image-rect(url(../img/close.png), 0, 32, 16, 16); | ||
} | ||
|
||
#undo-close-button:hover:active { | ||
background-image: -moz-image-rect(url(../img/close.png), 0, 48, 16, 32); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const async = require("lib/async"); | ||
const userDatabase = require("lib/userDatabase"); | ||
|
||
/** | ||
* Singleton that keeps track of all blocked links in the grid. | ||
*/ | ||
const blockedLinks = { | ||
/** | ||
* The cached list of blocked links. | ||
*/ | ||
_links: new Set(), | ||
|
||
/** | ||
* Load the blocked links from userDatabase and cache them. | ||
*/ | ||
init: async(function*() { | ||
const result = yield userDatabase.load("prefs", "blockedLinks"); | ||
const loadedBlockedLinks = JSON.parse(result); | ||
if (loadedBlockedLinks && loadedBlockedLinks.length) { | ||
blockedLinks._links.clear(); | ||
loadedBlockedLinks.forEach(item => blockedLinks._links.add(item)); | ||
} | ||
return blockedLinks; | ||
}), | ||
|
||
/** | ||
* Blocks a given link. Adjusts siteMap accordingly, and notifies listeners. | ||
* | ||
* @param {String} aURL The link to block. | ||
*/ | ||
block(aURL) { | ||
this._links.add(aURL); | ||
return this.save(); | ||
}, | ||
|
||
/** | ||
* Unblocks a given link. Adjusts siteMap accordingly, and notifies listeners. | ||
* | ||
* @param {String} aURL The link to unblock. | ||
*/ | ||
unblock(aURL) { | ||
const isBlocked = this.isBlocked(aURL); | ||
if (isBlocked) { | ||
this._links.delete(aURL); | ||
return this.save(); | ||
} | ||
return Promise.resolve(); | ||
}, | ||
|
||
/** | ||
* Saves the current list of blocked links. | ||
*/ | ||
save() { | ||
return userDatabase.save("prefs", "blockedLinks", JSON.stringify([...this._links])); | ||
}, | ||
|
||
/** | ||
* Returns whether a given link is blocked. | ||
* | ||
* @param {String} aURL The link to check. | ||
*/ | ||
isBlocked(aURL) { | ||
return this._links.has(aURL); | ||
}, | ||
|
||
/** | ||
* Checks whether the list of blocked links is empty. | ||
* | ||
* @return {Boolean} Whether the list is empty. | ||
*/ | ||
isEmpty() { | ||
return this._links.size === 0; | ||
}, | ||
|
||
/** | ||
* Resets the links cache and IDB object. | ||
*/ | ||
reset() { | ||
this._links.clear(); | ||
return this.save(); | ||
} | ||
}; | ||
module.exports = blockedLinks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.