-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend): 今日誕生日のフォロー中のユーザーを一覧表示できるウィジェットを追加 #12450
Changes from all commits
53051b9
d97f9a1
97fc5f3
5af3785
684c8d9
43b08be
22ae48c
b0ec255
f79f1a5
934e55f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export class AddBdayIndex1700902349231 { | ||
name = 'AddBdayIndex1700902349231' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`CREATE INDEX "IDX_de22cd2b445eee31ae51cdbe99" ON "user_profile" (SUBSTR("birthday", 6, 5))`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_de22cd2b445eee31ae51cdbe99"`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
--> | ||
|
||
<template> | ||
<MkContainer :showHeader="widgetProps.showHeader" class="mkw-bdayfollowings"> | ||
<template #icon><i class="ti ti-cake"></i></template> | ||
<template #header>{{ i18n.ts._widgets.birthdayFollowings }}</template> | ||
|
||
<div :class="$style.bdayFRoot"> | ||
<MkLoading v-if="fetching"/> | ||
<div v-else-if="users.length > 0" :class="$style.bdayFGrid"> | ||
<MkAvatar v-for="user in users" :key="user.id" :user="user.followee" link preview></MkAvatar> | ||
</div> | ||
<div v-else :class="$style.bdayFFallback"> | ||
<img :src="infoImageUrl" class="_ghost" :class="$style.bdayFFallbackImage"/> | ||
<div>{{ i18n.ts.nothing }}</div> | ||
</div> | ||
</div> | ||
</MkContainer> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from 'vue'; | ||
import * as Misskey from 'misskey-js'; | ||
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; | ||
import { GetFormResultType } from '@/scripts/form.js'; | ||
import MkContainer from '@/components/MkContainer.vue'; | ||
import * as os from '@/os.js'; | ||
import { useInterval } from '@/scripts/use-interval.js'; | ||
import { i18n } from '@/i18n.js'; | ||
import { infoImageUrl } from '@/instance.js'; | ||
import { $i } from '@/account.js'; | ||
|
||
const name = i18n.ts._widgets.birthdayFollowings; | ||
|
||
const widgetPropsDef = { | ||
showHeader: { | ||
type: 'boolean' as const, | ||
default: true, | ||
}, | ||
}; | ||
|
||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>; | ||
|
||
const props = defineProps<WidgetComponentProps<WidgetProps>>(); | ||
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>(); | ||
|
||
const { widgetProps, configure } = useWidgetPropsManager(name, | ||
widgetPropsDef, | ||
props, | ||
emit, | ||
); | ||
|
||
const users = ref<Misskey.entities.FollowingFolloweePopulated[]>([]); | ||
const fetching = ref(true); | ||
let lastFetchedAt = '1970-01-01'; | ||
|
||
const fetch = () => { | ||
if (!$i) { | ||
users.value = []; | ||
fetching.value = false; | ||
return; | ||
} | ||
|
||
const lfAtD = new Date(lastFetchedAt); | ||
lfAtD.setHours(0, 0, 0, 0); | ||
const now = new Date(); | ||
now.setHours(0, 0, 0, 0); | ||
|
||
if (now > lfAtD) { | ||
os.api('users/following', { | ||
limit: 18, | ||
birthday: now.toISOString(), | ||
userId: $i.id, | ||
}).then(res => { | ||
users.value = res; | ||
fetching.value = false; | ||
}); | ||
|
||
lastFetchedAt = now.toISOString(); | ||
} | ||
}; | ||
|
||
useInterval(fetch, 1000 * 60, { | ||
immediate: true, | ||
afterMounted: true, | ||
}); | ||
Comment on lines
+86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 誕生日は1日に1回しか変わらないので60秒おきにfetchする理由はなさそう There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これ日付変わるのを検知しないと実際にはfetchしないようになっています |
||
|
||
defineExpose<WidgetComponentExpose>({ | ||
name, | ||
configure, | ||
id: props.widget ? props.widget.id : null, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.bdayFRoot { | ||
overflow: hidden; | ||
min-height: calc(calc(calc(50px * 3) - 8px) + calc(var(--margin) * 2)); | ||
} | ||
.bdayFGrid { | ||
display: grid; | ||
grid-template-columns: repeat(6, 42px); | ||
grid-template-rows: repeat(3, 42px); | ||
place-content: center; | ||
gap: 8px; | ||
margin: var(--margin) auto; | ||
} | ||
|
||
.bdayFFallback { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.bdayFFallbackImage { | ||
height: 96px; | ||
width: auto; | ||
max-width: 90%; | ||
margin-bottom: 8px; | ||
border-radius: var(--radius); | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これタイムゾーン吹き飛ぶせいで UTC 以外(e.g. JST)だと一日ズレる