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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkContainer :style="`height: ${widgetProps.height}px;`" :showHeader="widgetProps.showHeader" :scrollable="true" class="mkw-bdayfollowings">
<template #icon><i class="ti ti-cake"></i></template>
<template #header>{{ i18n.ts._widgets.birthdayFollowings }}</template>
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="fetch"><i class="ti ti-refresh"></i></button></template>
<MkPagination v-slot="{ items }" :paginator="birthdayUsersPaginator">
<div>
<template v-for="(user, i) in items" :key="user.id">
<div
v-if="i > 0 && isSeparatorNeeded(birthdayUsersPaginator.items.value[i - 1].birthday, user.birthday)"
>
<div :class="$style.date">
<span><i class="ti ti-chevron-up"></i> {{ getSeparatorInfo(birthdayUsersPaginator.items.value[i - 1].birthday, user.birthday)?.prevText }}</span>
<span style="height: 1em; width: 1px; background: var(--MI_THEME-divider);"></span>
<span>{{ getSeparatorInfo(birthdayUsersPaginator.items.value[i - 1].birthday, user.birthday)?.nextText }} <i class="ti ti-chevron-down"></i></span>
</div>
<XUser :class="$style.user" :item="user" />
</div>
<XUser v-else :class="$style.user" :item="user" />
</template>
</div>
</MkPagination>
</MkContainer>
</template>
<script lang="ts" setup>
import { computed, markRaw, ref, watch } from 'vue';
import { useLowresTime } from '@/composables/use-lowres-time.js';
import { isSeparatorNeeded, getSeparatorInfo } from '@/utility/timeline-date-separate.js';
import { useWidgetPropsManager } from './widget.js';
import type { WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import type { FormWithDefault, GetFormResultType } from '@/utility/form.js';
import MkContainer from '@/components/MkContainer.vue';
import MkPagination from '@/components/MkPagination.vue';
import XUser from './WidgetBirthdayFollowings.user.vue';
import { i18n } from '@/i18n.js';
import { Paginator } from '@/utility/paginator.js';
const name = 'birthdayFollowings';
const widgetPropsDef = {
showHeader: {
type: 'boolean',
label: i18n.ts._widgetOptions.showHeader,
default: true,
},
height: {
type: 'number' as const,
label: i18n.ts._widgetOptions.height,
default: 300,
},
period: {
type: 'radio' as const,
label: i18n.ts._widgetOptions._birthdayFollowings.period,
default: '3day',
options: [{
value: 'today' as const,
label: i18n.ts.today,
}, {
value: '3day' as const,
label: i18n.tsx.dayX({ day: 3 }),
}, {
value: 'week' as const,
label: i18n.ts.oneWeek,
}, {
value: 'month' as const,
label: i18n.ts.oneMonth,
}],
},
} satisfies FormWithDefault;
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
const props = defineProps<WidgetComponentProps<WidgetProps>>();
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const { widgetProps, configure } = useWidgetPropsManager(
name,
widgetPropsDef,
props,
emit,
);
const now = useLowresTime();
const nextDay = new Date();
nextDay.setHours(24, 0, 0, 0);
let nextDayMidnightTime = nextDay.getTime();
const begin = ref<Date>(new Date());
const end = computed(() => {
switch (widgetProps.period) {
case '3day':
return new Date(begin.value.getTime() + 1000 * 60 * 60 * 24 * 3);
case 'week':
return new Date(begin.value.getTime() + 1000 * 60 * 60 * 24 * 7);
case 'month':
return new Date(begin.value.getTime() + 1000 * 60 * 60 * 24 * 30);
default:
return begin.value;
}
});
const birthdayUsersPaginator = markRaw(new Paginator('users/get-following-birthday-users', {
limit: 18,
offsetMode: true,
computedParams: computed(() => {
if (widgetProps.period === 'today') {
return {
birthday: {
month: begin.value.getMonth() + 1,
day: begin.value.getDate(),
},
};
} else {
return {
birthday: {
begin: {
month: begin.value.getMonth() + 1,
day: begin.value.getDate(),
},
end: {
month: end.value.getMonth() + 1,
day: end.value.getDate(),
},
},
};
}
}),
}));
function fetch() {
const now = new Date();
begin.value = now;
}
const UPDATE_INTERVAL = 1000 * 60;
let nextDayTimer: number | null = null;
watch(now, (to) => {
// 次回更新までに日付が変わる場合、日付が変わった直後に強制的に更新するタイマーをセットする
if (nextDayMidnightTime - to <= UPDATE_INTERVAL) {
if (nextDayTimer != null) {
window.clearTimeout(nextDayTimer);
nextDayTimer = null;
}
nextDayTimer = window.setTimeout(() => {
fetch();
nextDay.setHours(24, 0, 0, 0);
nextDayMidnightTime = nextDay.getTime();
nextDayTimer = null;
}, nextDayMidnightTime - to);
}
}, { immediate: true });
defineExpose<WidgetComponentExpose>({
name,
configure,
id: props.widget ? props.widget.id : null,
});
</script>
<style lang="scss" module>
.root {
container-type: inline-size;
background: var(--MI_THEME-panel);
}
.user {
border-bottom: solid 0.5px var(--MI_THEME-divider);
}
.date {
display: flex;
font-size: 85%;
align-items: center;
justify-content: center;
gap: 1em;
opacity: 0.75;
padding: 8px 8px;
margin: 0 auto;
border-bottom: solid 0.5px var(--MI_THEME-divider);
}
</style>
|