Skip to content
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

Implementation of UI for webmention reactions. #2572

Merged
merged 16 commits into from
Nov 25, 2021

Conversation

SaptakS
Copy link
Collaborator

@SaptakS SaptakS commented Nov 22, 2021

Refs #2192

I have added the UI implementation for the webmention reactions corresponding to like, reposts, replies and mentions of the chapter link. The tabs are keyboard navigable and have aria-notations similar to https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tab_role

Screenshot for likes in 2021 restructured data:
image

Screenshot for reposts in 2021 restructured data:
image

Screenshot for replies in 2021 restructured data:
image

Screenshot for mention in 2021 restructured data:
image

Things that can still be improved or added:

  • HTML sanitizing or DOM purifying: In the content for replies and mentions, we want to keep some HTML tags but santizie maybe the rest of them to prevent any kind of XSS attack. I know https://github.com/cure53/DOMPurify allows such implementation telling which tags and attributes to allow. Does anyone have any other suggestion?
  • Pagination: If the number of replies or mentions become a lot, then it might cause a lot of scroll. Also, in likes and reposts, more number of likes mean more images to load. So might want to think about that?
  • Homepage reactions: I and @tunetheweb had a little discussion that it might be worth adding webmentions (like replies and mentions) in the homepage in the form of testimonials like in https://www.11ty.dev/#dont-take-my-word-for-it-%F0%9F%8C%88

Staged URL: https://20211122t101742-dot-webalmanac.uk.r.appspot.com/en/2021/

@SaptakS SaptakS requested a review from tunetheweb November 22, 2021 13:12
@rviscomi rviscomi added the development Building the Almanac tech stack label Nov 22, 2021
@rviscomi rviscomi added this to the 2021 Launch 🚀 milestone Nov 22, 2021
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
@rviscomi
Copy link
Member

I've staged the PR here: https://20211122t101742-dot-webalmanac.uk.r.appspot.com/en/2021/

@SaptakS @tunetheweb I'm getting 0 reactions on all chapters. Is that a dev env CORS issue? How did it work for the screenshots above?

image

@SaptakS
Copy link
Collaborator Author

SaptakS commented Nov 22, 2021

Not sure if it's available in all chapters. I saw webmentions data in structured-data and third-parties. I tested in structured-data. And seems it's showing up there: https://20211122t101742-dot-webalmanac.uk.r.appspot.com/en/2021/structured-data

@rviscomi
Copy link
Member

Very weird. It only seems to work some of the time. Here's a side by side comparison of the same URL loaded twice

image

id="likes-tab"
tabindex="0"
>
<span id="likes-count">0</span> {{ self.likes() }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd need additional logic to handle singular and plural grammar, ie "1 like" vs "2 likes".

This is complicated for translations that follow different rules than simply 1 or not-1. @tunetheweb do we have any precedent for how to handle that in the translations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup:

if (comments === 1) {
document.querySelectorAll('.comment-singular').forEach(el => {
el.removeAttribute('data-translation');
});
} else {
document.querySelectorAll('.comment-plural').forEach(el => {
el.removeAttribute('data-translation');
});
}

Though suspect we need more than that for Slavic languages that have more than just singlar and plural. We have a plural_ru macro for that but looks like we never implemented that for the comment/comments. Can look at that later.

Copy link
Member

@rviscomi rviscomi Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. Let's get basic singular/plural support into this PR then we can worry about the more complex rules in a separate issue.

I also just came across Intl.PluralRules.select() which looks like it could be useful.

- use textContent instead of innerHTML where only text is added
- use key instead of keyCode which is deprecated
- use DOMParser and appendChild instead of innerHTML
- removes DOMContentLoaded eventListener
@SaptakS
Copy link
Collaborator Author

SaptakS commented Nov 22, 2021

I have tried to address most of the comments above.

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work @SaptakS !

Particularly appreciate the effort to make it accessible (and today I learned how to make accessible tablists!).

Got some requested changes though.

src/static/css/page.css Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/templates/base/base_chapter.html Outdated Show resolved Hide resolved
src/templates/base/base_chapter.html Outdated Show resolved Hide resolved
src/static/js/webmentions.js Show resolved Hide resolved
src/templates/base/base_chapter.html Outdated Show resolved Hide resolved
src/templates/base/base_chapter.html Show resolved Hide resolved
- Uses the text part of content in replies and mentions
- Unifies the rendering logic for different render types
- Rewrites the code using createElement instead of string parse
@SaptakS
Copy link
Collaborator Author

SaptakS commented Nov 23, 2021

@tunetheweb I have addressed all the comments.

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much cleaner. Will have a deeper look later but a few quick comments for you upfront.

src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty happy with this now. I think these last few suggestions will make CI pass and allow us to merge this.

src/static/css/page.css Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Outdated Show resolved Hide resolved
src/static/js/webmentions.js Show resolved Hide resolved
src/templates/base/base_chapter.html Outdated Show resolved Hide resolved
src/templates/base/base_chapter.html Outdated Show resolved Hide resolved
Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go! Great work on it.

@rviscomi you wanna have another look or happy to merge?

@tunetheweb tunetheweb merged commit b2fcafe into HTTPArchive:main Nov 25, 2021
@tunetheweb
Copy link
Member

Great job @SaptakS ! Thanks a lot for this.

Btw there's another tab index dev issue if interested?: #1325 (comment)

@tunetheweb
Copy link
Member

FYI @SaptakS I forgot to add you to the Developers team with this so added that to #2590 too.

@SaptakS
Copy link
Collaborator Author

SaptakS commented Nov 26, 2021

Great job @SaptakS ! Thanks a lot for this.

Btw there's another tab index dev issue if interested?: #1325 (comment)

I can take a stab at it after the security chapter related stuff is done with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Building the Almanac tech stack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants