summaryrefslogtreecommitdiff
path: root/packages/client/src/ui/_common_/statusbar-federation.vue
blob: 7d4f0d61667a1bd48f5431b5405f5b9d9b3e15b4 (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
103
<template>
<span v-if="!fetching" class="nmidsaqw">
	<template v-if="display === 'marquee'">
		<transition name="change" mode="default">
			<MarqueeText :key="key" :duration="marqueeDuration" :reverse="marqueeReverse">
				<span v-for="instance in instances" :key="instance.id" class="item" :class="{ colored }" :style="{ background: colored ? instance.themeColor : null }">
					<img v-if="instance.iconUrl" class="icon" :src="instance.iconUrl" alt=""/>
					<MkA :to="`/instance-info/${instance.host}`" class="host _monospace">
						{{ instance.host }}
					</MkA>
					<span class="divider"></span>
				</span>
			</MarqueeText>
		</transition>
	</template>
	<template v-else-if="display === 'oneByOne'">
		<!-- TODO -->
	</template>
</span>
</template>

<script lang="ts" setup>
import { computed, defineAsyncComponent, ref, toRef, watch } from 'vue';
import * as misskey from 'misskey-js';
import MarqueeText from '@/components/MkMarquee.vue';
import * as os from '@/os';
import { useInterval } from '@/scripts/use-interval';
import { getNoteSummary } from '@/scripts/get-note-summary';
import { notePage } from '@/filters/note';

const props = defineProps<{
	display?: 'marquee' | 'oneByOne';
	colored?: boolean;
	marqueeDuration?: number;
	marqueeReverse?: boolean;
	oneByOneInterval?: number;
	refreshIntervalSec?: number;
}>();

const instances = ref<misskey.entities.Instance[]>([]);
const fetching = ref(true);
let key = $ref(0);

const tick = () => {
	os.api('federation/instances', {
		sort: '+lastCommunicatedAt',
		limit: 30,
	}).then(res => {
		instances.value = res;
		fetching.value = false;
		key++;
	});
};

useInterval(tick, Math.max(5000, props.refreshIntervalSec * 1000), {
	immediate: true,
	afterMounted: true,
});
</script>

<style lang="scss" scoped>
.change-enter-active, .change-leave-active {
	position: absolute;
	top: 0;
  transition: all 1s ease;
}
.change-enter-from {
  opacity: 0;
	transform: translateY(-100%);
}
.change-leave-to {
  opacity: 0;
	transform: translateY(100%);
}

.nmidsaqw {
	display: inline-block;
	position: relative;

	::v-deep(.item) {
		display: inline-block;
		vertical-align: bottom;
		margin-right: 5em;

		> .icon {
			display: inline-block;
			height: var(--height);
			aspect-ratio: 1;
			vertical-align: bottom;
			margin-right: 1em;
		}

		> .host {
			vertical-align: bottom;
		}

		&.colored {
			padding-right: 1em;
			color: #fff;
		}
	}
}
</style>