From 16ba0191a8bdfad695b9e383464f5c3ca349493a Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:02:07 +0700 Subject: [PATCH] sidebar: apis: fix inconsistent tab switch --- .config/ags/modules/.commonwidgets/tabcontainer.js | 9 ++++++++- .config/ags/modules/sideleft/apis/gemini.js | 4 ++-- .config/ags/modules/sideleft/apiwidgets.js | 10 ++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.config/ags/modules/.commonwidgets/tabcontainer.js b/.config/ags/modules/.commonwidgets/tabcontainer.js index 135875fb6..c643e052a 100644 --- a/.config/ags/modules/.commonwidgets/tabcontainer.js +++ b/.config/ags/modules/.commonwidgets/tabcontainer.js @@ -94,7 +94,12 @@ export const TabContainer = ({ icons, names, children, className = '', setup = ( } -export const IconTabContainer = ({ iconWidgets, names, children, className = '', setup = () => { }, tabsHpack = 'center', ...rest }) => { +export const IconTabContainer = ({ + iconWidgets, names, children, className = '', + setup = () => { }, onChange = () => { }, + tabsHpack = 'center', + ...rest +}) => { const shownIndex = Variable(0); let previousShownIndex = 0; const count = Math.min(iconWidgets.length, names.length, children.length); @@ -104,6 +109,7 @@ export const IconTabContainer = ({ iconWidgets, names, children, className = '', className: 'spacing-h-5', children: iconWidgets.map((icon, i) => Button({ className: 'tab-icon', + tooltipText: names[i], child: icon, setup: setupCursorHover, onClicked: () => shownIndex.value = i, @@ -150,6 +156,7 @@ export const IconTabContainer = ({ iconWidgets, names, children, className = '', self.pack_start(tabSection, false, false, 0); self.pack_end(contentStack, true, true, 0); setup(self); + self.hook(shownIndex, (self) => onChange(self, shownIndex.value)); }, ...rest, }); diff --git a/.config/ags/modules/sideleft/apis/gemini.js b/.config/ags/modules/sideleft/apis/gemini.js index 6c9c89d97..57b966dd4 100644 --- a/.config/ags/modules/sideleft/apis/gemini.js +++ b/.config/ags/modules/sideleft/apis/gemini.js @@ -88,7 +88,7 @@ export const GeminiSettings = () => MarginRevealer({ GeminiService.temperature = value; }, }), - ConfigGap({ vertical: true, size: 10 }), // Note: size can only be 5, 10, or 15 + ConfigGap({ vertical: true, size: 10 }), // Note: size can only be 5, 10, or 15 Box({ vertical: true, hpack: 'fill', @@ -106,7 +106,7 @@ export const GeminiSettings = () => MarginRevealer({ ConfigToggle({ icon: 'shield', name: 'Safety', - desc: 'When turned off, tells the API not to block harmful/explicit content', + desc: 'When turned off, tells the API (not the model) \nto not block harmful/explicit content', initValue: GeminiService.safe, onChange: (self, newValue) => { GeminiService.safe = newValue; diff --git a/.config/ags/modules/sideleft/apiwidgets.js b/.config/ags/modules/sideleft/apiwidgets.js index 6595c32d3..7f1c5ce93 100644 --- a/.config/ags/modules/sideleft/apiwidgets.js +++ b/.config/ags/modules/sideleft/apiwidgets.js @@ -181,16 +181,18 @@ const apiCommandStack = Stack({ export const apiContentStack = IconTabContainer({ className: 'margin-top-5', - iconWidgets: APIS.map((api, id) => api.tabIcon), + iconWidgets: APIS.map((api) => api.tabIcon), names: APIS.map((api) => api.name), children: APIS.map((api) => api.contentWidget), + onChange: (self, id) => { + apiCommandStack.shown = APIS[id].name; + chatPlaceholder.label = APIS[id].placeholderText; + currentApiId = id; + } }); function switchToTab(id) { apiContentStack.shown.value = id; - apiCommandStack.shown = APIS[id].name; - chatPlaceholder.label = APIS[id].placeholderText; - currentApiId = id; } const apiWidgets = Widget.Box({