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
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
385fa0f
feat: show tag hover card when hovering cursor on hashtag links
shuuji3 Feb 25, 2024
0d3ec43
text: update snapshot as `TagHoverWrapper` adds one `<span>` wrapper
shuuji3 Feb 25, 2024
381d166
fix: avoid aggressive tag fetch call by moving `fetchTag()` to `TagCa…
shuuji3 Feb 25, 2024
32b1151
fix: adjust tag hovercard layout
shuuji3 Feb 25, 2024
de8e26a
test: update vitest snapshot
shuuji3 Feb 25, 2024
f7c376a
chore: avoid fetching card until visible
userquin Feb 25, 2024
9b3184d
Revert "test: update vitest snapshot"
shuuji3 Feb 25, 2024
1019773
fix: remove unnecessary async
shuuji3 Feb 25, 2024
c1bce74
feat: improve tag card layout
shuuji3 Feb 25, 2024
acd15de
test: set `test.pool` = `forks` to fix pending test issue
shuuji3 Feb 25, 2024
3ed696f
fix: store a resolved promise when resolving cache result
userquin Feb 25, 2024
3219d65
fix(cache): cache fetch promises until resolved
userquin Feb 25, 2024
4bb6bdb
fix(cache): cache fetch promises until resolved also for account by id
userquin Feb 25, 2024
23bc2e9
chore: don't store promise, return the promise when requested
userquin Feb 25, 2024
9b8056f
chore: .
userquin Feb 25, 2024
89f0a47
chore: rever account hover changes
userquin Feb 25, 2024
0056238
chore: revert fetch promises
userquin Feb 25, 2024
b84c7f0
chore: remove pool forks
userquin Feb 25, 2024
2215703
chore: don't fetch when running tests
userquin Feb 25, 2024
da7dddd
chore: return resolved promise when cached instead the cached
userquin Feb 25, 2024
35cc206
chore: include `hide_account_and_tag_hover_card` translation for es-ES
userquin Feb 25, 2024
0f05142
chore: cleanup tag hover wrapper
userquin Feb 25, 2024
d19770d
feat: split `hideAccountHoverCard` and `hideTagHoverCard` settings
shuuji3 Feb 26, 2024
f6b2471
feat: fetch tag cache just once after hovering
shuuji3 Feb 26, 2024
db070ee
test: update vitest snapshot
shuuji3 Feb 27, 2024
8364abc
fix: check hovered value in watch and fetch tag cache each mouse hove…
shuuji3 Feb 27, 2024
d327c60
feat: show TagCardSkeleton during loading tag data
shuuji3 Feb 28, 2024
f67be19
refactor: use `useElementHover` for hover state detection
shuuji3 Feb 28, 2024
95fdea6
fix: revert show delay to initial 500ms included by mistake
shuuji3 Feb 28, 2024
9b9d74b
chore: update spanish entries
userquin Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 18 additions & 43 deletions components/account/TagHoverWrapper.vue
Original file line number Diff line number Diff line change
@@ -1,63 +1,38 @@
<script setup lang="ts">
import type { mastodon } from 'masto'
import { fetchTag } from '~/composables/cache'

type WatcherType = [tag?: mastodon.v1.Tag, tagName?: string, v?: boolean]

defineOptions({
inheritAttrs: false,
})

const props = defineProps<{
tag?: mastodon.v1.Tag
const { tagName, disabled } = defineProps<{
tagName?: string
disabled?: boolean
}>()

const hoverCard = ref()
const targetIsVisible = ref(false)
const tag = ref<mastodon.v1.Tag | null | undefined>(props.tag)

useIntersectionObserver(
hoverCard,
([{ intersectionRatio }]) => {
targetIsVisible.value = intersectionRatio > 0.1
},
)

watch(
() => [props.tag, props.tagName, targetIsVisible.value] satisfies WatcherType,
([newTag, newTagName, newVisible], oldProps) => {
if (newTag) {
tag.value = newTag
return
}

if (!newVisible || process.test)
return
const tag = ref<mastodon.v1.Tag>()
const hovered = ref(false)

if (newTagName) {
const [_oldTag, oldTagName, _oldVisible] = oldProps ?? [undefined, undefined, false]
if (!oldTagName || newTagName !== oldTagName || !tag.value) {
fetchTag(newTagName).then((t) => {
if (newTagName === props.tagName)
tag.value = t
})
}

return
}

tag.value = undefined
}, { immediate: true, flush: 'post' },
)
watch(hovered, () => {
if (tagName) {
fetchTag(tagName).then((t) => {
tag.value = t
})
}
})

const userSettings = useUserSettings()
</script>

<template>
<span ref="hoverCard">
<VMenu v-if="!disabled && tag && !getPreferences(userSettings, 'hideTagHoverCard')" placement="bottom-start" :delay="{ show: 500, hide: 100 }" v-bind="$attrs" :close-on-content-click="false">
<span @mouseenter="hovered = true">
shuuji3 marked this conversation as resolved.
Show resolved Hide resolved
<VMenu
v-if="!disabled && !getPreferences(userSettings, 'hideTagHoverCard')"
placement="bottom-start"
:delay="{ show: 500, hide: 100 }"
v-bind="$attrs"
:close-on-content-click="false"
>
<slot />
<template #popper>
<TagCard v-if="tag" :tag="tag" />
Expand Down
Loading