83 lines
1.7 KiB
Vue
83 lines
1.7 KiB
Vue
<template>
|
|
<div>
|
|
<Loading v-if="loading" />
|
|
<AdaptativeList v-if="!loading">
|
|
<NcListItem v-for="feed in feeds"
|
|
:key="feed.link"
|
|
:details="moment(feed.fetchedAtUnix*1000).fromNow()"
|
|
:name="feed.title"
|
|
:to="toUrl(feed.link)">
|
|
<template #icon>
|
|
<NcAvatar :display-name="feed.author"
|
|
:is-no-user="true"
|
|
:url="feed.imageUrl" />
|
|
</template>
|
|
<template #subname>
|
|
{{ feed.author }}
|
|
</template>
|
|
</NcListItem>
|
|
</AdaptativeList>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { NcAvatar, NcListItem } from '@nextcloud/vue'
|
|
import AdaptativeList from '../Atoms/AdaptativeList.vue'
|
|
import Loading from '../Atoms/Loading.vue'
|
|
import axios from '@nextcloud/axios'
|
|
import { debounce } from '../../utils/debounce.js'
|
|
import { generateUrl } from '@nextcloud/router'
|
|
import moment from '@nextcloud/moment'
|
|
import { showError } from '@nextcloud/dialogs'
|
|
|
|
export default {
|
|
name: 'Search',
|
|
components: {
|
|
AdaptativeList,
|
|
Loading,
|
|
NcAvatar,
|
|
NcListItem,
|
|
},
|
|
props: {
|
|
value: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
feeds: [],
|
|
loading: false,
|
|
}
|
|
},
|
|
watch: {
|
|
value() {
|
|
this.search()
|
|
},
|
|
},
|
|
methods: {
|
|
moment,
|
|
search: debounce(async function value() {
|
|
try {
|
|
this.loading = true
|
|
const currentSearch = this.value
|
|
const feeds = await axios.get(generateUrl('/apps/repod/search?value={value}', { value: currentSearch }))
|
|
if (currentSearch === this.value) {
|
|
this.feeds = feeds.data
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
showError(t('repod', 'Could not fetch search results'))
|
|
} finally {
|
|
if (this.feeds) {
|
|
this.loading = false
|
|
}
|
|
}
|
|
}, 200),
|
|
toUrl(url) {
|
|
return `/${btoa(url)}`
|
|
},
|
|
},
|
|
}
|
|
</script>
|