2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-12-26 01:29:47 +00:00
|
|
|
<template>
|
2023-05-19 07:20:53 +00:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" class="mkw-userList">
|
2023-01-14 23:30:29 +00:00
|
|
|
<template #icon><i class="ti ti-users"></i></template>
|
|
|
|
<template #header>{{ list ? list.name : i18n.ts._widgets.userList }}</template>
|
|
|
|
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="configure()"><i class="ti ti-settings"></i></button></template>
|
2022-12-26 01:29:47 +00:00
|
|
|
|
|
|
|
<div :class="$style.root">
|
|
|
|
<div v-if="widgetProps.listId == null" class="init">
|
|
|
|
<MkButton primary @click="chooseList">{{ i18n.ts._widgets._userList.chooseList }}</MkButton>
|
|
|
|
</div>
|
|
|
|
<MkLoading v-else-if="fetching"/>
|
|
|
|
<div v-else class="users">
|
2023-01-16 05:18:11 +00:00
|
|
|
<span v-for="user in users" :key="user.id" class="user">
|
|
|
|
<MkAvatar :user="user" class="avatar" indicator link preview/>
|
|
|
|
</span>
|
2022-12-26 01:29:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-05-19 07:20:53 +00:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2022-12-26 01:29:47 +00:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2022-12-26 01:29:47 +00:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
|
|
|
|
const name = 'userList';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
listId: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 07:20:53 +00:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-12-26 01:29:47 +00:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
let list = $ref();
|
|
|
|
let users = $ref([]);
|
|
|
|
let fetching = $ref(true);
|
|
|
|
|
|
|
|
async function chooseList() {
|
|
|
|
const lists = await os.api('users/lists/list');
|
|
|
|
const { canceled, result: list } = await os.select({
|
|
|
|
title: i18n.ts.selectList,
|
|
|
|
items: lists.map(x => ({
|
|
|
|
value: x, text: x.name,
|
|
|
|
})),
|
|
|
|
default: widgetProps.listId,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
widgetProps.listId = list.id;
|
|
|
|
save();
|
|
|
|
fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
const fetch = () => {
|
|
|
|
if (widgetProps.listId == null) {
|
|
|
|
fetching = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os.api('users/lists/show', {
|
|
|
|
listId: widgetProps.listId,
|
|
|
|
}).then(_list => {
|
|
|
|
list = _list;
|
|
|
|
os.api('users/show', {
|
|
|
|
userIds: list.userIds,
|
|
|
|
}).then(_users => {
|
|
|
|
users = _users;
|
|
|
|
fetching = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useInterval(fetch, 1000 * 60, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
|
|
|
&:global {
|
|
|
|
> .init {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .users {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(30px, 40px));
|
|
|
|
grid-gap: 12px;
|
|
|
|
place-content: center;
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
> .user {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
aspect-ratio: 1;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|