iceshrimp/packages/client/src/components/MkInstanceCardMini.vue

170 lines
3.5 KiB
Vue
Raw Normal View History

2022-06-21 17:55:38 +09:00
<template>
2023-04-08 09:01:42 +09:00
<div
:class="[
$style.root,
{
yellow: instance.isNotResponding,
red: instance.isBlocked,
2023-05-01 06:42:01 +09:00
purple: instance.isSilenced,
2023-04-08 09:01:42 +09:00
gray: instance.isSuspended,
},
]"
>
<img class="icon" :src="getInstanceIcon(instance)" alt="" />
<div class="body">
<span class="host">{{ instance.name ?? instance.host }}</span>
<span class="sub _monospace"
><b>{{ instance.host }}</b> /
{{ instance.softwareName || "?" }}
{{ instance.softwareVersion }}</span
>
</div>
<MkMiniChart v-if="chartValues" class="chart" :src="chartValues" />
2022-06-21 17:55:38 +09:00
</div>
</template>
<script lang="ts" setup>
2023-05-01 06:42:01 +09:00
import * as calckey from "calckey-js";
2023-04-08 09:01:42 +09:00
import MkMiniChart from "@/components/MkMiniChart.vue";
import * as os from "@/os";
import { getProxiedImageUrlNullable } from "@/scripts/media-proxy";
2022-06-21 17:55:38 +09:00
const props = defineProps<{
2023-05-01 06:42:01 +09:00
instance: calckey.entities.Instance;
2022-06-21 17:55:38 +09:00
}>();
2022-06-26 15:55:51 +09:00
let chartValues = $ref<number[] | null>(null);
2022-06-21 17:55:38 +09:00
2023-04-08 09:01:42 +09:00
os.apiGet("charts/instance", {
host: props.instance.host,
limit: 16 + 1,
span: "day",
}).then((res) => {
2022-06-26 15:54:07 +09:00
// 今日のぶんの値はまだ途中の値であり、それも含めると大抵の場合前日よりも下降しているようなグラフになってしまうため今日は弾く
res.requests.received.splice(0, 1);
chartValues = res.requests.received;
2022-06-21 17:55:38 +09:00
});
function getInstanceIcon(instance): string {
2023-04-08 09:01:42 +09:00
return (
getProxiedImageUrlNullable(instance.iconUrl, "preview") ??
getProxiedImageUrlNullable(instance.faviconUrl, "preview") ??
"/client-assets/dummy.png"
);
}
2022-06-21 17:55:38 +09:00
</script>
<style lang="scss" module>
.root {
$bodyTitleHieght: 18px;
$bodyInfoHieght: 16px;
display: flex;
align-items: center;
padding: 16px;
background: var(--panel);
border-radius: 8px;
> :global(.icon) {
display: block;
width: ($bodyTitleHieght + $bodyInfoHieght);
height: ($bodyTitleHieght + $bodyInfoHieght);
object-fit: cover;
border-radius: 4px;
2022-06-22 23:40:53 +09:00
margin-right: 10px;
2022-06-21 17:55:38 +09:00
}
> :global(.body) {
flex: 1;
overflow: hidden;
font-size: 0.9em;
color: var(--fg);
padding-right: 8px;
> :global(.host) {
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: $bodyTitleHieght;
}
> :global(.sub) {
2022-06-23 13:39:28 +09:00
display: block;
width: 100%;
font-size: 80%;
2022-06-21 17:55:38 +09:00
opacity: 0.7;
line-height: $bodyInfoHieght;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
> :global(.chart) {
height: 30px;
}
&:global(.yellow) {
--c: rgb(255 196 0 / 15%);
2023-04-08 09:01:42 +09:00
background-image: linear-gradient(
45deg,
var(--c) 16.67%,
transparent 16.67%,
transparent 50%,
var(--c) 50%,
var(--c) 66.67%,
transparent 66.67%,
transparent 100%
);
2022-06-21 17:55:38 +09:00
background-size: 16px 16px;
}
&:global(.red) {
--c: rgb(255 0 0 / 15%);
2023-04-08 09:01:42 +09:00
background-image: linear-gradient(
45deg,
var(--c) 16.67%,
transparent 16.67%,
transparent 50%,
var(--c) 50%,
var(--c) 66.67%,
transparent 66.67%,
transparent 100%
);
2022-06-21 17:55:38 +09:00
background-size: 16px 16px;
}
2023-05-01 06:42:01 +09:00
&:global(.purple) {
--c: rgba(196, 0, 255, 0.15);
background-image: linear-gradient(
45deg,
var(--c) 16.67%,
transparent 16.67%,
transparent 50%,
var(--c) 50%,
var(--c) 66.67%,
transparent 66.67%,
transparent 100%
);
background-size: 16px 16px;
}
2022-06-21 17:55:38 +09:00
&:global(.gray) {
--c: var(--bg);
2023-04-08 09:01:42 +09:00
background-image: linear-gradient(
45deg,
var(--c) 16.67%,
transparent 16.67%,
transparent 50%,
var(--c) 50%,
var(--c) 66.67%,
transparent 66.67%,
transparent 100%
);
2022-06-21 17:55:38 +09:00
background-size: 16px 16px;
}
}
</style>