summaryrefslogtreecommitdiff
path: root/src/client/app/common/views/deck/deck.search-column.vue
blob: ab19bdaab622ea46bb2ee9cb356a9e61109c03e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<template>
<x-column>
	<template #header>
		<fa icon="search"/><span>{{ q }}</span>
	</template>

	<div>
		<x-notes ref="timeline" :make-promise="makePromise" @inited="() => $emit('loaded')"/>
	</div>
</x-column>
</template>

<script lang="ts">
import Vue from 'vue';
import XColumn from './deck.column.vue';
import XNotes from './deck.notes.vue';

const limit = 20;

export default Vue.extend({
	components: {
		XColumn,
		XNotes
	},

	data() {
		return {
			makePromise: cursor => this.$root.api('notes/search', {
				limit: limit + 1,
				offset: cursor ? cursor : undefined,
				query: this.q
			}).then(notes => {
				if (notes.length == limit + 1) {
					notes.pop();
					return {
						notes: notes,
						cursor: cursor ? cursor + limit : limit
					};
				} else {
					return {
						notes: notes,
						more: false
					};
				}
			})
		};
	},

	computed: {
		q(): string {
			return this.$route.query.q;
		}
	},

	watch: {
		$route() {
			this.$refs.timeline.reload();
		}
	},
});
</script>