frequi_origin/src/components/BotList.vue

75 lines
2.0 KiB
Vue
Raw Normal View History

2021-08-29 08:29:53 +00:00
<template>
2022-04-18 11:21:53 +00:00
<div v-if="botStore.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
2022-04-18 11:21:53 +00:00
v-for="bot in botStore.availableBots"
:key="bot.botId"
2022-04-18 11:21:53 +00:00
:active="bot.botId === botStore.selectedBot"
button
:title="`${bot.botId} - ${bot.botName} - ${bot.botUrl} - ${
botStore.botStores[bot.botId].isBotLoggedIn ? '' : 'Login info expired!'
}`"
2022-04-18 11:21:53 +00:00
@click="botStore.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)"
@editLogin="editBotLogin(bot.botId)"
/>
2021-08-29 09:07:41 +00:00
</b-list-group-item>
</b-list-group>
<LoginModal v-if="!small" ref="loginModal" class="mt-2" login-text="Add new bot" />
2021-08-29 08:29:53 +00:00
</div>
</template>
2023-02-25 14:31:03 +00:00
<script setup lang="ts">
2021-08-29 08:29:53 +00:00
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';
2021-08-29 08:29:53 +00:00
2023-02-25 14:31:03 +00:00
import { ref } from 'vue';
2022-04-18 11:21:53 +00:00
import { useBotStore } from '@/stores/ftbotwrapper';
import { AuthStorageWithBotId } from '@/types';
2021-08-29 08:29:53 +00:00
2023-02-25 14:31:03 +00:00
defineProps({
small: { default: false, type: Boolean },
});
2022-04-18 11:21:53 +00:00
2023-02-25 14:31:03 +00:00
const botStore = useBotStore();
2021-08-29 18:17:34 +00:00
2023-02-25 14:31:03 +00:00
const editingBots = ref<string[]>([]);
const loginModal = ref<typeof LoginModal>();
2021-09-26 09:06:07 +00:00
2023-02-25 14:31:03 +00:00
const editBot = (botId: string) => {
if (!editingBots.value.includes(botId)) {
editingBots.value.push(botId);
}
};
2023-02-25 14:31:03 +00:00
const editBotLogin = (botId: string) => {
const loginInfo: AuthStorageWithBotId = {
...botStore.botStores[botId].getLoginInfo(),
botId,
};
loginModal.value?.openLoginModal(loginInfo);
};
2021-08-29 09:07:41 +00:00
2023-02-25 14:31:03 +00:00
const stopEditBot = (botId: string) => {
if (!editingBots.value.includes(botId)) {
return;
}
2021-08-29 12:08:32 +00:00
2023-02-25 14:31:03 +00:00
editingBots.value.splice(editingBots.value.indexOf(botId), 1);
};
2021-08-29 08:29:53 +00:00
</script>