-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: marie and other Sharkey contributors, and esurio | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
--> | ||
<template> | ||
<MkWindow ref="window" :initialWidth="600" :initialHeight="450" :canResize="true" @closed="emit('closed')"> | ||
<template #header> | ||
<i class="ti ti-zoom" style="margin-right: 0.5em;"></i> | ||
<b>{{ i18n.ts.searchResult }}</b> | ||
</template> | ||
<MkNotes :key="props.noteKey" :pagination="props.notePagination"/> | ||
</MkWindow> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { } from 'vue'; | ||
import type { Paging } from '@/components/MkPagination.vue'; | ||
import MkNotes from '@/components/MkNotes.vue'; | ||
import MkWindow from '@/components/MkWindow.vue'; | ||
import { i18n } from '@/i18n.js'; | ||
const props = defineProps<{ | ||
noteKey: string | number | symbol | undefined; | ||
notePagination: Paging; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(ev: 'closed'): void; | ||
}>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: marie and other Sharkey contributors, and esurio | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
--> | ||
|
||
<template> | ||
<MkContainer :showHeader="widgetProps.showHeader" :class="$style.skwSearch"> | ||
<MkInput v-model="searchQuery" :large="true" type="search" @keydown="onInputKeydown"> | ||
<template #suffix> | ||
<button :class="$style.searchBtn" @click="search"><i class="ti ti-zoom"></i></button> | ||
</template> | ||
</MkInput> | ||
</MkContainer> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { defineAsyncComponent, ref } from 'vue'; | ||
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; | ||
import MkInput from '@/components/MkInput.vue'; | ||
import MkContainer from '@/components/MkContainer.vue'; | ||
import { i18n } from '@/i18n.js'; | ||
import { misskeyApi } from '@/scripts/misskey-api.js'; | ||
import * as os from '@/os.js'; | ||
import { useRouter } from '@/router/supplier.js'; | ||
import { GetFormResultType } from '@/scripts/form.js'; | ||
const name = 'search'; | ||
const widgetPropsDef = { | ||
showHeader: { | ||
type: 'boolean' as const, | ||
default: false, | ||
}, | ||
}; | ||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>; | ||
const props = defineProps<WidgetComponentProps<WidgetProps>>(); | ||
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>(); | ||
const { widgetProps, configure } = useWidgetPropsManager(name, | ||
widgetPropsDef, | ||
props, | ||
emit, | ||
); | ||
function onInputKeydown(evt: KeyboardEvent) { | ||
if (evt.key === 'Enter') { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
search(); | ||
} | ||
} | ||
const router = useRouter(); | ||
let key = ref(0); | ||
let searchQuery = ref(''); | ||
let notePagination = ref(); | ||
let isLocalOnly = ref(false); | ||
async function search() { | ||
const query = searchQuery.value.toString().trim(); | ||
if (query == null || query === '') return; | ||
if (query.startsWith('https://')) { | ||
const promise = misskeyApi('ap/show', { | ||
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; | ||
} | ||
if (query.match(/^@[a-z0-9_.-]+@[a-z0-9_.-]+$/i)) { | ||
router.push(`/${query}`); | ||
return; | ||
} | ||
if (query.startsWith('#')) { | ||
router.push(`/tags/${encodeURIComponent(query.substring(1))}`); | ||
return; | ||
} | ||
notePagination.value = { | ||
endpoint: 'notes/search', | ||
limit: 10, | ||
params: { | ||
query: searchQuery, | ||
userId: null, | ||
}, | ||
}; | ||
if (isLocalOnly.value) notePagination.value.params.host = '.'; | ||
key.value++; | ||
const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkSearchResultWindow.vue')), { | ||
noteKey: key.value, | ||
notePagination: notePagination.value, | ||
}, { | ||
closed: () => dispose(), | ||
}); | ||
} | ||
defineExpose<WidgetComponentExpose>({ | ||
name, | ||
configure, | ||
id: props.widget ? props.widget.id : null, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.skwSearch { | ||
border-radius: var(--radius-sm) !important; | ||
} | ||
.searchBtn { | ||
position: relative; | ||
z-index: 2; | ||
margin: 0 auto; | ||
border: none; | ||
background: none; | ||
pointer-events: auto; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters