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: allow searching for statuses #632

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions components/search/SearchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const onActivate = () => {
<CommonScrollIntoView as="RouterLink" :active="active" :to="result.to" py2 block px2 :aria-selected="active" :class="{ 'bg-active': active }" hover:bg-active @click="() => onActivate()">
<SearchHashtagInfo v-if="result.type === 'hashtag'" :hashtag="result.hashtag" />
<AccountInfo v-else-if="result.type === 'account'" :account="result.account" />
<StatusCard v-else-if="result.type === 'status'" :status="result.status" :actions="false" :show-reply-to="false" />
<div v-else-if="result.type === 'action'" text-center>
{{ result.action!.label }}
</div>
Expand Down
7 changes: 4 additions & 3 deletions components/search/SearchWidget.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
const query = ref('')
const { accounts, hashtags, loading } = useSearch(query)
const { accounts, hashtags, loading, statuses } = useSearch(query)
const index = ref(0)

const { t } = useI18n()
Expand All @@ -13,8 +13,9 @@ const results = computed(() => {
return []

const results = [
...hashtags.value.slice(0, 3).map(hashtag => ({ type: 'hashtag', hashtag, to: `/tags/${hashtag.name}` })),
...accounts.value.map(account => ({ type: 'account', account, to: `/@${account.acct}` })),
...hashtags.value.slice(0, 3).map(hashtag => ({ type: 'hashtag', hashtag, to: getTagRoute(hashtag.name) })),
...accounts.value.map(account => ({ type: 'account', account, to: getAccountRoute(account) })),
...statuses.value.map(status => ({ type: 'status', status, to: getStatusRoute(status) })),

// Disable until search page is implemented
// {
Expand Down
5 changes: 3 additions & 2 deletions components/search/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Account } from 'masto'
import type { Account, Status } from 'masto'

export interface SearchResult {
type: 'account' | 'hashtag' | 'action'
type: 'account' | 'hashtag' | 'action' | 'status'
to: string
label?: string
account?: Account
status?: Status
hashtag?: any
action?: {
label: string
Expand Down
2 changes: 1 addition & 1 deletion components/status/StatusCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const isDM = $computed(() => status.visibility === 'direct')
<StatusEditIndicator :status="status" inline />
</div>
</div>
<StatusActionsMore :status="status" mr--2 />
<StatusActionsMore v-if="actions !== false" :status="status" mr--2 />
</div>
<StatusContent :status="status" :context="context" mb2 :class="{ mt2: isDM }" />
<div>
Expand Down
10 changes: 10 additions & 0 deletions composables/masto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export function getStatusRoute(status: Status) {
})
}

export function getTagRoute(tag: string) {
return useRouter().resolve({
name: 'tag',
params: {
server: currentServer.value,
tag,
},
})
}

export function getStatusPermalinkRoute(status: Status) {
return status.url ? withoutProtocol(status.url) : null
}
Expand Down
3 changes: 2 additions & 1 deletion composables/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface UseSearchOptions {

export function useSearch(query: MaybeRef<string>, options?: UseSearchOptions) {
const done = ref(false)
const masto = useMasto()
const loading = ref(false)
const statuses = ref<Status[]>([])
const accounts = ref<Account[]>([])
Expand All @@ -24,7 +25,7 @@ export function useSearch(query: MaybeRef<string>, options?: UseSearchOptions) {
* Based on the source it seems like modifying the params when calling next would result in a new search,
* but that doesn't seem to be the case. So instead we just create a new paginator with the new params.
*/
paginator = useMasto().search({ q: unref(query), type: unref(options?.type) })
paginator = masto.search({ q: unref(query), resolve: true, type: unref(options?.type) })
const nextResults = await paginator.next()

done.value = nextResults.done || false
Expand Down
4 changes: 4 additions & 0 deletions pages/[[server]]/tags/[tag].vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script setup lang="ts">
definePageMeta({
name: 'tag',
})

const params = useRoute().params
const tagName = $(computedEager(() => params.tag as string))

Expand Down