summaryrefslogtreecommitdiff
path: root/packages/frontend/src/pages/welcome.timeline.vue
blob: 16d558cc91626cc8068ef6c66ea7b7c501383505 (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
98
99
100
101
102
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root" class="_gaps">
	<div
		ref="notesMainContainerEl"
		class="_gaps"
		:class="[$style.scrollBoxMain, { [$style.scrollIntro]: (scrollState === 'intro'), [$style.scrollLoop]: (scrollState === 'loop') }]"
		@animationend="changeScrollState"
	>
		<XNote v-for="note in notes" :key="`${note.id}_1`" :class="$style.note" :note="note"/>
	</div>
	<div v-if="isScrolling" class="_gaps" :class="[$style.scrollBoxSub, { [$style.scrollIntro]: (scrollState === 'intro'), [$style.scrollLoop]: (scrollState === 'loop') }]">
		<XNote v-for="note in notes" :key="`${note.id}_2`" :class="$style.note" :note="note"/>
	</div>
</div>
</template>

<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { onUpdated, ref, shallowRef } from 'vue';
import XNote from '@/pages/welcome.timeline.note.vue';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import { getScrollContainer } from '@@/js/scroll.js';

const notes = ref<Misskey.entities.Note[]>([]);
const isScrolling = ref(false);
const scrollState = ref<null | 'intro' | 'loop'>(null);
const notesMainContainerEl = shallowRef<HTMLElement>();

misskeyApiGet('notes/featured').then(_notes => {
	notes.value = _notes.filter(n => n.cw == null);
});

function changeScrollState() {
	if (scrollState.value !== 'loop') {
		scrollState.value = 'loop';
	}
}

onUpdated(() => {
	if (!notesMainContainerEl.value) return;
	const container = getScrollContainer(notesMainContainerEl.value);
	const containerHeight = container ? container.clientHeight : window.innerHeight;
	if (notesMainContainerEl.value.offsetHeight > containerHeight) {
		if (scrollState.value === null) {
			scrollState.value = 'intro';
		}
		isScrolling.value = true;
	}
});
</script>

<style lang="scss" module>
@keyframes scrollIntro {
	0% {
		transform: translate3d(0, 0, 0);
	}
	100% {
		transform: translate3d(0, calc(calc(-100% - 128px) - var(--margin)), 0);
	}
}

@keyframes scrollConstant {
	0% {
		transform: translate3d(0, -128px, 0);
	}
	100% {
		transform: translate3d(0, calc(calc(-100% - 128px) - var(--margin)), 0);
	}
}

.root {
	text-align: right;
}

.scrollBoxMain {
	&.scrollIntro {
		animation: scrollIntro 30s linear forwards;
	}
	&.scrollLoop {
		animation: scrollConstant 30s linear infinite;
	}
}

.scrollBoxSub {
	&.scrollIntro {
		animation: scrollIntro 30s linear forwards;
	}
	&.scrollLoop {
		animation: scrollConstant 30s linear infinite;
	}
}

.root:has(.note:hover) .scrollBoxMain,
.root:has(.note:hover) .scrollBoxSub {
	animation-play-state: paused;
}
</style>