2023-02-12 01:20:17 +00:00
|
|
|
<template>
|
2023-04-08 00:01:42 +00:00
|
|
|
<XModalWindow
|
|
|
|
ref="dialogEl"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="selected == null"
|
|
|
|
@click="cancel()"
|
|
|
|
@close="cancel()"
|
|
|
|
@ok="ok()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
|
|
|
<template #header>{{ i18n.ts.selectInstance }}</template>
|
|
|
|
<div class="mehkoush">
|
|
|
|
<div class="form">
|
|
|
|
<MkInput
|
|
|
|
v-model="hostname"
|
|
|
|
:autofocus="true"
|
|
|
|
@update:modelValue="search"
|
|
|
|
>
|
2023-02-12 01:20:17 +00:00
|
|
|
<template #label>{{ i18n.ts.instance }}</template>
|
|
|
|
</MkInput>
|
2023-04-08 00:01:42 +00:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="hostname != ''"
|
|
|
|
class="result"
|
|
|
|
:class="{ hit: instances.length > 0 }"
|
|
|
|
>
|
|
|
|
<div v-if="instances.length > 0" class="instances">
|
|
|
|
<div
|
|
|
|
v-for="item in instances"
|
|
|
|
:key="item.id"
|
|
|
|
class="instance"
|
|
|
|
:class="{
|
|
|
|
selected: selected && selected.id === item.id,
|
|
|
|
}"
|
|
|
|
@click="selected = item"
|
|
|
|
@dblclick="ok()"
|
|
|
|
>
|
|
|
|
<div class="body">
|
|
|
|
<img
|
|
|
|
class="icon"
|
|
|
|
:src="
|
|
|
|
item.iconUrl ?? '/client-assets/dummy.png'
|
|
|
|
"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
<span class="name">{{ item.host }}</span>
|
|
|
|
</div>
|
2023-02-12 01:20:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-08 00:01:42 +00:00
|
|
|
<div v-else class="empty">
|
|
|
|
<span>{{ i18n.ts.noInstances }}</span>
|
|
|
|
</div>
|
2023-02-12 01:20:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-08 00:01:42 +00:00
|
|
|
</XModalWindow>
|
2023-02-12 01:20:17 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-04-08 00:01:42 +00:00
|
|
|
import MkInput from "@/components/form/input.vue";
|
|
|
|
import XModalWindow from "@/components/MkModalWindow.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { Instance } from "calckey-js/built/entities";
|
2023-02-12 01:20:17 +00:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2023-04-08 00:01:42 +00:00
|
|
|
(ev: "ok", selected: Instance): void;
|
|
|
|
(ev: "cancel"): void;
|
|
|
|
(ev: "closed"): void;
|
2023-02-12 01:20:17 +00:00
|
|
|
}>();
|
|
|
|
|
2023-04-08 00:01:42 +00:00
|
|
|
let hostname = $ref("");
|
2023-02-12 01:20:17 +00:00
|
|
|
let instances: Instance[] = $ref([]);
|
|
|
|
let selected: Instance | null = $ref(null);
|
|
|
|
let dialogEl = $ref<InstanceType<typeof XModalWindow>>();
|
|
|
|
|
2023-02-12 01:51:26 +00:00
|
|
|
let searchOrderLatch = 0;
|
2023-02-12 01:20:17 +00:00
|
|
|
const search = () => {
|
2023-04-08 00:01:42 +00:00
|
|
|
if (hostname === "") {
|
2023-02-12 01:20:17 +00:00
|
|
|
instances = [];
|
|
|
|
return;
|
|
|
|
}
|
2023-02-12 01:51:26 +00:00
|
|
|
|
|
|
|
const searchId = ++searchOrderLatch;
|
2023-04-08 00:01:42 +00:00
|
|
|
os.api("federation/instances", {
|
2023-02-12 01:20:17 +00:00
|
|
|
host: hostname,
|
|
|
|
limit: 10,
|
|
|
|
blocked: false,
|
|
|
|
suspended: false,
|
2023-04-08 00:01:42 +00:00
|
|
|
sort: "+pubSub",
|
|
|
|
}).then((_instances) => {
|
2023-02-12 01:51:26 +00:00
|
|
|
if (searchId !== searchOrderLatch) return;
|
2023-04-08 00:01:42 +00:00
|
|
|
instances = _instances.map(
|
|
|
|
(x) =>
|
|
|
|
({
|
|
|
|
id: x.id,
|
|
|
|
host: x.host,
|
|
|
|
iconUrl: x.iconUrl,
|
|
|
|
} as Instance)
|
|
|
|
);
|
2023-02-12 01:20:17 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const ok = () => {
|
|
|
|
if (selected == null) return;
|
2023-04-08 00:01:42 +00:00
|
|
|
emit("ok", selected);
|
2023-02-12 01:20:17 +00:00
|
|
|
dialogEl?.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
const cancel = () => {
|
2023-04-08 00:01:42 +00:00
|
|
|
emit("cancel");
|
2023-02-12 01:20:17 +00:00
|
|
|
dialogEl?.close();
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mehkoush {
|
|
|
|
margin: var(--marginFull) 0;
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
padding: 0 var(--root-margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .result {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
overflow: auto;
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
&.result.hit {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .instances {
|
|
|
|
flex: 1;
|
|
|
|
overflow: auto;
|
|
|
|
padding: 8px 0;
|
|
|
|
|
|
|
|
> .instance {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 8px var(--root-margin);
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--X7);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
background: var(--accent);
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
padding: 0 8px;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
margin-right: 8px;
|
|
|
|
float: left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .empty {
|
|
|
|
opacity: 0.7;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|