forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): 今日誕生日のフォロー中のユーザーを一覧表示できるウィジェットを追加 (misskey-dev#12450)
* (add) 今日誕生日のフォロイー一覧表示 * Update Changelog * Update Changelog * 実装漏れ * create index * (fix) index
- Loading branch information
1 parent
7df163b
commit f4736bd
Showing
8 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/backend/migration/1700902349231-add-bday-index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
packages/frontend/src/widgets/WidgetBirthdayFollowings.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
|
||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters