2023-02-12 02:20:17 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02: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 02:20:17 +01:00
|
|
|
<template #label>{{ i18n.ts.instance }}</template>
|
|
|
|
</MkInput>
|
2023-04-08 02:01:42 +02: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 02:20:17 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div v-else class="empty">
|
|
|
|
<span>{{ i18n.ts.noInstances }}</span>
|
|
|
|
</div>
|
2023-02-12 02:20:17 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
</XModalWindow>
|
2023-02-12 02:20:17 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-08-12 02:44:46 +02:00
|
|
|
import { ref } from "vue";
|
|
|
|
|
2024-02-12 16:40:46 +01:00
|
|
|
import type { entities } from "firefish-js";
|
2023-04-08 02:01:42 +02:00
|
|
|
import MkInput from "@/components/form/input.vue";
|
|
|
|
import XModalWindow from "@/components/MkModalWindow.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { i18n } from "@/i18n";
|
2023-02-12 02:20:17 +01:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2024-02-12 16:40:46 +01:00
|
|
|
(ev: "ok", selected: entities.Instance): void;
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "cancel"): void;
|
|
|
|
(ev: "closed"): void;
|
2023-02-12 02:20:17 +01:00
|
|
|
}>();
|
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
const hostname = ref("");
|
2024-02-12 16:40:46 +01:00
|
|
|
const instances = ref<entities.Instance[]>([]);
|
|
|
|
const selected = ref<entities.Instance | null>();
|
2023-09-02 01:27:33 +02:00
|
|
|
const dialogEl = ref<InstanceType<typeof XModalWindow>>();
|
2023-02-12 02:20:17 +01:00
|
|
|
|
2023-02-12 02:51:26 +01:00
|
|
|
let searchOrderLatch = 0;
|
2023-02-12 02:20:17 +01:00
|
|
|
const search = () => {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (hostname.value === "") {
|
|
|
|
instances.value = [];
|
2023-02-12 02:20:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-02-12 02:51:26 +01:00
|
|
|
|
|
|
|
const searchId = ++searchOrderLatch;
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("federation/instances", {
|
2023-08-12 02:44:46 +02:00
|
|
|
host: hostname.value,
|
2023-02-12 02:20:17 +01:00
|
|
|
limit: 10,
|
|
|
|
blocked: false,
|
|
|
|
suspended: false,
|
2023-04-08 02:01:42 +02:00
|
|
|
sort: "+pubSub",
|
|
|
|
}).then((_instances) => {
|
2023-02-12 02:51:26 +01:00
|
|
|
if (searchId !== searchOrderLatch) return;
|
2023-08-12 02:44:46 +02:00
|
|
|
instances.value = _instances.map(
|
2023-04-08 02:01:42 +02:00
|
|
|
(x) =>
|
|
|
|
({
|
|
|
|
id: x.id,
|
|
|
|
host: x.host,
|
|
|
|
iconUrl: x.iconUrl,
|
2024-02-12 16:40:46 +01:00
|
|
|
}) as entities.Instance,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2023-02-12 02:20:17 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const ok = () => {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (selected.value == null) return;
|
|
|
|
emit("ok", selected.value);
|
|
|
|
dialogEl.value?.close();
|
2023-02-12 02:20:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const cancel = () => {
|
2023-04-08 02:01:42 +02:00
|
|
|
emit("cancel");
|
2023-08-12 02:44:46 +02:00
|
|
|
dialogEl.value?.close();
|
2023-02-12 02:20:17 +01:00
|
|
|
};
|
|
|
|
</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>
|