summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkPaginationControl.vue
blob: 8eab987d2aadf42f1b39c74cf9cd972cbb4e15de (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root">
	<div :class="$style.control">
		<MkSelect v-model="order" :class="$style.order" :items="[{ label: i18n.ts._order.newest, value: 'newest' }, { label: i18n.ts._order.oldest, value: 'oldest' }]">
			<template #prefix><i class="ti ti-arrows-sort"></i></template>
		</MkSelect>
		<MkButton v-if="canSearch" v-tooltip="i18n.ts.search" iconOnly transparent rounded :active="searchOpened" @click="searchOpened = !searchOpened"><i class="ti ti-search"></i></MkButton>
		<MkButton v-if="canFilter" v-tooltip="i18n.ts.filter" iconOnly transparent rounded :active="filterOpened" @click="filterOpened = !filterOpened"><i class="ti ti-filter"></i></MkButton>
		<MkButton v-tooltip="i18n.ts.dateAndTime" iconOnly transparent rounded :active="date != null" @click="date = date == null ? Date.now() : null"><i class="ti ti-calendar-clock"></i></MkButton>
		<MkButton v-tooltip="i18n.ts.reload" iconOnly transparent rounded @click="emit('reload')"><i class="ti ti-refresh"></i></MkButton>
	</div>

	<MkInput
		v-if="searchOpened"
		v-model="q"
		type="search"
		debounce
	>
		<template #label>{{ i18n.ts.search }}</template>
		<template #prefix><i class="ti ti-search"></i></template>
	</MkInput>

	<MkInput
		v-if="date != null"
		type="date"
		:modelValue="formatDateTimeString(new Date(date), 'yyyy-MM-dd')"
		@update:modelValue="date = new Date($event).getTime()"
	>
	</MkInput>

	<slot v-if="filterOpened"></slot>
</div>
</template>

<script lang="ts" setup generic="T extends PagingCtx">
import { ref, watch } from 'vue';
import type { PagingCtx } from '@/composables/use-pagination.js';
import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
import MkSelect from '@/components/MkSelect.vue';
import MkInput from '@/components/MkInput.vue';
import { formatDateTimeString } from '@/utility/format-time-string.js';

const props = withDefaults(defineProps<{
	canSearch?: boolean;
	canFilter?: boolean;
	filterOpened?: boolean;
}>(), {
	canSearch: false,
	canFilter: false,
	filterOpened: false,
});

const emit = defineEmits<{
	(ev: 'reload'): void;
}>();

const searchOpened = ref(false);
const filterOpened = ref(props.filterOpened);

const order = defineModel<'newest' | 'oldest'>('order', {
	default: 'newest',
});

const date = defineModel<number | null>('date', {
	default: null,
});

const q = defineModel<string | null>('q', {
	default: null,
});
</script>

<style lang="scss" module>
.root {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: 10px;
}

.control {
	display: flex;
	align-items: center;
	gap: 4px;
}

.order {
	flex: 1;
	margin-right: 6px;
}
</style>