Skip to content

Commit

Permalink
feat(status): merge status lights
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 20, 2023
1 parent 0df94d5 commit e3a474a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions plugins/status/client/bots/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
></bot-preview>
</template>
</template>
<status-light v-for="(bot, key) in store.status.bots" :key="key" :class="getStatus(bot.status)"></status-light>
<template v-for="(count, status) in statusMap" :key="status">
<template v-if="count > 5">
<status-light :class="status"></status-light>
<span class="count">×{{ count }}</span>
</template>
<template v-else>
<status-light v-for="(_, key) in Array(count)" :key="key" :class="status"></status-light>
</template>
</template>
<k-icon name="arrow-up"/>
<span>{{ sent }}/min</span>
<k-icon name="arrow-down"/>
Expand All @@ -21,11 +29,22 @@
<script setup lang="ts">
import { computed } from 'vue'
import { store, router } from '@koishijs/client'
import { store, router, Dict } from '@koishijs/client'
import { getStatus } from './utils'
import BotPreview from './preview.vue'
import StatusLight from './light.vue'
const statusMap = computed(() => {
const map: Dict<number> = {}
for (const bot of Object.values(store.status.bots)) {
const key = getStatus(bot.status)
map[key] = (map[key] || 0) + 5
map['reconnect'] = (map['reconnect'] || 0) + 5
}
return Object.fromEntries(Object.entries(map)
.sort((a, b) => a[0].localeCompare(b[0])))
})
const sent = computed(() => {
return Object.values(store.status.bots).reduce((acc, bot) => acc + bot.messageSent, 0)
})
Expand All @@ -46,6 +65,11 @@ const received = computed(() => {
* + .k-icon {
margin-left: 6px;
}
.count {
margin: 0 4px 0 4px;
letter-spacing: 1px;
}
}
</style>

0 comments on commit e3a474a

Please sign in to comment.