Skip to content

Commit

Permalink
Add simple mode (#113)
Browse files Browse the repository at this point in the history
* Add simple mode

The current UI is too complicated for some first time users.
This commit adds a "Advanced mode" toggle that defaults on but can be
turned off. When the toggle if switched off, the simple mode is
activated and following UI elements are hided:

- Model parameters setting
- Role switch
- Save button (This means user must save *and* submit in simple mode.)

* Simple mode: Fix ctrl-enter in non-sticky blocks

* i18n

* hide token count

* add back save button

* remove unused variables

---------

Co-authored-by: Jing Hua <[email protected]>
  • Loading branch information
peng1999 and ztjhz committed Apr 15, 2023
1 parent f5f777b commit c2d833b
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 10 deletions.
1 change: 1 addition & 0 deletions public/locales/da/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Indstillinger",
"image": "Billede",
"autoTitle": "Auto generer titel",
"advancedMode": "Avanceret tilstand",
"prompt": "Opgave",
"promptLibrary": "Opgavebibliotek",
"name": "Navn",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en-US/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Settings",
"image": "Image",
"autoTitle": "Auto generate title",
"advancedMode": "Advanced mode",
"prompt": "Prompt",
"promptLibrary": "Prompt Library",
"name": "Name",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Settings",
"image": "Image",
"autoTitle": "Auto generate title",
"advancedMode": "Advanced mode",
"prompt": "Prompt",
"promptLibrary": "Prompt Library",
"name": "Name",
Expand Down
1 change: 1 addition & 0 deletions public/locales/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Ajustes",
"image": "Imagen",
"autoTitle": "Generar automáticamente el título de la conversación.",
"advancedMode": "Modo avanzado",
"prompt": "Prompt",
"promptLibrary": "Librería de Prompts",
"name": "Nombre",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Paramètres",
"image": "Image",
"autoTitle": "Générer le titre automatiquement",
"advancedMode": "Mode avancé",
"prompt": "Incitation",
"promptLibrary": "Bibliothèque de prompt",
"name": "Nom",
Expand Down
1 change: 1 addition & 0 deletions public/locales/it/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Impostazioni",
"image": "Immagine",
"autoTitle": "Genera automaticamente il titolo",
"advancedMode": "Modalità avanzata",
"prompt": "Prompt",
"promptLibrary": "Libreria Prompt",
"name": "Nome",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "設定",
"image": "画像",
"autoTitle": "タイトルを自動生成",
"advancedMode": "上級モード",
"prompt": "プロンプト",
"promptLibrary": "プロンプトライブラリ",
"name": "名前",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ms/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Tetapan",
"image": "Imej",
"autoTitle": "Jana tajuk secara automatik",
"advancedMode": "Mod lanjutan",
"prompt": "Arahan",
"promptLibrary": "Pustaka Arahan",
"name": "Nama",
Expand Down
1 change: 1 addition & 0 deletions public/locales/nb/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Innstillinger",
"image": "Bilde",
"autoTitle": "Auto generer tittel",
"advancedMode": "Avansert modus",
"prompt": "Oppgave",
"promptLibrary": "Oppgavebibliotek",
"name": "Navn",
Expand Down
1 change: 1 addition & 0 deletions public/locales/sv/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "Inställningar",
"image": "Bild",
"autoTitle": "Auto generera titel",
"advancedMode": "Avancerat läge",
"prompt": "Uppmaning",
"promptLibrary": "Uppmaningsbibliotek",
"name": "Namn",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-CN/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "设置",
"image": "图片",
"autoTitle": "自动生成标题",
"advancedMode": "高级模式",
"prompt": "提示词",
"promptLibrary": "提示词资料库",
"name": "名称",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-HK/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "設定",
"image": "圖片",
"autoTitle": "自動生成標題",
"advancedMode": "高級模式",
"prompt": "Prompt",
"promptLibrary": "Prompt 資料庫",
"name": "",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-TW/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"setting": "設定",
"image": "圖片",
"autoTitle": "自動生成標題",
"advancedMode": "高級模式",
"prompt": "提示詞",
"promptLibrary": "提示詞資料庫",
"name": "名稱",
Expand Down
7 changes: 4 additions & 3 deletions src/components/Chat/ChatContent/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ChatContent = () => {
? state.chats[state.currentChatIndex].messages.length
: 0
);
const advancedMode = useStore((state) => state.advancedMode);
const generating = useStore.getState().generating;
const hideSideMenu = useStore((state) => state.hideSideMenu);

Expand All @@ -58,8 +59,8 @@ const ChatContent = () => {
className='flex flex-col items-center text-sm dark:bg-gray-800 w-full'
ref={saveRef}
>
<ChatTitle />
{!generating && messages?.length === 0 && (
{advancedMode && <ChatTitle />}
{!generating && advancedMode && messages?.length === 0 && (
<NewMessageButton messageIndex={-1} />
)}
{messages?.map((message, index) => (
Expand All @@ -69,7 +70,7 @@ const ChatContent = () => {
content={message.content}
messageIndex={index}
/>
{!generating && <NewMessageButton messageIndex={index} />}
{!generating && advancedMode && <NewMessageButton messageIndex={index} />}
</React.Fragment>
))}
</div>
Expand Down
12 changes: 7 additions & 5 deletions src/components/Chat/ChatContent/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Message = React.memo(
sticky?: boolean;
}) => {
const hideSideMenu = useStore((state) => state.hideSideMenu);
const advancedMode = useStore((state) => state.advancedMode);

return (
<div
Expand All @@ -43,11 +44,12 @@ const Message = React.memo(
>
<Avatar role={role} />
<div className='w-[calc(100%-50px)] '>
<RoleSelector
role={role}
messageIndex={messageIndex}
sticky={sticky}
/>
{advancedMode &&
<RoleSelector
role={role}
messageIndex={messageIndex}
sticky={sticky}
/>}
<MessageContent
role={role}
content={content}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Chat/ChatContent/Message/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const MessageContent = ({
sticky?: boolean;
}) => {
const [isEdit, setIsEdit] = useState<boolean>(sticky);
const advancedMode = useStore((state) => state.advancedMode);

return (
<div className='relative flex flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]'>
<div className='flex flex-grow flex-col gap-3'></div>
{advancedMode && <div className='flex flex-grow flex-col gap-3'></div>}
{isEdit ? (
<EditView
content={content}
Expand Down Expand Up @@ -483,6 +484,7 @@ const EditViewButtons = React.memo(
}) => {
const { t } = useTranslation();
const generating = useStore.getState().generating;
const advancedMode = useStore((state) => state.advancedMode);

return (
<div className='flex'>
Expand Down Expand Up @@ -539,7 +541,7 @@ const EditViewButtons = React.memo(
</button>
)}
</div>
{sticky && <TokenCount />}
{sticky && advancedMode && <TokenCount />}
<CommandPrompt _setContent={_setContent} />
</div>
);
Expand Down
28 changes: 28 additions & 0 deletions src/components/SettingsMenu/AdvencedModeToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import useStore from '@store/store';
import Toggle from '@components/Toggle';

const AdvancedModeToggle = () => {
const { t } = useTranslation();

const setAdvancedMode = useStore((state) => state.setAdvancedMode);

const [isChecked, setIsChecked] = useState<boolean>(
useStore.getState().advancedMode
);

useEffect(() => {
setAdvancedMode(isChecked);
}, [isChecked]);

return (
<Toggle
label={t('advancedMode') as string}
isChecked={isChecked}
setIsChecked={setIsChecked}
/>
);
};

export default AdvancedModeToggle;
2 changes: 2 additions & 0 deletions src/components/SettingsMenu/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SettingIcon from '@icon/SettingIcon';
import ThemeSwitcher from '@components/Menu/MenuOptions/ThemeSwitcher';
import LanguageSelector from '@components/LanguageSelector';
import AutoTitleToggle from './AutoTitleToggle';
import AdvancedModeToggle from './AdvencedModeToggle';
import PromptLibraryMenu from '@components/PromptLibraryMenu';
import ChatConfigMenu from '@components/ChatConfigMenu';
import EnterToSubmitToggle from './EnterToSubmitToggle';
Expand Down Expand Up @@ -44,6 +45,7 @@ const SettingsMenu = () => {
<div className='flex flex-col gap-3'>
<AutoTitleToggle />
<EnterToSubmitToggle />
<AdvancedModeToggle />
</div>
<PromptLibraryMenu />
<ChatConfigMenu />
Expand Down
9 changes: 9 additions & 0 deletions src/store/config-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export interface ConfigSlice {
theme: Theme;
autoTitle: boolean;
hideMenuOptions: boolean;
advancedMode: boolean;
defaultChatConfig: ConfigInterface;
defaultSystemMessage: string;
hideSideMenu: boolean;
enterToSubmit: boolean;
setOpenConfig: (openConfig: boolean) => void;
setTheme: (theme: Theme) => void;
setAutoTitle: (autoTitle: boolean) => void;
setAdvancedMode: (advancedMode: boolean) => void;
setDefaultChatConfig: (defaultChatConfig: ConfigInterface) => void;
setDefaultSystemMessage: (defaultSystemMessage: string) => void;
setHideMenuOptions: (hideMenuOptions: boolean) => void;
Expand All @@ -29,6 +31,7 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
hideSideMenu: false,
autoTitle: false,
enterToSubmit: true,
advancedMode: true,
defaultChatConfig: _defaultChatConfig,
defaultSystemMessage: _defaultSystemMessage,
setOpenConfig: (openConfig: boolean) => {
Expand All @@ -49,6 +52,12 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
autoTitle: autoTitle,
}));
},
setAdvancedMode: (advancedMode: boolean) => {
set((prev: ConfigSlice) => ({
...prev,
advancedMode: advancedMode,
}));
},
setDefaultChatConfig: (defaultChatConfig: ConfigInterface) => {
set((prev: ConfigSlice) => ({
...prev,
Expand Down
1 change: 1 addition & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const createPartializedState = (state: StoreState) => ({
apiEndpoint: state.apiEndpoint,
theme: state.theme,
autoTitle: state.autoTitle,
advancedMode: state.advancedMode,
prompts: state.prompts,
defaultChatConfig: state.defaultChatConfig,
defaultSystemMessage: state.defaultSystemMessage,
Expand Down

0 comments on commit c2d833b

Please sign in to comment.