feat: add plugin entry selection
This commit is contained in:
parent
a51fb24f36
commit
fa6ebadc7b
|
@ -1,4 +1,4 @@
|
||||||
import { useEffect, useRef, useMemo } from "react";
|
import React, { useEffect, useRef, useMemo, useState } from "react";
|
||||||
|
|
||||||
import styles from "./home.module.scss";
|
import styles from "./home.module.scss";
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import DragIcon from "../icons/drag.svg";
|
||||||
|
|
||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
|
|
||||||
import { useAppConfig, useChatStore } from "../store";
|
import { ModelType, useAppConfig, useChatStore } from "../store";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_SIDEBAR_WIDTH,
|
DEFAULT_SIDEBAR_WIDTH,
|
||||||
|
@ -29,7 +29,7 @@ import {
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { isIOS, useMobileScreen } from "../utils";
|
import { isIOS, useMobileScreen } from "../utils";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { showConfirm, showToast } from "./ui-lib";
|
import { Selector, showConfirm, showToast } from "./ui-lib";
|
||||||
|
|
||||||
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
|
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
|
||||||
loading: () => null,
|
loading: () => null,
|
||||||
|
@ -140,6 +140,7 @@ export function SideBar(props: { className?: string }) {
|
||||||
() => isIOS() && isMobileScreen,
|
() => isIOS() && isMobileScreen,
|
||||||
[isMobileScreen],
|
[isMobileScreen],
|
||||||
);
|
);
|
||||||
|
const [showPluginSelector, setShowPluginSelector] = useState(false);
|
||||||
|
|
||||||
useHotKey();
|
useHotKey();
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ export function SideBar(props: { className?: string }) {
|
||||||
icon={<PluginIcon />}
|
icon={<PluginIcon />}
|
||||||
text={shouldNarrow ? undefined : Locale.Plugin.Name}
|
text={shouldNarrow ? undefined : Locale.Plugin.Name}
|
||||||
className={styles["sidebar-bar-button"]}
|
className={styles["sidebar-bar-button"]}
|
||||||
onClick={() => showToast(Locale.WIP)}
|
onClick={() => setShowPluginSelector(true)}
|
||||||
shadow
|
shadow
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -245,6 +246,22 @@ export function SideBar(props: { className?: string }) {
|
||||||
>
|
>
|
||||||
<DragIcon />
|
<DragIcon />
|
||||||
</div>
|
</div>
|
||||||
|
{showPluginSelector && (
|
||||||
|
<Selector
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
title: "👇 Please select the plugin you need to use",
|
||||||
|
value: "-",
|
||||||
|
disable: true,
|
||||||
|
},
|
||||||
|
{ title: "Stable Diffusion", value: "sd" },
|
||||||
|
]}
|
||||||
|
onClose={() => setShowPluginSelector(false)}
|
||||||
|
onSelection={(s) => {
|
||||||
|
console.log("go to page: ", s);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,6 +291,10 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
|
|
||||||
|
.selector-item-disabled{
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
&-content {
|
&-content {
|
||||||
.list {
|
.list {
|
||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
|
|
|
@ -13,7 +13,7 @@ import MinIcon from "../icons/min.svg";
|
||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
|
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import React, { HTMLProps, useEffect, useState } from "react";
|
import React, { HTMLProps, MouseEvent, useEffect, useState } from "react";
|
||||||
import { IconButton } from "./button";
|
import { IconButton } from "./button";
|
||||||
|
|
||||||
export function Popover(props: {
|
export function Popover(props: {
|
||||||
|
@ -47,7 +47,7 @@ export function ListItem(props: {
|
||||||
children?: JSX.Element | JSX.Element[];
|
children?: JSX.Element | JSX.Element[];
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
className?: string;
|
className?: string;
|
||||||
onClick?: () => void;
|
onClick?: (event: MouseEvent) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -442,6 +442,7 @@ export function Selector<T>(props: {
|
||||||
title: string;
|
title: string;
|
||||||
subTitle?: string;
|
subTitle?: string;
|
||||||
value: T;
|
value: T;
|
||||||
|
disable?: boolean;
|
||||||
}>;
|
}>;
|
||||||
defaultSelectedValue?: T;
|
defaultSelectedValue?: T;
|
||||||
onSelection?: (selection: T[]) => void;
|
onSelection?: (selection: T[]) => void;
|
||||||
|
@ -456,13 +457,18 @@ export function Selector<T>(props: {
|
||||||
const selected = props.defaultSelectedValue === item.value;
|
const selected = props.defaultSelectedValue === item.value;
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
className={styles["selector-item"]}
|
className={`${styles["selector-item"]} ${
|
||||||
|
item.disable && styles["selector-item-disabled"]
|
||||||
|
}`}
|
||||||
key={i}
|
key={i}
|
||||||
title={item.title}
|
title={item.title}
|
||||||
subTitle={item.subTitle}
|
subTitle={item.subTitle}
|
||||||
onClick={() => {
|
onClick={(event) => {
|
||||||
props.onSelection?.([item.value]);
|
event.stopPropagation();
|
||||||
props.onClose?.();
|
if (!item.disable) {
|
||||||
|
props.onSelection?.([item.value]);
|
||||||
|
props.onClose?.();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{selected ? (
|
{selected ? (
|
||||||
|
|
Loading…
Reference in New Issue