Sharkey/packages/frontend/src/widgets/WidgetOnlineUsers.vue

73 lines
1.6 KiB
Vue
Raw Normal View History

2020-12-30 06:07:16 +02:00
<template>
2023-05-24 08:34:46 +03:00
<div data-cy-mkw-onlineUsers :class="[$style.root, { _panel: !widgetProps.transparent, [$style.pad]: !widgetProps.transparent }]">
<span :class="$style.text">
<I18n v-if="onlineUsersCount" :src="i18n.ts.onlineUsersCount" textTag="span">
<template #n><b style="color: #41b781;">{{ number(onlineUsersCount) }}</b></template>
</I18n>
</span>
2020-12-30 06:07:16 +02:00
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
2023-05-19 10:20:53 +03:00
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
import { GetFormResultType } from '@/scripts/form';
2021-11-11 19:02:25 +02:00
import * as os from '@/os';
import { useInterval } from '@/scripts/use-interval';
2022-07-20 16:24:26 +03:00
import { i18n } from '@/i18n';
import number from '@/filters/number';
2020-12-30 06:07:16 +02:00
const name = 'onlineUsers';
2020-12-30 06:07:16 +02:00
const widgetPropsDef = {
transparent: {
type: 'boolean' as const,
default: true,
2020-12-30 06:07:16 +02:00
},
};
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
2023-05-19 10:20:53 +03:00
const props = defineProps<WidgetComponentProps<WidgetProps>>();
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const { widgetProps, configure } = useWidgetPropsManager(name,
widgetPropsDef,
props,
emit,
);
const onlineUsersCount = ref(0);
const tick = () => {
os.apiGet('get-online-users-count').then(res => {
onlineUsersCount.value = res.count;
});
};
useInterval(tick, 1000 * 15, {
immediate: true,
afterMounted: true,
});
defineExpose<WidgetComponentExpose>({
name,
configure,
id: props.widget ? props.widget.id : null,
2020-12-30 06:07:16 +02:00
});
</script>
2023-05-24 08:34:46 +03:00
<style lang="scss" module>
.root {
2020-12-30 06:07:16 +02:00
text-align: center;
&.pad {
padding: 16px 0;
}
2023-05-24 08:34:46 +03:00
}
2020-12-30 06:07:16 +02:00
2023-05-24 08:34:46 +03:00
.text {
color: var(--fgTransparentWeak);
2020-12-30 06:07:16 +02:00
}
</style>