frequi_origin/src/components/BotList.vue

83 lines
2.3 KiB
Vue
Raw Normal View History

2021-08-29 08:29:53 +00:00
<template>
2021-09-26 09:06:07 +00:00
<div v-if="botCount > 0">
2021-08-29 18:17:34 +00:00
<h3 v-if="!small">Available bots</h3>
2021-08-29 09:07:41 +00:00
<b-list-group>
<b-list-group-item
v-for="bot in allAvailableBots"
:key="bot.botId"
:active="bot.botId === selectedBot"
button
2021-08-29 11:59:39 +00:00
:title="`${bot.botId} - ${bot.botName} - ${bot.botUrl}`"
@click="selectBot(bot.botId)"
2021-08-29 09:07:41 +00:00
>
2022-03-10 07:57:06 +00:00
<bot-rename
v-if="editingBots.includes(bot.botId)"
:bot="bot"
@saved="stopEditBot(bot.botId)"
@cancelled="stopEditBot(bot.botId)"
/>
<bot-entry v-else :bot="bot" :no-buttons="small" @edit="editBot(bot.botId)" />
2021-08-29 09:07:41 +00:00
</b-list-group-item>
</b-list-group>
2021-08-29 18:17:34 +00:00
<LoginModal v-if="!small" class="mt-2" login-text="Add new bot" />
2021-08-29 08:29:53 +00:00
</div>
</template>
<script lang="ts">
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
import LoginModal from '@/views/LoginModal.vue';
2021-08-29 18:17:34 +00:00
import BotEntry from '@/components/BotEntry.vue';
2022-03-10 07:57:06 +00:00
import BotRename from '@/components/BotRename.vue';
import StoreModules from '@/store/storeSubModules';
2021-08-29 08:29:53 +00:00
2022-04-15 18:14:13 +00:00
import { defineComponent, ref } from '@vue/composition-api';
import { useNamespacedActions, useNamespacedGetters } from 'vuex-composition-helpers';
2021-08-29 08:29:53 +00:00
2022-04-15 18:14:13 +00:00
export default defineComponent({
name: 'BotList',
components: { LoginModal, BotEntry, BotRename },
props: {
small: { default: false, type: Boolean },
2022-03-10 07:57:06 +00:00
},
2022-04-15 18:14:13 +00:00
setup() {
const { botCount, selectedBot, allIsBotOnline, allAvailableBots } = useNamespacedGetters(
StoreModules.ftbot,
[
MultiBotStoreGetters.botCount,
MultiBotStoreGetters.selectedBot,
MultiBotStoreGetters.allIsBotOnline,
MultiBotStoreGetters.allAvailableBots,
],
);
const { selectBot } = useNamespacedActions(StoreModules.ftbot, ['selectBot']);
const editingBots = ref<string[]>([]);
2021-08-29 18:17:34 +00:00
2022-04-15 18:14:13 +00:00
const editBot = (botId: string) => {
if (!editingBots.value.includes(botId)) {
editingBots.value.push(botId);
}
};
2021-09-26 09:06:07 +00:00
2022-04-15 18:14:13 +00:00
const stopEditBot = (botId: string) => {
if (!editingBots.value.includes(botId)) {
return;
}
2021-08-29 09:07:41 +00:00
2022-04-15 18:14:13 +00:00
editingBots.value.splice(editingBots.value.indexOf(botId), 1);
};
2021-08-29 12:08:32 +00:00
2022-04-15 18:14:13 +00:00
return {
botCount,
selectedBot,
allIsBotOnline,
allAvailableBots,
selectBot,
editingBots,
editBot,
stopEditBot,
};
},
});
2021-08-29 08:29:53 +00:00
</script>