Skip to content

Commit

Permalink
feat: Add Enable and Disable All button on right click bot logo (#757)
Browse files Browse the repository at this point in the history
* Add Enable and Disable All button on right click bot logo

* Update

* Update

* Update

* Update v-btn to v-list-item and translate

* Update zh.json

---------

Co-authored-by: Sun Zhigang <sunner@gmail.com>
  • Loading branch information
asyncButNeverAwaits and sunner authored Mar 23, 2024
1 parent b170f8d commit bb68781
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
65 changes: 64 additions & 1 deletion src/components/Footer/FooterBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,30 @@
>
{{ $t("footer.sendPrompt") }}
</v-btn>
<div class="bot-logos" ref="favBotLogosRef" :key="rerenderFavBotLogos">
<div
class="bot-logos"
ref="favBotLogosRef"
:key="rerenderFavBotLogos"
@contextmenu="show"
>
<v-menu
v-model="showMenu"
class="position-fixed"
:style="{ left: `${x}px`, top: `${y}px` }"
>
<v-list>
<v-list-item @click="disableAllBots">
<v-list-item-title>{{
$t("footer.disableAll")
}}</v-list-item-title>
</v-list-item>
<v-list-item @click="enableAllBots">
<v-list-item-title>{{
$t("footer.enableAll")
}}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<BotLogo
v-for="(bot, index) in favBots"
:id="`fav-bot-${index + 1}`"
Expand Down Expand Up @@ -396,6 +419,46 @@ async function usePrompt(value) {
document.execCommand("insertText", false, value);
}
const showMenu = ref(false);
const x = ref(0);
const y = ref(0);
function show(e) {
x.value = e.clientX;
y.value = e.clientY - 72;
showMenu.value = true;
}
async function disableAllBots() {
for (const botClassname in activeBots) {
if (activeBots[botClassname]) {
await store.dispatch("setBotSelected", { botClassname, selected: false });
}
}
}
async function enableAllBots() {
for (const botClassname in activeBots) {
if (!activeBots[botClassname]) {
const bot = favBots.value.find((bot) => bot.classname === botClassname);
if (bot && bot.instance && !bot.instance.isAvailable()) {
const availability = await bot.instance.checkAvailability();
if (!availability) {
clickedBot.value = bot.instance;
// Open the bot's settings dialog
isMakeAvailableOpen.value = true;
} else {
updateActiveBots();
}
} else {
await store.dispatch("setBotSelected", {
botClassname,
selected: true,
});
}
}
}
}
defineExpose({
focusPromptTextarea,
});
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"openSource": "Open Source",
"free": "Free",
"paid": "Paid",
"api": "API"
"api": "API",
"enableAll": "Enable All",
"disableAll": "Disable All"
},
"error": {
"error": "Error",
Expand Down
5 changes: 3 additions & 2 deletions src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"openSource": "开源",
"free": "免费",
"paid": "付费",
"api": "API"
"enableAll": "全部启用",
"disableAll": "全部禁用"
},
"error": {
"error": "错误",
Expand Down Expand Up @@ -335,4 +336,4 @@
"25": "25",
"50": "50",
"100": "100"
}
}
13 changes: 13 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ export default createStore({
},
},
actions: {
async setBotSelected(_, { botClassname, selected }) {
const currentChat = await Chats.getCurrentChat();
for (let i = 0; i < currentChat.favBots.length; i++) {
const bot = currentChat.favBots[i];
if (bot.classname === botClassname) {
bot.selected = selected;
await Chats.table.update(currentChat.index, {
favBots: currentChat.favBots,
});
return;
}
}
},
async sendPrompt({ commit, dispatch }, { prompt, bots, promptIndex }) {
const currentChat = await Chats.getCurrentChat();
if (promptIndex === undefined) {
Expand Down

0 comments on commit bb68781

Please sign in to comment.