2022-06-29 23:28:52 +09:00
|
|
|
<template>
|
2022-06-30 10:53:40 +09:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :show-header="false" class="mkw-instance-cloud">
|
2022-06-29 23:28:52 +09:00
|
|
|
<div class="">
|
|
|
|
<MkTagCloud v-if="activeInstances">
|
2022-07-07 20:19:50 +09:00
|
|
|
<li v-for="instance in activeInstances" :key="instance.id">
|
2022-06-29 23:28:52 +09:00
|
|
|
<a @click.prevent="onInstanceClick(instance)">
|
2023-02-11 07:46:08 +09:00
|
|
|
<img style="width: 32px;" :src="getInstanceIcon(instance)">
|
2022-06-29 23:28:52 +09:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</MkTagCloud>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-12-17 11:28:05 +09:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentProps } from './widget';
|
|
|
|
import type { Widget, WidgetComponentExpose } from './widget';
|
|
|
|
import type { GetFormResultType } from '@/scripts/form';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-08-31 00:24:33 +09:00
|
|
|
import MkTagCloud from '@/components/MkTagCloud.vue';
|
2022-06-29 23:28:52 +09:00
|
|
|
import * as os from '@/os';
|
|
|
|
import { useInterval } from '@/scripts/use-interval';
|
2023-02-11 07:46:08 +09:00
|
|
|
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy';
|
2022-06-29 23:28:52 +09:00
|
|
|
|
|
|
|
const name = 'instanceCloud';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
let cloud = $ref<InstanceType<typeof MkTagCloud> | null>();
|
|
|
|
let activeInstances = $shallowRef(null);
|
|
|
|
|
|
|
|
function onInstanceClick(i) {
|
|
|
|
os.pageWindow(`/instance-info/${i.host}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
useInterval(() => {
|
|
|
|
os.api('federation/instances', {
|
|
|
|
sort: '+lastCommunicatedAt',
|
|
|
|
limit: 25,
|
|
|
|
}).then(res => {
|
|
|
|
activeInstances = res;
|
|
|
|
if (cloud) cloud.update();
|
|
|
|
});
|
|
|
|
}, 1000 * 60 * 3, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
2023-02-11 07:46:08 +09:00
|
|
|
function getInstanceIcon(instance): string {
|
|
|
|
return getProxiedImageUrlNullable(instance.iconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? '/client-assets/dummy.png';
|
|
|
|
}
|
|
|
|
|
2022-06-29 23:28:52 +09:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|