frequi_origin/src/components/BotList.vue

94 lines
2.8 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>
2023-04-19 04:16:58 +00:00
<b-list-group ref="sortContainer">
2021-08-29 09:07:41 +00:00
<b-list-group-item
2023-04-19 04:16:58 +00:00
v-for="bot in botListComp"
: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!'
}`"
2023-04-19 04:16:58 +00:00
class="d-flex"
2022-04-18 11:21:53 +00:00
@click="botStore.selectBot(bot.botId)"
2021-08-29 09:07:41 +00:00
>
2023-04-19 04:16:58 +00:00
<ReorderIcon v-if="!small" class="handle me-2" />
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)"
2023-04-13 04:32:00 +00:00
@edit-login="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';
2023-04-19 04:16:58 +00:00
import ReorderIcon from 'vue-material-design-icons/ReorderHorizontal.vue';
2021-08-29 08:29:53 +00:00
2023-04-19 04:16:58 +00:00
import { computed, ref } from 'vue';
2022-04-18 11:21:53 +00:00
import { useBotStore } from '@/stores/ftbotwrapper';
2023-04-19 04:16:58 +00:00
import { AuthStorageWithBotId, BotDescriptor } from '@/types';
import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable';
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>();
2023-04-19 04:16:58 +00:00
const sortContainer = ref<HTMLElement | null>(null);
const botListComp = computed<BotDescriptor[]>(() => {
//Convert to array
return Object.values(botStore.availableBots).sort((a, b) => (a.sortId ?? 0) - (b.sortId ?? 0));
});
useSortable(sortContainer, botListComp, {
handle: '.handle',
onUpdate: (e) => {
const oldBotId = botListComp.value[e.oldIndex].botId;
const newBotId = botListComp.value[e.newIndex].botId;
botStore.updateBot(oldBotId, { sortId: e.newIndex });
botStore.updateBot(newBotId, { sortId: e.oldIndex });
},
});
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>