2022-11-25 22:21:02 +09:00
|
|
|
<script setup lang="ts">
|
2022-11-26 15:55:54 +09:00
|
|
|
import type { Account } from 'masto'
|
2022-12-18 07:15:41 +09:00
|
|
|
import CommonScrollIntoView from '../common/CommonScrollIntoView.vue'
|
2022-11-26 15:55:54 +09:00
|
|
|
|
2022-11-25 22:21:02 +09:00
|
|
|
const { items, command } = defineProps<{
|
2022-11-26 15:55:54 +09:00
|
|
|
items: Account[]
|
2022-11-25 22:21:02 +09:00
|
|
|
command: Function
|
2022-11-27 15:34:38 +09:00
|
|
|
isPending?: boolean
|
2022-11-25 22:21:02 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
let selectedIndex = $ref(0)
|
|
|
|
|
|
|
|
watch(items, () => {
|
|
|
|
selectedIndex = 0
|
|
|
|
})
|
|
|
|
|
|
|
|
function onKeyDown(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'ArrowUp') {
|
|
|
|
selectedIndex = ((selectedIndex + items.length) - 1) % items.length
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else if (event.key === 'ArrowDown') {
|
|
|
|
selectedIndex = (selectedIndex + 1) % items.length
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else if (event.key === 'Enter') {
|
|
|
|
selectItem(selectedIndex)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectItem(index: number) {
|
|
|
|
const item = items[index]
|
|
|
|
if (item)
|
2022-11-26 15:55:54 +09:00
|
|
|
command({ id: item.acct })
|
2022-11-25 22:21:02 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
onKeyDown,
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-27 15:34:38 +09:00
|
|
|
<div v-if="isPending || items.length" relative bg-base text-base shadow border="~ base rounded" text-sm py-2 overflow-x-hidden overflow-y-auto max-h-100>
|
|
|
|
<template v-if="isPending">
|
|
|
|
<div flex gap-1 items-center p2 animate-pulse>
|
|
|
|
<div i-ri:loader-2-line animate-spin />
|
|
|
|
<span>Fetching...</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-11-25 22:21:02 +09:00
|
|
|
<template v-if="items.length">
|
2022-12-18 07:15:41 +09:00
|
|
|
<CommonScrollIntoView
|
|
|
|
v-for="(item, index) in items" :key="index"
|
|
|
|
:active="index === selectedIndex"
|
|
|
|
as="button"
|
2022-11-27 05:41:18 +09:00
|
|
|
:class="index === selectedIndex ? 'bg-active' : 'text-secondary'"
|
2022-11-25 22:21:02 +09:00
|
|
|
block m0 w-full text-left px2 py1
|
|
|
|
@click="selectItem(index)"
|
|
|
|
>
|
2022-11-27 12:34:55 +09:00
|
|
|
<AccountInfo :account="item" />
|
2022-12-18 07:15:41 +09:00
|
|
|
</CommonScrollIntoView>
|
2022-11-25 22:21:02 +09:00
|
|
|
</template>
|
|
|
|
</div>
|
2022-11-27 15:34:38 +09:00
|
|
|
<div v-else />
|
2022-11-25 22:21:02 +09:00
|
|
|
</template>
|