-
Notifications
You must be signed in to change notification settings - Fork 17
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
fetch previews only once per page load #296
Conversation
further clicking of preview only hides and shows content, does not reload
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.
given a bit of test drive, seems to be working fine
come to think of it, maybe the wording of the retry link label should be adjusted: "Click here to retry." since hiding and reopening the preview now no longer refresh the preview content and only that link would trigger refresh
mbin/assets/controllers/preview_controller.js
Lines 72 to 80 in 824905b
let failedHtml = | |
`<div class="preview"> | |
<a class="retry-failed" href="#" | |
data-action="preview#retry" | |
data-preview-url-param="${event.params.url}" | |
data-preview-ratio-param="${event.params.ratio}"> | |
Failed to load. Click to retry. | |
</a> | |
</div>` |
It'd be nice if it could be a loc token but I didn't see a quick example of that via JS. maybe it needs to load a twig template instead? |
some ways I could think of:
<div data-controller="preview"
data-preview-retry-label-value="{{ 'preview_click_to_retry'|trans }}">...</div> export default class extends Controller {
static values = {
retryLabel: String,
};
// ...
async show(event) {
// ...
let failedHtml = `<div><a>${this.retryLabelValue}</a></div>`
// ...
}
} |
This seems to work except for inline embeds. I'm stuck on adding it to https://github.com/MbinOrg/mbin/blob/main/src/Markdown/CommonMark/EmbedElement.php#L15-L19 I have Then again, maybe it doesn't effect past content if that markdown is parsed only once... hmm no even posting new content doesn't add any attributes to that html 😕 it renders |
Maybe I should just change the hardcoded wording here, leave it alone for now, and open a separate PR for translating it to take a look at? |
it should be that file ( using ux-translator for this is starting to look like a better option... |
Alright not saying I'm giving up but pulling in an experimental bundle for this also seems like it'd require a lot of testing, but it's possible we want to do that anyways, we probably have more hardcoded copy elsewhere I just went with changing the hardcoded copy for now to keep the changes here simple |
yeah I think that'd be good enough for now (the changes I pulled from kbin side is also hardcoded too)
I also found another bundle: https://github.com/willdurand/BazingaJsTranslationBundle if you want to play around |
this is a simple change where, after clicking the preview button once, further clicking will only hide and show the content, with no further AJAX calls to fetch the content again. If it fails, it will act as it did before showing a click to retry prompt (clicking preview will hide and show this prompt, but clicking on the prompt itself works to refetch the content)
@asdfzdfj since you touched the preview stuff recently, want to check with you that this makes sense
edit: tested this with asdfzdfj's example post of linked youtube with 2 image inlines and it appears to work, fetched each preview only once and correctly hid/made visible the previews after that