vikunja-frontend/src/components/tasks/partials/listSearch.vue

81 lines
1.9 KiB
Vue
Raw Normal View History

2020-04-18 12:39:56 +00:00
<template>
2022-07-20 19:15:35 +00:00
<Multiselect
class="control is-expanded"
:placeholder="$t('list.search')"
@search="findLists"
:search-results="foundLists"
@select="select"
label="title"
v-model="list"
:select-placeholder="$t('list.searchSelect')"
2020-04-18 12:39:56 +00:00
>
2022-10-17 11:14:07 +00:00
<template #searchResult="{option}">
<span class="list-namespace-title search-result">{{ namespace((option as IList).namespaceId) }} ></span>
{{ (option as IList).title }}
</template>
2022-07-20 19:15:35 +00:00
</Multiselect>
2020-04-18 12:39:56 +00:00
</template>
<script lang="ts" setup>
import {reactive, ref, watch} from 'vue'
import type {PropType} from 'vue'
import {useI18n} from 'vue-i18n'
2022-09-06 09:36:01 +00:00
import ListModel from '@/models/list'
import type {IList} from '@/modelTypes/IList'
import Multiselect from '@/components/input/multiselect.vue'
import {useListStore} from '@/stores/lists'
2022-09-02 09:15:29 +00:00
import {useNamespaceStore} from '@/stores/namespaces'
2022-10-17 11:14:07 +00:00
import type { INamespace } from '@/modelTypes/INamespace'
2020-04-18 12:39:56 +00:00
const props = defineProps({
modelValue: {
2022-07-20 22:42:36 +00:00
type: Object as PropType<IList>,
required: false,
},
})
const emit = defineEmits(['update:modelValue'])
const {t} = useI18n({useScope: 'global'})
2022-07-20 22:42:36 +00:00
const list: IList = reactive(new ListModel())
watch(
() => props.modelValue,
(newList) => Object.assign(list, newList),
{
immediate: true,
deep: true,
},
)
2022-09-02 09:15:29 +00:00
const listStore = useListStore()
const namespaceStore = useNamespaceStore()
const foundLists = ref<IList[]>([])
function findLists(query: string) {
if (query === '') {
select(null)
}
foundLists.value = listStore.searchList(query)
}
2022-07-20 22:42:36 +00:00
function select(l: IList | null) {
if (l === null) {
return
}
Object.assign(list, l)
emit('update:modelValue', list)
}
2022-10-17 11:14:07 +00:00
function namespace(namespaceId: INamespace['id']) {
2022-09-02 09:15:29 +00:00
const namespace = namespaceStore.getNamespaceById(namespaceId)
return namespace !== null
? namespace.title
: t('list.shared')
}
2020-04-18 12:39:56 +00:00
</script>
<style lang="scss" scoped>
.list-namespace-title {
color: var(--grey-500);
}
</style>