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

feat: show tag hover card when hovering cursor on hashtag links #2621

Merged
merged 30 commits into from Mar 4, 2024

Conversation

shuuji3
Copy link
Member

@shuuji3 shuuji3 commented Feb 25, 2024

This implements the hovercard feature for hashtags.

I think there are several benefits of tag hovercard:

Screenshots

Screenshot from 2024-02-25 17-35-58

Screenshot from 2024-02-25 17-53-58

Copy link

stackblitz bot commented Feb 25, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for elk-docs canceled.

Name Link
🔨 Latest commit 9b9d74b
🔍 Latest deploy log https://app.netlify.com/sites/elk-docs/deploys/65df7b40f1e01c000818ed5a

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for elk-zone ready!

Name Link
🔨 Latest commit 9b9d74b
🔍 Latest deploy log https://app.netlify.com/sites/elk-zone/deploys/65df7b4020c8b00008922aa0
😎 Deploy Preview https://deploy-preview-2621--elk-zone.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@patak-dev
Copy link
Member

This looks amazing! I agree the UX after this change for tags is greatly improved.

One thing before we merge, could you check the layout of that card?
image

I think we should have more gap between the text and the graph. And maybe push the star to the right of the tag name so the tag looks aligned with the text below.

() => [props.tagName, targetIsVisible.value] satisfies WatcherType,
async ([newTagName, newVisible]) => {
if (newTagName) {
tag.value = await fetchTag(newTagName)
Copy link
Member

Choose a reason for hiding this comment

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

Ensure you dont fetch it if not in screen

Copy link
Member

Choose a reason for hiding this comment

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

the browser will hang

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! The original implementation was fetching API too aggressively.😅

I moved the fetchTag() to TagCard component to ensure that it's only called when showing the card.

Copy link
Member

Choose a reason for hiding this comment

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

I'm going to take a look at this...

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 25, 2024

@patak-dev I adjusted the layout a bit. What do you think?

Screenshot from 2024-02-25 20-14-29

Screenshot from 2024-02-25 20-14-34

@@ -32,13 +40,13 @@ function go(evt: MouseEvent | KeyboardEvent) {

<template>
<div
block p4 hover:bg-active flex justify-between cursor-pointer
block p4 hover:bg-active flex justify-between cursor-pointer flex-gap-2
Copy link
Member Author

Choose a reason for hiding this comment

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

This gap also improves the layout of the hashtag page in Explore tab for very long hashtag names.

Screenshot from 2024-02-25 20-21-16

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 for long tags the start should be top aligned

Copy link
Member

Choose a reason for hiding this comment

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

I'd like the tag to always be aligned with the text below. I proposed having the star to the right, but I see now that it isn't a good idea. Maybe we should have the star always at the top left, and then the tag and the text below to the right of it. Or the star could be at the right of the graph, kind of like the Follow button in the notification cards for people following you

Copy link
Member Author

@shuuji3 shuuji3 Feb 25, 2024

Choose a reason for hiding this comment

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

OK, I tried another layout by making the follow button an independent block and placing it on the left. This ensures both texts are aligned and more robust with a long hashtag.

For Hovercard, items-center looks lined up better than the top. For Hashtag, both look fine.

@patak-dev Which position do you prefer if we use this layout?

Hovercard

Screenshot from 2024-02-25 21-19-41

align center (items-center)

Screenshot from 2024-02-25 21-19-06
Screenshot from 2024-02-25 21-10-25

align top (items-start)

Screenshot from 2024-02-25 21-18-56
Screenshot from 2024-02-25 21-11-57

Hashtag page

Screenshot from 2024-02-25 21-44-05
Screenshot from 2024-02-25 21-43-37

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 25, 2024

Hmm, I'm not sure why snapshot tests start revealing <VMenu> tag here: https://github.com/elk-zone/elk/actions/runs/8037557151/job/21952513803#step:7:88

I wonder if it's safe to update the snapshot test. 🤔

@userquin
Copy link
Member

userquin commented Feb 25, 2024

Hmm, I'm not sure why snapshot tests start revealing <VMenu> tag here: https://github.com/elk-zone/elk/actions/runs/8037557151/job/21952513803#step:7:88

I wonder if it's safe to update the snapshot test. 🤔

We'll need to mock it, I'm going to fix it

@userquin
Copy link
Member

userquin commented Feb 25, 2024

@shuuji3 your local deps are stale, run nr test:ci in your local

Try updating main and update your branch, then pnpm install --frozen-lockfile && nr test:ci (should dedupe dependencies)

@userquin userquin marked this pull request as draft February 25, 2024 12:09
@userquin
Copy link
Member

@shuuji3 the logic seems to be wrong, we should avoid fetching the tag until visible in the viewport, the browser will hang if lot of tags, the result is not deterministic since it depends on the current timeline content

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 25, 2024

@userquin Does your local branch have this commit (381d166)? I observed that issue in the network tab on devtool, but that issue should be fixed after this commit.

@userquin
Copy link
Member

yes, but this is wrong, the tagName will not prevent to fetch the tag once set, you have the fetch with toplevel await in the TagCard script setup

@patak-dev
Copy link
Member

Thanks for playing with the design of the card, I think it looks a lot better now! 🧡

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 25, 2024

Updated to the new layout (used items-center to be able to share the same template without the necessity of the layout prop) and fixed the remaining test error now.

@shuuji3 shuuji3 marked this pull request as ready for review February 25, 2024 14:12
composables/settings/definition.ts Outdated Show resolved Hide resolved
@shuuji3 shuuji3 closed this Feb 26, 2024
@shuuji3 shuuji3 reopened this Feb 26, 2024
@shuuji3 shuuji3 marked this pull request as draft February 26, 2024 10:48
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Awesome!

I see it is still a draft, mark it as ready when you think we should merge it

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 26, 2024

Ah, actually, the draft change was intentional (close/reopen was my mistake 😅). Thanks to userquin, the issue where multiple tag fetch caused the race condition and hanging up timeline was solved, and also duplicated calls fr the same tag are properly cached now.

However, it seems that the current TagCardWrapper still calls API requests to https://<server-domain>/api/v1/tags/<tag-name> when the user scrolls the timeline and sees a new tag for the first time.

This is problematic because this endpoint has 300 calls / 5 min. rate limit similar to other API endpoints so if the user scrolls in a short period and sees more than 300 tags, it will exceed the rate limit and the endpoint will start returning 429 (too many requests) during 5 min. window.

So I need to find a way not to call the tag endpoint until the user hovers the cursor on the tag link.

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 27, 2024

Now, fetchTag() should be called only once when hovering it. Also, the component code can be simplified. I hope this works fine.

tag-hovering.mp4

@shuuji3 shuuji3 marked this pull request as ready for review February 27, 2024 16:01
@shuuji3
Copy link
Member Author

shuuji3 commented Feb 27, 2024

I had to update the same test snapshot again for strange <VMenu>. I guess this original comment is correct in a way:
https://github.com/shuuji3/elk/blob/db070eed8111bfc71b0686f9003f8cd736aff55a/tests/nuxt/content-rich.test.ts#L163-L163

@userquin
Copy link
Member

I had to update the same test snapshot again for strange <VMenu>. I guess this original comment is correct in a way

The bdi content should be there I'm going to check what's wrong in the content-render module

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 27, 2024

TODO: show spinner before receiving the actual tag data.

@userquin
Copy link
Member

Check #2632

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 28, 2024

There was a good skeleton component for the tag: https://github.com/elk-zone/elk/blob/main/components/tag/TagCardSkeleton.vue

elk-taghover-skeleton.mp4

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 28, 2024

f67be19 (#2621)

Also, there was a useful useElementHover utility (https://vueuse.org/core/useElementHover/) instead of the manual mouse event handling. This can be used in #2632 as well.

@shuuji3
Copy link
Member Author

shuuji3 commented Feb 28, 2024

OK, I think it's ready to merge.

elk-taghover-skeleton.mp4

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Amazing work! 👏🏼

@patak-dev patak-dev added this pull request to the merge queue Mar 4, 2024
Merged via the queue into elk-zone:main with commit e44833b Mar 4, 2024
13 checks passed
@shuuji3 shuuji3 deleted the feat/tag-hover-card branch March 4, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show details on hover for mentions and tags in statuses
3 participants