2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-06-20 11:38:49 +03:00
|
|
|
<MkStickyContainer>
|
2023-03-16 04:56:20 +02:00
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer v-if="tab === 'note'" :content-max="800">
|
|
|
|
<div v-if="notesSearchAvailable" class="_gaps">
|
|
|
|
<div class="_gaps">
|
|
|
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
|
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
|
|
|
</MkInput>
|
|
|
|
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<MkFoldableSection v-if="notePagination">
|
|
|
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
|
|
|
<MkNotes :key="key" :pagination="notePagination"/>
|
|
|
|
</MkFoldableSection>
|
2023-02-25 02:01:21 +02:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
2023-03-16 04:56:20 +02:00
|
|
|
<MkInfo warn>{{ i18n.ts.notesSearchNotAvailable }}</MkInfo>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
<MkSpacer v-else-if="tab === 'user'" :content-max="800">
|
|
|
|
<div class="_gaps">
|
|
|
|
<div class="_gaps">
|
|
|
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
|
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
|
|
|
</MkInput>
|
|
|
|
<MkRadios v-model="searchOrigin" @update:model-value="search()">
|
|
|
|
<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>
|
2023-02-25 02:01:21 +02:00
|
|
|
</div>
|
2022-06-20 11:38:49 +03:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-12 19:21:43 +02:00
|
|
|
<script lang="ts" setup>
|
2023-02-25 02:01:21 +02:00
|
|
|
import { computed, onMounted } from 'vue';
|
2023-02-22 04:00:34 +02:00
|
|
|
import MkNotes from '@/components/MkNotes.vue';
|
2023-02-25 02:01:21 +02:00
|
|
|
import MkUserList from '@/components/MkUserList.vue';
|
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
2023-03-16 04:56:20 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2022-01-12 19:21:43 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 11:38:49 +03:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-01-08 04:15:54 +02:00
|
|
|
import * as os from '@/os';
|
2023-03-16 04:56:20 +02:00
|
|
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
|
|
|
import { $i } from '@/account';
|
|
|
|
import { instance } from '@/instance';
|
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-12 19:21:43 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
query: string;
|
|
|
|
channel?: string;
|
2023-02-25 02:01:21 +02:00
|
|
|
type?: string;
|
|
|
|
origin?: string;
|
2022-01-12 19:21:43 +02:00
|
|
|
}>();
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
let key = $ref('');
|
|
|
|
let tab = $ref('note');
|
2023-02-25 02:01:21 +02:00
|
|
|
let searchQuery = $ref('');
|
|
|
|
let searchOrigin = $ref('combined');
|
2023-03-16 04:56:20 +02:00
|
|
|
let notePagination = $ref();
|
|
|
|
let userPagination = $ref();
|
|
|
|
|
|
|
|
const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes));
|
2023-02-25 02:01:21 +02:00
|
|
|
|
|
|
|
onMounted(() => {
|
2023-03-16 04:56:20 +02:00
|
|
|
tab = props.type ?? 'note';
|
2023-02-25 02:01:21 +02:00
|
|
|
searchQuery = props.query ?? '';
|
|
|
|
searchOrigin = props.origin ?? 'combined';
|
|
|
|
});
|
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
async function search() {
|
2023-02-25 02:01:21 +02:00
|
|
|
const query = searchQuery.toString().trim();
|
|
|
|
|
|
|
|
if (query == null || query === '') return;
|
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
if (tab === 'note') {
|
|
|
|
notePagination = {
|
|
|
|
endpoint: 'notes/search',
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
query: searchQuery,
|
|
|
|
channelId: props.channel,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else if (tab === 'user') {
|
|
|
|
userPagination = {
|
|
|
|
endpoint: 'users/search',
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
query: searchQuery,
|
|
|
|
origin: searchOrigin,
|
|
|
|
},
|
|
|
|
};
|
2023-02-25 02:01:21 +02:00
|
|
|
}
|
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
key = query;
|
|
|
|
}
|
2022-01-12 19:21:43 +02:00
|
|
|
|
2022-06-20 11:38:49 +03:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'note',
|
|
|
|
title: i18n.ts.notes,
|
|
|
|
icon: 'ti ti-pencil',
|
|
|
|
}, {
|
|
|
|
key: 'user',
|
|
|
|
title: i18n.ts.users,
|
|
|
|
icon: 'ti ti-users',
|
|
|
|
}]);
|
2022-06-20 11:38:49 +03:00
|
|
|
|
|
|
|
definePageMetadata(computed(() => ({
|
2023-02-25 02:01:21 +02:00
|
|
|
title: searchQuery ? i18n.t('searchWith', { q: searchQuery }) : i18n.ts.search,
|
2022-12-19 12:01:30 +02:00
|
|
|
icon: 'ti ti-search',
|
2022-06-20 11:38:49 +03:00
|
|
|
})));
|
2020-01-29 21:37:25 +02:00
|
|
|
</script>
|