forked from Mirrors/elk
feat: follow tags from trends page (#1391)
This commit is contained in:
parent
677d6188b4
commit
1a7ae6f0ef
2 changed files with 42 additions and 8 deletions
|
@ -12,6 +12,13 @@ const emit = defineEmits<{
|
||||||
const { client } = $(useMasto())
|
const { client } = $(useMasto())
|
||||||
|
|
||||||
const toggleFollowTag = async () => {
|
const toggleFollowTag = async () => {
|
||||||
|
// We save the state so be can do an optimistic UI update, but fallback to the previous state if the API call fails
|
||||||
|
const previousFollowingState = tag.following
|
||||||
|
|
||||||
|
// eslint-disable-next-line vue/no-mutating-props
|
||||||
|
tag.following = !tag.following
|
||||||
|
|
||||||
|
try {
|
||||||
if (tag.following)
|
if (tag.following)
|
||||||
await client.v1.tags.unfollow(tag.name)
|
await client.v1.tags.unfollow(tag.name)
|
||||||
else
|
else
|
||||||
|
@ -19,6 +26,11 @@ const toggleFollowTag = async () => {
|
||||||
|
|
||||||
emit('change')
|
emit('change')
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
// eslint-disable-next-line vue/no-mutating-props
|
||||||
|
tag.following = previousFollowingState
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -11,12 +11,34 @@ const to = $computed(() => {
|
||||||
const { hostname, pathname } = new URL(tag.url)
|
const { hostname, pathname } = new URL(tag.url)
|
||||||
return `/${hostname}${pathname}`
|
return `/${hostname}${pathname}`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
function onclick(evt: MouseEvent | KeyboardEvent) {
|
||||||
|
const path = evt.composedPath() as HTMLElement[]
|
||||||
|
const el = path.find(el => ['A', 'BUTTON'].includes(el.tagName?.toUpperCase()))
|
||||||
|
const text = window.getSelection()?.toString()
|
||||||
|
if (!el && !text)
|
||||||
|
go(evt)
|
||||||
|
}
|
||||||
|
|
||||||
|
function go(evt: MouseEvent | KeyboardEvent) {
|
||||||
|
if (evt.metaKey || evt.ctrlKey)
|
||||||
|
window.open(to)
|
||||||
|
else
|
||||||
|
router.push(to)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NuxtLink :to="to" block p4 hover:bg-active flex justify-between>
|
<div
|
||||||
|
block p4 hover:bg-active flex justify-between cursor-pointer
|
||||||
|
@click="onclick"
|
||||||
|
@keydown.enter="onclick"
|
||||||
|
>
|
||||||
<div>
|
<div>
|
||||||
<h4 text-size-base leading-normal font-medium line-clamp-1 break-all ws-pre-wrap>
|
<h4 flex items-center text-size-base leading-normal font-medium line-clamp-1 break-all ws-pre-wrap>
|
||||||
|
<TagActionButton :tag="tag" />
|
||||||
<span>#</span>
|
<span>#</span>
|
||||||
<span hover:underline>{{ tag.name }}</span>
|
<span hover:underline>{{ tag.name }}</span>
|
||||||
</h4>
|
</h4>
|
||||||
|
@ -25,5 +47,5 @@ const to = $computed(() => {
|
||||||
<div flex items-center>
|
<div flex items-center>
|
||||||
<CommonTrendingCharts :history="tag.history" />
|
<CommonTrendingCharts :history="tag.history" />
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in a new issue