Enable hashtag search

This commit is contained in:
silverpill 2022-09-19 01:02:14 +00:00
parent 48f9c1800a
commit d16981c2b5
3 changed files with 20 additions and 4 deletions

View file

@ -46,7 +46,7 @@ export interface Mention {
url: string; url: string;
} }
export interface PostTag { export interface Tag {
name: string; name: string;
url: string; url: string;
} }
@ -66,7 +66,7 @@ export interface Post {
reblogs_count: number; reblogs_count: number;
media_attachments: Attachment[]; media_attachments: Attachment[];
mentions: Mention[]; mentions: Mention[];
tags: PostTag[]; tags: Tag[];
favourited: boolean; favourited: boolean;
reblogged: boolean; reblogged: boolean;
ipfs_cid: string | null; ipfs_cid: string | null;

View file

@ -2,12 +2,13 @@ import { BACKEND_URL } from "@/constants"
import { createDidFromEthereumAddress } from "@/utils/did" import { createDidFromEthereumAddress } from "@/utils/did"
import { http } from "./common" import { http } from "./common"
import { Post } from "./posts" import { Post, Tag } from "./posts"
import { Profile } from "./users" import { Profile } from "./users"
interface SearchResults { interface SearchResults {
accounts: Profile[]; accounts: Profile[];
statuses: Post[]; statuses: Post[];
hashtags: Tag[];
} }
export async function getSearchResults( export async function getSearchResults(

View file

@ -6,6 +6,7 @@
<template v-if="errorMessage">{{ errorMessage }}</template> <template v-if="errorMessage">{{ errorMessage }}</template>
<template v-else-if="profiles.length > 0">{{ profiles.length }} people</template> <template v-else-if="profiles.length > 0">{{ profiles.length }} people</template>
<template v-else-if="posts.length > 0">{{ posts.length }} posts</template> <template v-else-if="posts.length > 0">{{ posts.length }} posts</template>
<template v-else-if="tags.length > 0">{{ tags.length }} tags</template>
<template v-else>No results</template> <template v-else>No results</template>
</div> </div>
<div v-if="!isLoading" class="search-result-list"> <div v-if="!isLoading" class="search-result-list">
@ -24,6 +25,14 @@
:in-thread="false" :in-thread="false"
:key="post.id" :key="post.id"
></post> ></post>
<router-link
class="search-result tag"
v-for="tag in tags"
:key="tag.name"
:to="{ name: 'tag', params: { tagName: tag.name } }"
>
#{{ tag.name }}
</router-link>
</div> </div>
</template> </template>
</sidebar-layout> </sidebar-layout>
@ -34,7 +43,7 @@ import { onMounted } from "vue"
import { $ref } from "vue/macros" import { $ref } from "vue/macros"
import { useRoute } from "vue-router" import { useRoute } from "vue-router"
import { Post as PostObject } from "@/api/posts" import { Post as PostObject, Tag } from "@/api/posts"
import { getSearchResults } from "@/api/search" import { getSearchResults } from "@/api/search"
import { Profile } from "@/api/users" import { Profile } from "@/api/users"
import Loader from "@/components/Loader.vue" import Loader from "@/components/Loader.vue"
@ -52,6 +61,7 @@ let errorMessage = $ref("")
let profiles = $ref<Profile[]>([]) let profiles = $ref<Profile[]>([])
let posts = $ref<PostObject[]>([]) let posts = $ref<PostObject[]>([])
let tags = $ref<Tag[]>([])
onMounted(async () => { onMounted(async () => {
const q = route.query?.q const q = route.query?.q
@ -65,6 +75,7 @@ onMounted(async () => {
) )
profiles = results.accounts profiles = results.accounts
posts = results.statuses posts = results.statuses
tags = results.hashtags
} catch (error: any) { } catch (error: any) {
errorMessage = error.message errorMessage = error.message
} }
@ -104,4 +115,8 @@ onMounted(async () => {
border-bottom: none; border-bottom: none;
} }
} }
.tag {
padding: $block-inner-padding;
}
</style> </style>