Skip to content

Commit

Permalink
💄 style: Update Markdown in ChatItem
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Mar 15, 2024
1 parent 7d4d83e commit be75549
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 76 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
"@icons-pack/react-simple-icons": "^9",
"@lobehub/chat-plugin-sdk": "latest",
"@lobehub/chat-plugins-gateway": "latest",
"@lobehub/icons": "^1.13.0",
"@lobehub/icons": "latest",
"@lobehub/tts": "latest",
"@lobehub/ui": "^1.129.2",
"@lobehub/ui": "latest",
"@vercel/analytics": "^1",
"ahooks": "^3",
"ai": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/chat/features/ChatHeader/ShareButton/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Preview = memo<FieldType & { title?: string }>(
</Flexbox>
{withSystemRole && systemRole && (
<div className={styles.role}>
<Markdown className={styles.markdown}>{systemRole}</Markdown>
<Markdown variant={'chat'}>{systemRole}</Markdown>
</div>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/app/chat/features/ChatHeader/ShareButton/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const useStyles = createStyles(({ css, token, stylish, cx }, withBackgrou
background: ${token.colorBgContainer};
border-bottom: 1px solid ${token.colorBorder};
`,
markdown: stylish.markdownInChat,
preview: cx(
stylish.noScrollbar,
css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const AgentModalInner = memo(() => {
</Flexbox>
<Flexbox style={{ padding: 16 }}>
{tab === InfoTabs.prompt && (
<Markdown className={styles.markdown} fullFeaturedCodeBlock>
<Markdown fullFeaturedCodeBlock variant={'chat'}>
{systemRole}
</Markdown>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ css, token, prefixCls, stylish }) => ({
export const useStyles = createStyles(({ css, token, prefixCls }) => ({
author: css`
font-size: 12px;
`,
Expand All @@ -27,7 +27,6 @@ export const useStyles = createStyles(({ css, token, prefixCls, stylish }) => ({
flex-direction: column;
}
`,
markdown: stylish.markdownInChat,
nav: css`
padding-top: 8px;
`,
Expand Down
11 changes: 4 additions & 7 deletions src/app/settings/llm/Azure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import { LLMProviderApiTokenKey, LLMProviderBaseUrlKey, LLMProviderConfigKey } f

const useStyles = createStyles(({ css, token }) => ({
markdown: css`
a {
font-size: 12px !important;
}
p {
font-size: 12px !important;
color: ${token.colorTextDescription} !important;
}
`,
Expand Down Expand Up @@ -73,7 +68,7 @@ const AzureOpenAIProvider = memo(() => {
/>
),
desc: (
<Markdown className={styles.markdown}>
<Markdown className={styles.markdown} fontSize={12} variant={'chat'}>
{t('llm.AzureOpenAI.azureApiVersion.desc')}
</Markdown>
),
Expand All @@ -89,7 +84,9 @@ const AzureOpenAIProvider = memo(() => {
/>
),
desc: (
<Markdown className={styles.markdown}>{t('llm.AzureOpenAI.deployments.desc')}</Markdown>
<Markdown className={styles.markdown} fontSize={12} variant={'chat'}>
{t('llm.AzureOpenAI.deployments.desc')}
</Markdown>
),

label: t('llm.AzureOpenAI.deployments.title'),
Expand Down
9 changes: 3 additions & 6 deletions src/app/settings/llm/OpenAI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import { LLMProviderConfigKey } from '../const';

const useStyles = createStyles(({ css, token }) => ({
markdown: css`
a {
font-size: 12px !important;
}
p {
font-size: 12px !important;
color: ${token.colorTextDescription} !important;
}
`,
Expand Down Expand Up @@ -110,7 +105,9 @@ const LLM = memo(() => {
/>
),
desc: (
<Markdown className={styles.markdown}>{t('llm.OpenAI.azureApiVersion.desc')}</Markdown>
<Markdown className={styles.markdown} fontSize={12} variant={'chat'}>
{t('llm.OpenAI.azureApiVersion.desc')}
</Markdown>
),
hidden: !useAzure,
label: t('llm.OpenAI.azureApiVersion.title'),
Expand Down
6 changes: 2 additions & 4 deletions src/features/AgentInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import { Center } from 'react-layout-kit';

import { MetaData } from '@/types/meta';

const useStyles = createStyles(({ css, token, stylish }) => ({
const useStyles = createStyles(({ css, token }) => ({
avatar: css`
flex: none;
`,
desc: css`
color: ${token.colorTextDescription};
text-align: center;
`,
markdown: stylish.markdownInChat,

title: css`
font-size: 20px;
font-weight: 600;
Expand Down Expand Up @@ -62,7 +60,7 @@ const AgentInfo = memo<AgentInfoProps>(({ systemRole, style, meta, onAvatarClick
{systemRole && (
<>
<Divider style={{ margin: '8px 0' }} />
<Markdown className={styles.markdown}>{systemRole}</Markdown>
<Markdown variant={'chat'}>{systemRole}</Markdown>
</>
)}
</Center>
Expand Down
10 changes: 3 additions & 7 deletions src/features/Conversation/Extras/Translate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionIcon, Icon, Markdown, Tag, copyToClipboard } from '@lobehub/ui';
import { App } from 'antd';
import { createStyles } from 'antd-style';
import { useTheme } from 'antd-style';
import { ChevronDown, ChevronUp, ChevronsRight, CopyIcon, TrashIcon } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -11,17 +11,13 @@ import { ChatTranslate } from '@/types/message';

import BubblesLoading from '../components/BubblesLoading';

const useStyles = createStyles(({ stylish }) => ({
markdown: stylish.markdownInChat,
}));

interface TranslateProps extends ChatTranslate {
id: string;
loading?: boolean;
}

const Translate = memo<TranslateProps>(({ content = '', from, to, id, loading }) => {
const { theme, styles } = useStyles();
const theme = useTheme();
const { t } = useTranslation('common');
const [show, setShow] = useState(true);
const clearTranslate = useChatStore((s) => s.clearTranslate);
Expand Down Expand Up @@ -67,7 +63,7 @@ const Translate = memo<TranslateProps>(({ content = '', from, to, id, loading })
{!show ? null : loading && !content ? (
<BubblesLoading />
) : (
<Markdown className={styles.markdown}>{content}</Markdown>
<Markdown variant={'chat'}>{content}</Markdown>
)}
</Flexbox>
);
Expand Down
10 changes: 9 additions & 1 deletion src/features/Conversation/Plugins/Render/MarkdownType/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Markdown } from '@lobehub/ui';
import { memo } from 'react';

import { useGlobalStore } from '@/store/global';
import { settingsSelectors } from '@/store/global/selectors';

import Loading from '../Loading';

export interface PluginMarkdownTypeProps {
Expand All @@ -9,9 +12,14 @@ export interface PluginMarkdownTypeProps {
}

const PluginMarkdownType = memo<PluginMarkdownTypeProps>(({ content, loading }) => {
const fontSize = useGlobalStore((s) => settingsSelectors.currentSettings(s).fontSize);
if (loading) return <Loading />;

return <Markdown>{content}</Markdown>;
return (
<Markdown fontSize={fontSize} variant={'chat'}>
{content}
</Markdown>
);
});

export default PluginMarkdownType;
4 changes: 4 additions & 0 deletions src/features/Conversation/components/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useTranslation } from 'react-i18next';

import { useChatStore } from '@/store/chat';
import { chatSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
import { settingsSelectors } from '@/store/global/selectors';
import { useSessionStore } from '@/store/session';
import { agentSelectors } from '@/store/session/selectors';
import { ChatMessage } from '@/types/message';
Expand All @@ -31,6 +33,7 @@ export interface ChatListItemProps {
}

const Item = memo<ChatListItemProps>(({ index, id }) => {
const fontSize = useGlobalStore((s) => settingsSelectors.currentSettings(s).fontSize);
const { t } = useTranslation('common');
const { styles } = useStyles();
const [editing, setEditing] = useState(false);
Expand Down Expand Up @@ -111,6 +114,7 @@ const Item = memo<ChatListItemProps>(({ index, id }) => {
editing={editing}
error={error}
errorMessage={<ErrorMessageExtra data={item} />}
fontSize={fontSize}
loading={loading}
message={item.content}
messageExtra={<MessageExtra data={item} />}
Expand Down
43 changes: 12 additions & 31 deletions src/features/Conversation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,22 @@ import { ReactNode, memo } from 'react';
import { Flexbox } from 'react-layout-kit';

import ChatHydration from '@/components/StoreHydration/ChatHydration';
import { useGlobalStore } from '@/store/global';
import { settingsSelectors } from '@/store/global/selectors';

import SkeletonList from './components/SkeletonList';
import ChatList from './components/VirtualizedList';
import { useInitConversation } from './hooks/useInitConversation';

const useStyles = createStyles(({ css, responsive, stylish, cx }, fontSize: number = 14) =>
cx(
css`
position: relative;
overflow-y: auto;
height: 100%;
${responsive.mobile} {
${stylish.noScrollbar}
width: 100vw;
}
`,
fontSize !== 14 &&
css`
article[data-code-type='markdown'] {
p,
code,
pre,
ul,
ol,
li,
blockquote {
font-size: ${fontSize}px;
}
}
`,
),
const useStyles = createStyles(
({ css, responsive, stylish }) => css`
position: relative;
overflow-y: auto;
height: 100%;
${responsive.mobile} {
${stylish.noScrollbar}
width: 100vw;
}
`,
);

interface ConversationProps {
Expand All @@ -45,8 +27,7 @@ interface ConversationProps {
}

const Conversation = memo<ConversationProps>(({ chatInput, mobile }) => {
const fontSize = useGlobalStore((s) => settingsSelectors.currentSettings(s).fontSize);
const { styles } = useStyles(fontSize);
const { styles } = useStyles();

const init = useInitConversation();

Expand Down
4 changes: 1 addition & 3 deletions src/features/PluginDetailModal/Meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import { Center } from 'react-layout-kit';
import { pluginHelpers, useToolStore } from '@/store/tool';
import { pluginSelectors } from '@/store/tool/selectors';

const useStyles = createStyles(({ css, token, stylish }) => ({
const useStyles = createStyles(({ css, token }) => ({
avatar: css`
flex: none;
`,
desc: css`
color: ${token.colorTextDescription};
text-align: center;
`,
markdown: stylish.markdownInChat,

title: css`
font-size: 20px;
font-weight: 600;
Expand Down
23 changes: 13 additions & 10 deletions src/features/PluginSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ interface PluginSettingsConfigProps {
schema: PluginSchema;
}

const useStyles = createStyles(({ css, token, stylish, cx }) => ({
markdown: cx(
stylish.markdownInChat,
css`
p {
color: ${token.colorTextDescription};
}
`,
),
const useStyles = createStyles(({ css, token }) => ({
markdown: css`
p {
color: ${token.colorTextDescription};
}
`,
}));

const PluginSettingsConfig = memo<PluginSettingsConfigProps>(({ schema, id }) => {
Expand All @@ -59,7 +56,13 @@ const PluginSettingsConfig = memo<PluginSettingsConfigProps>(({ schema, id }) =>
<Form form={form} layout={'vertical'} style={{ width: '100%' }}>
{items.map((item) => (
<Form.Item
desc={item.desc && <Markdown className={styles.markdown}>{item.desc as string}</Markdown>}
desc={
item.desc && (
<Markdown className={styles.markdown} variant={'chat'}>
{item.desc as string}
</Markdown>
)
}
key={item.label}
label={item.label}
tag={item.tag}
Expand Down

0 comments on commit be75549

Please sign in to comment.