Skip to content

Commit

Permalink
Merge branch 'feat-redesign-ui' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-bf committed May 8, 2024
2 parents 32f62d7 + 240d330 commit 00b1a97
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/components/Btn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function Btn(props: BtnProps) {
} text-text-btn-primary `;
break;
case "danger":
btnClassName = `bg-danger-btn text-text-btn-danger hover:bg-hovered-btn`;
btnClassName = `bg-danger-btn text-text-btn-danger hover:bg-hovered-danger-btn`;
break;
default:
btnClassName = `bg-default-btn text-text-btn-default hover:bg-hovered-btn`;
Expand Down
8 changes: 6 additions & 2 deletions app/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DetailedHTMLProps,
InputHTMLAttributes,
useContext,
useEffect,
useLayoutEffect,
useState,
} from "react";
Expand All @@ -17,6 +16,7 @@ export interface CommonInputProps
> {
className?: string;
}

export interface NumberInputProps {
onChange?: (v: number) => void;
type?: "number";
Expand Down Expand Up @@ -49,12 +49,16 @@ export default function Input(props: CommonInputProps & InputProps) {

const internalType = (show && "text") || type;

const { update } = useContext(List.ListContext);
const { update, handleValidate } = useContext(List.ListContext);

useLayoutEffect(() => {
update?.({ type: "input" });
}, []);

useLayoutEffect(() => {
handleValidate?.(value);
}, [value]);

return (
<div
className={` group/input w-[100%] rounded-chat-input bg-input transition-colors duration-300 ease-in-out flex gap-3 items-center px-3 py-2 ${className} hover:bg-select-hover ${inputClassName}`}
Expand Down
50 changes: 44 additions & 6 deletions app/components/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface WidgetStyle {

interface ChildrenMeta {
type?: "unknown" | "input" | "range";
error?: string;
}

export interface ListProps {
Expand All @@ -27,17 +28,31 @@ export interface ListProps {
widgetStyle?: WidgetStyle;
}

type Error =
| {
error: true;
message: string;
}
| {
error: false;
};

export interface ListItemProps {
title: string;
subTitle?: string;
children?: JSX.Element | JSX.Element[];
className?: string;
onClick?: () => void;
nextline?: boolean;
validator?: (v: any) => Error | Promise<Error>;
}

export const ListContext = createContext<
{ isMobileScreen?: boolean; update?: (m: ChildrenMeta) => void } & WidgetStyle
{
isMobileScreen?: boolean;
update?: (m: ChildrenMeta) => void;
handleValidate?: (v: any) => void;
} & WidgetStyle
>({ isMobileScreen: false });

export function ListItem(props: ListItemProps) {
Expand All @@ -48,6 +63,7 @@ export function ListItem(props: ListItemProps) {
subTitle,
children,
nextline,
validator,
} = props;

const context = useContext(ListContext);
Expand All @@ -56,9 +72,11 @@ export function ListItem(props: ListItemProps) {

const { inputNextLine, rangeNextLine } = context;

const { type, error } = childrenMeta;

let internalNextLine;

switch (childrenMeta.type) {
switch (type) {
case "input":
internalNextLine = !!(nextline || inputNextLine);
break;
Expand All @@ -70,7 +88,22 @@ export function ListItem(props: ListItemProps) {
}

const update = useCallback((m: ChildrenMeta) => {
setMeta(m);
setMeta((pre) => ({ ...pre, ...m }));
}, []);

const handleValidate = useCallback((v: any) => {
const insideValidator = validator || (() => {});

Promise.resolve(insideValidator(v)).then((result) => {
if (result && result.error) {
return update({
error: result.message,
});
}
update({
error: undefined,
});
});
}, []);

return (
Expand All @@ -88,13 +121,18 @@ export function ListItem(props: ListItemProps) {
<div className={` text-sm text-text-list-subtitle`}>{subTitle}</div>
)}
</div>
<ListContext.Provider value={{ ...context, update }}>
<ListContext.Provider value={{ ...context, update, handleValidate }}>
<div
className={`${
internalNextLine ? "mt-[0.625rem]" : "max-w-[70%]"
} flex items-center justify-center`}
} flex flex-col items-center justify-center`}
>
{children}
<div>{children}</div>
{!!error && (
<div className="text-text-btn-danger text-sm-mobile-tab mt-[0.3125rem] flex items-start w-[100%]">
<div className="">{error}</div>
</div>
)}
</div>
</ListContext.Provider>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/components/MenuLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function MenuLayout<
<div
className={`
w-[100%] relative bg-center
max-md:h-[100%]
md:flex md:my-2.5
`}
>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Select = <Value extends number | string>(props: SearchProps<Value>) => {
className={selectClassName}
>
<div
className={`flex items-center gap-3 py-2 px-3 bg-select rounded-action-btn font-time text-sm-title cursor-pointer hover:bg-select-hover transition duration-300 ease-in-out`}
className={`flex items-center gap-3 py-2 px-3 bg-select rounded-action-btn font-common text-sm-title cursor-pointer hover:bg-select-hover transition duration-300 ease-in-out`}
ref={contentRef}
>
<div
Expand Down
3 changes: 3 additions & 0 deletions app/components/exporter.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
&-body {
margin-top: 20px;
}
div:not(.no-dark) > svg {
filter: invert(0.5);
}
}

