2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-05-11 11:10:34 +02:00
|
|
|
<template>
|
|
|
|
<div class="_gaps">
|
|
|
|
<div class="_gaps">
|
2023-12-27 23:58:32 +01:00
|
|
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search" @enter="search">
|
2023-05-11 11:10:34 +02:00
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
|
|
|
</MkInput>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkRadios v-model="searchOrigin" @update:modelValue="search()">
|
2023-05-11 11:10:34 +02:00
|
|
|
<option value="combined">{{ i18n.ts.all }}</option>
|
|
|
|
<option value="local">{{ i18n.ts.local }}</option>
|
|
|
|
<option value="remote">{{ i18n.ts.remote }}</option>
|
|
|
|
</MkRadios>
|
|
|
|
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<MkFoldableSection v-if="userPagination">
|
|
|
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
|
|
|
<MkUserList :key="key" :pagination="userPagination"/>
|
|
|
|
</MkFoldableSection>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-07-30 08:51:08 +02:00
|
|
|
import { ref, toRef } from 'vue';
|
|
|
|
import type { Endpoints } from 'misskey-js';
|
|
|
|
import type { Paging } from '@/components/MkPagination.vue';
|
2023-05-11 11:10:34 +02:00
|
|
|
import MkUserList from '@/components/MkUserList.vue';
|
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
2023-05-11 11:10:34 +02:00
|
|
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2024-01-30 13:07:34 +01:00
|
|
|
import { useRouter } from '@/router/supplier.js';
|
2023-05-11 11:10:34 +02:00
|
|
|
|
2024-07-30 08:51:08 +02:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
query?: string,
|
|
|
|
origin?: Endpoints['users/search']['req']['origin'],
|
|
|
|
}>(), {
|
|
|
|
query: '',
|
|
|
|
origin: 'combined',
|
|
|
|
});
|
|
|
|
|
2023-05-11 11:10:34 +02:00
|
|
|
const router = useRouter();
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const key = ref('');
|
2024-07-30 08:51:08 +02:00
|
|
|
const searchQuery = ref(toRef(props, 'query').value);
|
|
|
|
const searchOrigin = ref(toRef(props, 'origin').value);
|
|
|
|
const userPagination = ref<Paging>();
|
2023-05-11 11:10:34 +02:00
|
|
|
|
|
|
|
async function search() {
|
2023-12-07 06:42:09 +01:00
|
|
|
const query = searchQuery.value.toString().trim();
|
2023-05-11 11:10:34 +02:00
|
|
|
|
|
|
|
if (query == null || query === '') return;
|
|
|
|
|
2024-07-30 08:51:08 +02:00
|
|
|
//#region AP lookup
|
2023-05-11 11:10:34 +02:00
|
|
|
if (query.startsWith('https://')) {
|
2024-01-04 10:32:46 +01:00
|
|
|
const promise = misskeyApi('ap/show', {
|
2023-05-11 11:10:34 +02:00
|
|
|
uri: query,
|
|
|
|
});
|
|
|
|
|
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
|
|
|
|
|
|
|
const res = await promise;
|
|
|
|
|
|
|
|
if (res.type === 'User') {
|
|
|
|
router.push(`/@${res.object.username}@${res.object.host}`);
|
|
|
|
} else if (res.type === 'Note') {
|
|
|
|
router.push(`/notes/${res.object.id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2024-07-30 08:51:08 +02:00
|
|
|
//#endregion
|
2023-05-11 11:10:34 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
userPagination.value = {
|
2023-05-11 11:10:34 +02:00
|
|
|
endpoint: 'users/search',
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
2023-07-08 10:41:52 +02:00
|
|
|
query: query,
|
2023-12-07 06:42:09 +01:00
|
|
|
origin: searchOrigin.value,
|
2023-05-11 11:10:34 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
key.value = query;
|
2023-05-11 11:10:34 +02:00
|
|
|
}
|
|
|
|
</script>
|