-
Notifications
You must be signed in to change notification settings - Fork 11
Add lightbox support and Hydrogen URL hashes relative to the room #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
05e9eb3
Fill in image link to lightbox (lightbox not working)
MadLittleMods 16d5037
Use actual roomId
MadLittleMods 9dceb4a
Remove commented out code that isn't as relevant
MadLittleMods f153fcb
WIP: Make the lightbox open, not working yet
MadLittleMods d766028
Working lightbox pops up and closes
MadLittleMods eb44fe1
URL hashes relative to the room of the archive
MadLittleMods 0763c78
Fix blank hrefs reloading page
MadLittleMods 84407b3
Merge branch 'main' into madlittlemods/image-lightbox-routing
MadLittleMods fc731bc
Some cleanup
MadLittleMods a949620
Lightbox escape keyboard shortcut also works
MadLittleMods 3237399
Some cleanup
MadLittleMods 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
| 'use strict'; | ||
|
|
||
| const { History } = require('hydrogen-view-sdk'); | ||
| const assert = require('./assert'); | ||
|
|
||
| // Mock a full hash whenever someone asks via `history.get()` but when | ||
| // constructing URL's for use `href` etc, they should relative to the room | ||
| // (remove session and room from the hash). | ||
| class ArchiveHistory extends History { | ||
| constructor(roomId) { | ||
| super(); | ||
|
|
||
| assert(roomId); | ||
| this._baseHash = `#/session/123/room/${roomId}`; | ||
| } | ||
|
|
||
| // Even though the page hash is relative to the room, we still expose the full | ||
| // hash for Hydrogen to route things internally as expected. | ||
| get() { | ||
| const hash = super.get()?.replace(/^#/, '') ?? ''; | ||
| return this._baseHash + hash; | ||
| } | ||
|
|
||
| replaceUrlSilently(url) { | ||
| // We don't need to do this when server-side rendering in Node.js because | ||
| // the #hash is not available to servers. This will be called as a | ||
| // downstream call of `urlRouter.attach()` which we do when bootstraping | ||
| // everything. | ||
| if (window.history) { | ||
| super.replaceUrlSilently(url); | ||
| } | ||
| } | ||
|
|
||
| // Make the URLs we use in the UI of the app relative to the room: | ||
| // Before: #/session/123/room/!HBehERstyQBxyJDLfR:my.synapse.server/lightbox/$17cgP6YBP9ny9xuU1vBmpOYFhRG4zpOe9SOgWi2Wxsk | ||
| // After: #/lightbox/$17cgP6YBP9ny9xuU1vBmpOYFhRG4zpOe9SOgWi2Wxsk | ||
| pathAsUrl(path) { | ||
| const leftoverPath = super.pathAsUrl(path).replace(this._baseHash, ''); | ||
| // Only add back the hash when there is hash content beyond the base so we | ||
| // don't end up with an extraneous `#` on the end of the URL. This will end | ||
| // up creating some `<a href="">` (anchors with a blank href) but we have | ||
| // some code to clean this up, see `supressBlankAnchorsReloadingThePage`. | ||
| if (leftoverPath.length) { | ||
| return `#${leftoverPath}`; | ||
| } | ||
| return leftoverPath; | ||
| } | ||
| } | ||
|
|
||
| module.exports = ArchiveHistory; |
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.
Uh oh!
There was an error while loading. Please reload this page.