forked from Shinonome/dots-hyprland
sidebar: apis: fix inconsistent tab switch
This commit is contained in:
@@ -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);
|
const shownIndex = Variable(0);
|
||||||
let previousShownIndex = 0;
|
let previousShownIndex = 0;
|
||||||
const count = Math.min(iconWidgets.length, names.length, children.length);
|
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',
|
className: 'spacing-h-5',
|
||||||
children: iconWidgets.map((icon, i) => Button({
|
children: iconWidgets.map((icon, i) => Button({
|
||||||
className: 'tab-icon',
|
className: 'tab-icon',
|
||||||
|
tooltipText: names[i],
|
||||||
child: icon,
|
child: icon,
|
||||||
setup: setupCursorHover,
|
setup: setupCursorHover,
|
||||||
onClicked: () => shownIndex.value = i,
|
onClicked: () => shownIndex.value = i,
|
||||||
@@ -150,6 +156,7 @@ export const IconTabContainer = ({ iconWidgets, names, children, className = '',
|
|||||||
self.pack_start(tabSection, false, false, 0);
|
self.pack_start(tabSection, false, false, 0);
|
||||||
self.pack_end(contentStack, true, true, 0);
|
self.pack_end(contentStack, true, true, 0);
|
||||||
setup(self);
|
setup(self);
|
||||||
|
self.hook(shownIndex, (self) => onChange(self, shownIndex.value));
|
||||||
},
|
},
|
||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export const GeminiSettings = () => MarginRevealer({
|
|||||||
ConfigToggle({
|
ConfigToggle({
|
||||||
icon: 'shield',
|
icon: 'shield',
|
||||||
name: 'Safety',
|
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,
|
initValue: GeminiService.safe,
|
||||||
onChange: (self, newValue) => {
|
onChange: (self, newValue) => {
|
||||||
GeminiService.safe = newValue;
|
GeminiService.safe = newValue;
|
||||||
|
|||||||
@@ -181,16 +181,18 @@ const apiCommandStack = Stack({
|
|||||||
|
|
||||||
export const apiContentStack = IconTabContainer({
|
export const apiContentStack = IconTabContainer({
|
||||||
className: 'margin-top-5',
|
className: 'margin-top-5',
|
||||||
iconWidgets: APIS.map((api, id) => api.tabIcon),
|
iconWidgets: APIS.map((api) => api.tabIcon),
|
||||||
names: APIS.map((api) => api.name),
|
names: APIS.map((api) => api.name),
|
||||||
children: APIS.map((api) => api.contentWidget),
|
children: APIS.map((api) => api.contentWidget),
|
||||||
|
onChange: (self, id) => {
|
||||||
|
apiCommandStack.shown = APIS[id].name;
|
||||||
|
chatPlaceholder.label = APIS[id].placeholderText;
|
||||||
|
currentApiId = id;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function switchToTab(id) {
|
function switchToTab(id) {
|
||||||
apiContentStack.shown.value = id;
|
apiContentStack.shown.value = id;
|
||||||
apiCommandStack.shown = APIS[id].name;
|
|
||||||
chatPlaceholder.label = APIS[id].placeholderText;
|
|
||||||
currentApiId = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiWidgets = Widget.Box({
|
const apiWidgets = Widget.Box({
|
||||||
|
|||||||
Reference in New Issue
Block a user