-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DocDiff: Cache remote content #441
Open
ericholscher
wants to merge
14
commits into
main
Choose a base branch
from
cache-docdiff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−41
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
37f28d4
DocDiff: Cache remote content
ericholscher 2822fe7
Merge branch 'main' of github.com:readthedocs/addons into cache-docdiff
ericholscher 454eda2
Try caching
ericholscher 5606649
Merge branch 'main' of github.com:readthedocs/addons into cache-docdiff
ericholscher 09d5101
Don't run when it's already enabled
ericholscher adc6441
Properly keep track of state in docdiff module.
ericholscher ac0dd15
Remove unused imports
ericholscher 8ec9ef4
Try to track events
ericholscher 8a265cf
Merge branch 'main' of github.com:readthedocs/addons into cache-docdiff
ericholscher 49108f5
Fix function type to keep state
ericholscher 2e911b1
Remove logging
ericholscher 1ca8477
Add debug logging
ericholscher 21179dc
Add disconnect back
ericholscher 8a6e277
Refactor into functions so we can disable them
ericholscher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { ajv } from "./data-validation"; | ||
import { toString as keyboardEventToString } from "keyboard-event-to-string"; | ||
|
||
import { AddonBase } from "./utils"; | ||
import { html, nothing, LitElement } from "lit"; | ||
import { LitElement } from "lit"; | ||
import { | ||
EVENT_READTHEDOCS_SEARCH_SHOW, | ||
EVENT_READTHEDOCS_SEARCH_HIDE, | ||
EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW, | ||
EVENT_READTHEDOCS_DOCDIFF_HIDE, | ||
} from "./events"; | ||
|
@@ -26,7 +24,6 @@ export class HotKeysElement extends LitElement { | |
super(); | ||
|
||
this.config = null; | ||
this.docDiffShow = false; | ||
} | ||
|
||
loadConfig(config) { | ||
|
@@ -40,7 +37,7 @@ export class HotKeysElement extends LitElement { | |
this.config = config; | ||
|
||
this.docDiffHotKeyEnabled = this.config.addons.hotkeys.doc_diff.enabled; | ||
this.docDiffShowed = false; | ||
this.docDiffEnabled = false; | ||
|
||
this.searchHotKeyEnabled = this.config.addons.hotkeys.search.enabled; | ||
} | ||
|
@@ -51,6 +48,7 @@ export class HotKeysElement extends LitElement { | |
// Read more about these decisions at https://github.com/readthedocs/addons/issues/80 | ||
|
||
let event; | ||
|
||
// DocDiff | ||
if ( | ||
this.docDiffHotKeyEnabled && | ||
|
@@ -60,12 +58,13 @@ export class HotKeysElement extends LitElement { | |
document.activeElement.tagName !== "TEXTAREA" && | ||
document.activeElement.tagName !== "READTHEDOCS-SEARCH" | ||
) { | ||
if (this.docDiffShowed) { | ||
if (this.docDiffEnabled) { | ||
event = new CustomEvent(EVENT_READTHEDOCS_DOCDIFF_HIDE); | ||
this.docDiffShowed = false; | ||
} else { | ||
event = new CustomEvent(EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW); | ||
this.docDiffShowed = true; | ||
} | ||
if (event !== undefined) { | ||
document.dispatchEvent(event); | ||
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove this from here. The event is already dispatched in line 82 and it also prevent its default. |
||
} | ||
} | ||
|
||
|
@@ -89,12 +88,36 @@ export class HotKeysElement extends LitElement { | |
connectedCallback() { | ||
super.connectedCallback(); | ||
document.addEventListener("keydown", this._handleKeydown); | ||
document.addEventListener( | ||
EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW, | ||
this._handleDocDiffShow, | ||
); | ||
document.addEventListener( | ||
EVENT_READTHEDOCS_DOCDIFF_HIDE, | ||
this._handleDocDiffHide, | ||
); | ||
} | ||
|
||
disconnectedCallback() { | ||
document.removeEventListener("keydown", this._handleKeydown); | ||
document.removeEventListener( | ||
EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW, | ||
this._handleDocDiffShow, | ||
); | ||
document.removeEventListener( | ||
EVENT_READTHEDOCS_DOCDIFF_HIDE, | ||
this._handleDocDiffHide, | ||
); | ||
super.disconnectedCallback(); | ||
} | ||
|
||
_handleDocDiffShow = (event) => { | ||
this.docDiffEnabled = true; | ||
}; | ||
|
||
_handleDocDiffHide = (event) => { | ||
this.docDiffEnabled = false; | ||
}; | ||
} | ||
|
||
export class HotKeysAddon extends AddonBase { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is not correct when
this.config === null
. It will be confusing in that case since it won't be enabled because there is no config.