diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-04-03 22:04:11 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-04-03 22:06:37 -0400 |
| commit | 3eeb53ff63a5e776327a9fd067d0c74b9dc727f4 (patch) | |
| tree | 9b4ee01e1aaf1ab7b4a24ab897ccf14e1aa19a40 /packages/frontend/src/utility | |
| parent | refactor bubble-timeline.ts to match global-timeline.ts and local-timeline.ts (diff) | |
| parent | New Crowdin updates (#15740) (diff) | |
| download | sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.tar.gz sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.tar.bz2 sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.zip | |
Merge branch 'misskey-develop' into merge/2025-03-24
# Conflicts:
# package.json
# packages/backend/src/core/AccountMoveService.ts
# packages/frontend/src/components/MkDateSeparatedList.vue
# packages/misskey-js/etc/misskey-js.api.md
# pnpm-lock.yaml
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/timeline-date-separate.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/packages/frontend/src/utility/timeline-date-separate.ts b/packages/frontend/src/utility/timeline-date-separate.ts new file mode 100644 index 0000000000..e1bc9790b9 --- /dev/null +++ b/packages/frontend/src/utility/timeline-date-separate.ts @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { computed } from 'vue'; +import type { Ref } from 'vue'; + +export function getDateText(dateInstance: Date) { + const date = dateInstance.getDate(); + const month = dateInstance.getMonth() + 1; + return `${month.toString()}/${date.toString()}`; +} + +export type DateSeparetedTimelineItem<T> = { + id: string; + type: 'item'; + data: T; +} | { + id: string; + type: 'date'; + prev: Date; + prevText: string; + next: Date; + nextText: string; +}; + +export function makeDateSeparatedTimelineComputedRef<T extends { id: string; createdAt: string; }>(items: Ref<T[]>) { + return computed<DateSeparetedTimelineItem<T>[]>(() => { + const tl: DateSeparetedTimelineItem<T>[] = []; + for (let i = 0; i < items.value.length; i++) { + const item = items.value[i]; + + const date = new Date(item.createdAt); + const nextDate = items.value[i + 1] ? new Date(items.value[i + 1].createdAt) : null; + + tl.push({ + id: item.id, + type: 'item', + data: item, + }); + + if ( + i !== items.value.length - 1 && + nextDate != null && ( + date.getFullYear() !== nextDate.getFullYear() || + date.getMonth() !== nextDate.getMonth() || + date.getDate() !== nextDate.getDate() + ) + ) { + tl.push({ + id: `date-${item.id}`, + type: 'date', + prev: date, + prevText: getDateText(date), + next: nextDate, + nextText: getDateText(nextDate), + }); + } + } + return tl; + }); +} |