1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-21 10:08:19 +09:00
cherrypick/packages/frontend/src/widgets/WidgetInstanceCloud.vue

80 lines
2.2 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
2023-05-19 16:20:53 +09:00
<MkContainer :naked="widgetProps.transparent" :showHeader="false" class="mkw-instance-cloud">
<div class="">
<MkTagCloud v-if="activeInstances">
2022-07-07 20:19:50 +09:00
<li v-for="instance in activeInstances" :key="instance.id">
<a @click.prevent="onInstanceClick(instance)">
<img style="width: 32px;" :src="getInstanceIcon(instance)">
</a>
</li>
</MkTagCloud>
</div>
</MkContainer>
</template>
<script lang="ts" setup>
import { shallowRef } from 'vue';
2023-12-21 11:36:45 +09:00
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
2023-09-19 16:37:43 +09:00
import { GetFormResultType } from '@/scripts/form.js';
import MkContainer from '@/components/MkContainer.vue';
import MkTagCloud from '@/components/MkTagCloud.vue';
2023-09-19 16:37:43 +09:00
import * as os from '@/os.js';
import { useInterval } from '@/scripts/use-interval.js';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js';
const name = 'instanceCloud';
const widgetPropsDef = {
transparent: {
type: 'boolean' as const,
default: false,
},
};
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
2023-05-19 16:20:53 +09:00
const props = defineProps<WidgetComponentProps<WidgetProps>>();
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const { widgetProps, configure } = useWidgetPropsManager(name,
widgetPropsDef,
props,
emit,
);
const cloud = shallowRef<InstanceType<typeof MkTagCloud> | null>();
const activeInstances = shallowRef(null);
function onInstanceClick(i) {
os.pageWindow(`/instance-info/${i.host}`);
}
useInterval(() => {
os.api('federation/instances', {
2023-01-03 09:00:42 +09:00
sort: '+latestRequestReceivedAt',
limit: 25,
}).then(res => {
activeInstances.value = res;
if (cloud.value) cloud.value.update();
});
}, 1000 * 60 * 3, {
immediate: true,
afterMounted: true,
});
function getInstanceIcon(instance): string {
return getProxiedImageUrlNullable(instance.iconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? '/client-assets/dummy.png';
}
defineExpose<WidgetComponentExpose>({
name,
configure,
id: props.widget ? props.widget.id : null,
});
</script>