Skip to content

Commit b82e855

Browse files
authored
feat: show followed hashtag badge (#3273)
1 parent b0f3018 commit b82e855

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

components/status/StatusCard.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { mastodon } from 'masto'
33
44
const { actions = true, older, newer, hasOlder, hasNewer, main, ...props } = defineProps<{
55
status: mastodon.v1.Status
6+
followedTag?: string | null
67
actions?: boolean
78
context?: mastodon.v2.FilterContext
89
hover?: boolean
@@ -73,6 +74,20 @@ const forceShow = ref(false)
7374
<div :h="showUpperBorder ? '1px' : '0'" w-auto bg-border mb-1 z--1 />
7475

7576
<slot name="meta">
77+
<!-- followed hashtag badge -->
78+
<div flex="~ col" justify-between>
79+
<div
80+
v-if="!!followedTag && followedTag !== ''"
81+
flex="~ gap2" items-center h-auto text-sm text-orange
82+
m="is-5" p="t-1 is-5"
83+
relative text-secondary ws-nowrap
84+
>
85+
<div i-ri:hashtag />
86+
<!-- show first hit followed tag -->
87+
<span>{{ followedTag }}</span>
88+
</div>
89+
</div>
90+
7691
<!-- Pinned status -->
7792
<div flex="~ col" justify-between>
7893
<div

components/timeline/TimelineHome.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ const stream = useStreaming(client => client.user.subscribe())
1010
function reorderAndFilter(items: mastodon.v1.Status[]) {
1111
return reorderedTimeline(items, 'home')
1212
}
13+
14+
const followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
1315
</script>
1416

1517
<template>
1618
<div>
1719
<PublishWidgetList draft-key="home" />
1820
<div h="1px" w-auto bg-border mb-3 />
19-
<TimelinePaginator v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="home" />
21+
<TimelinePaginator :followed-tags="followedTags" v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="home" />
2022
</div>
2123
</template>

components/timeline/TimelinePaginator.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import type { mastodon } from 'masto'
44
import { DynamicScrollerItem } from 'vue-virtual-scroller'
55
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
66
7-
const { account, buffer = 10, endMessage = true } = defineProps<{
7+
const { account, buffer = 10, endMessage = true, followedTags = [] } = defineProps<{
88
paginator: mastodon.Paginator<mastodon.v1.Status[], mastodon.rest.v1.ListAccountStatusesParams>
99
stream?: mastodon.streaming.Subscription
1010
context?: mastodon.v2.FilterContext
1111
account?: mastodon.v1.Account
12+
followedTags?: mastodon.v1.Tag[]
1213
preprocess?: (items: mastodon.v1.Status[]) => mastodon.v1.Status[]
1314
buffer?: number
1415
endMessage?: boolean | string
@@ -20,6 +21,12 @@ const virtualScroller = usePreferences('experimentalVirtualScroller')
2021
const showOriginSite = computed(() =>
2122
account && account.id !== currentUser.value?.account.id && getServerName(account) !== currentServer.value,
2223
)
24+
25+
function getFollowedTag(status: mastodon.v1.Status): string | null {
26+
const followedTagNames = followedTags.map(tag => tag.name)
27+
const followedStatusTags = status.tags.filter(tag => followedTagNames.includes(tag.name))
28+
return followedStatusTags.length ? followedStatusTags[0]?.name : null
29+
}
2330
</script>
2431

2532
<template>
@@ -32,11 +39,11 @@ const showOriginSite = computed(() =>
3239
<template #default="{ item, older, newer, active }">
3340
<template v-if="virtualScroller">
3441
<DynamicScrollerItem :item="item" :active="active" tag="article">
35-
<StatusCard :status="item" :context="context" :older="older" :newer="newer" />
42+
<StatusCard :followed-tag="getFollowedTag(item)" :status="item" :context="context" :older="older" :newer="newer" />
3643
</DynamicScrollerItem>
3744
</template>
3845
<template v-else>
39-
<StatusCard :status="item" :context="context" :older="older" :newer="newer" />
46+
<StatusCard :followed-tag="getFollowedTag(item)" :status="item" :context="context" :older="older" :newer="newer" />
4047
</template>
4148
</template>
4249
<template v-if="context === 'account' " #done="{ items }">

components/timeline/TimelinePublic.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const stream = useStreaming(client => client.public.subscribe())
66
function reorderAndFilter(items: mastodon.v1.Status[]) {
77
return reorderedTimeline(items, 'public')
88
}
9+
10+
const followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
911
</script>
1012

1113
<template>
1214
<div>
13-
<TimelinePaginator v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="public" />
15+
<TimelinePaginator :followed-tags="followedTags" v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="public" />
1416
</div>
1517
</template>

components/timeline/TimelinePublicLocal.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const stream = useStreaming(client => client.public.local.subscribe())
66
function reorderAndFilter(items: mastodon.v1.Status[]) {
77
return reorderedTimeline(items, 'public')
88
}
9+
10+
const followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
911
</script>
1012

1113
<template>
1214
<div>
13-
<TimelinePaginator v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="public" />
15+
<TimelinePaginator :followed-tags="followedTags" v-bind="{ paginator, stream }" :preprocess="reorderAndFilter" context="public" />
1416
</div>
1517
</template>

pages/[[server]]/tags/[tag].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ onReactivated(() => {
2323
// The user will see the previous content first, and any changes will be updated to the UI when the request is completed
2424
refresh()
2525
})
26+
const followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
2627
</script>
2728

2829
<template>
@@ -38,7 +39,7 @@ onReactivated(() => {
3839
</template>
3940

4041
<slot>
41-
<TimelinePaginator v-bind="{ paginator, stream }" context="public" />
42+
<TimelinePaginator :followed-tags="followedTags" v-bind="{ paginator, stream }" context="public" />
4243
</slot>
4344
</MainContent>
4445
</template>

0 commit comments

Comments
 (0)