.export-content {
Expand Down
4 changes: 4 additions & 0 deletions app/components/mask.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
display: flex;
flex-direction: column;

div:not(.no-dark) > svg {
filter: invert(0.5);
}

.mask-page-body {
padding: 20px;
overflow-y: auto;
Expand Down
11 changes: 5 additions & 6 deletions app/components/mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export function ContextPrompts(props: {
);
}

export function MaskPage() {
export function MaskPage(props: { className?: string }) {
const navigate = useNavigate();

const maskStore = useMaskStore();
Expand Down Expand Up @@ -465,14 +465,13 @@ export function MaskPage() {
});
};

const isMobileScreen = useMobileScreen();

return (
<>
<div
className={`${styles["mask-page"]} !bg-gray-50 ${
isMobileScreen ? "pb-chat-panel-mobile" : ""
}`}
className={`
${styles["mask-page"]}
${props.className}
`}
>
<div className="window-header">
<div className="window-header-title">
Expand Down
4 changes: 4 additions & 0 deletions app/components/new-chat.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
justify-content: center;
flex-direction: column;

div:not(.no-dark) > svg {
filter: invert(0.5);
}

.mask-header {
display: flex;
justify-content: space-between;
Expand Down
9 changes: 5 additions & 4 deletions app/components/new-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function useMaskGroup(masks: Mask[]) {
return groups;
}

export function NewChat() {
export function NewChat(props: { className?: string }) {
const chatStore = useChatStore();
const maskStore = useMaskStore();

Expand Down Expand Up @@ -115,9 +115,10 @@ export function NewChat() {

return (
<div
className={`${styles["new-chat"]} !bg-gray-50 px-1 ${
isMobileScreen ? "pb-chat-panel-mobile" : ""
}`}
className={`
${styles["new-chat"]}
${props.className}
`}
>
<div className={styles["mask-header"]}>
<IconButton
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Chat/components/ChatInputPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export default forwardRef<ChatInputPanelInstance, ChatInputPanelProps>(
{!isMobileScreen && (
<div className="flex items-center justify-center text-sm gap-3">
<div className="flex-1">&nbsp;</div>
<div className="text-text-chat-input-placeholder text-time line-clamp-1">
<div className="text-text-chat-input-placeholder font-common line-clamp-1">
{Locale.Chat.Input(submitKey)}
</div>
<Btn
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Chat/components/ChatMessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default function ChatMessagePanel(props: ChatMessagePanelProps) {
}`}
>
<div
className={` pointer-events-none text-text-chat-message-date text-right text-time whitespace-nowrap transition-all duration-500 text-sm absolute z-1 ${
className={` pointer-events-none text-text-chat-message-date text-right font-common whitespace-nowrap transition-all duration-500 text-sm absolute z-1 ${
isUser ? "right-0" : "left-0"
} bottom-[100%] hidden group-hover:block`}
>
Expand Down
8 changes: 6 additions & 2 deletions app/containers/Chat/components/ModelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ const ModelSelect = () => {

return (
<Popover
content={content({ close: () => {} })}
content={
<div className="max-h-chat-actions-select-model-popover overflow-y-auto">
{content({ close: () => {} })}
</div>
}
trigger="click"
noArrow
placement={
position?.poi.relativePosition[1] !== Orientation.bottom ? "lb" : "lt"
}
popoverClassName="border border-select-popover rounded-lg shadow-select-popover-shadow w-actions-popover bg-model-select-popover-panel max-h-chat-actions-select-model-popover w-[280px]"
popoverClassName="border border-select-popover rounded-lg shadow-select-popover-shadow w-actions-popover bg-model-select-popover-panel w-[280px]"
onShow={(e) => {
if (e) {
autoScrollToSelectedModal();
Expand Down
17 changes: 8 additions & 9 deletions app/containers/Chat/components/PromptHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ export default function PromptHints(props: {
return (
<div
className={`
${styles["prompt-hints"]}
transition-all duration-300 shadow-prompt-hint-container rounded-none w-[100%] flex flex-col-reverse overflow-auto
${
notShowPrompt
? "max-h-[0vh] border-none"
: "border-b pt-2.5 max-h-[50vh]"
}
${props.className}
`}
transition-all duration-300 shadow-prompt-hint-container rounded-none flex flex-col-reverse overflow-x-hidden
${
notShowPrompt
? "max-h-[0vh] border-none"
: "border-b pt-2.5 max-h-[50vh]"
}
${props.className}
`}
>
{internalPrompts.map((prompt, i) => (
<div
Expand Down
47 changes: 21 additions & 26 deletions app/containers/Chat/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -525,38 +525,33 @@
text-overflow: ellipsis;
}

.prompt-hints {
.prompt-hint {
color:var(--btn-default-text);
padding: 6px 10px;
// animation: slide-in ease 0.3s;
// cursor: pointer;
// transition: all ease 0.3s;
border: transparent 1px solid;
margin: 4px;
border-radius: 8px;
.prompt-hint {
color:var(--btn-default-text);
padding: 6px 10px;
border: transparent 1px solid;
margin: 4px;
border-radius: 8px;

&:not(:last-child) {
margin-top: 0;
}
&:not(:last-child) {
margin-top: 0;
}

.hint-title {
font-size: 12px;
font-weight: bolder;
.hint-title {
font-size: 12px;
font-weight: bolder;

@include single-line();
}
@include single-line();
}

.hint-content {
font-size: 12px;
.hint-content {
font-size: 12px;

@include single-line();
}
@include single-line();
}

&-selected,
&:hover {
border-color: var(--primary);
}
&-selected,
&:hover {
border-color: var(--primary);
}
}

Expand Down
11 changes: 10 additions & 1 deletion app/containers/Settings/components/ModelSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,23 @@ export default function ModelSetting(props: {
title={Locale.Settings.InputTemplate.Title}
subTitle={Locale.Settings.InputTemplate.SubTitle}
nextline={isMobileScreen}
validator={(v: string) => {
if (!v.includes("{{input}}")) {
return {
error: true,
message: Locale.Settings.InputTemplate.Error,
};
}

return { error: false };
}}
>
<Input
type="text"
value={props.modelConfig.template}
onChange={(e = "") =>
props.updateConfig((config) => (config.template = e))
}
className="text-center"
></Input>
</ListItem>
</>
Expand Down
Loading

0 comments on commit 00b1a97

Please sign in to comment.