Skip to content

Commit

Permalink
Merge pull request #115 from lobehub/fix/common-error
Browse files Browse the repository at this point in the history
Fix/common error
  • Loading branch information
rdmclin2 authored Jul 14, 2024
2 parents 7f79bb0 + 14084ff commit 31a1d98
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 178 deletions.
13 changes: 10 additions & 3 deletions src/app/settings/Settings/touch/ActionList/List/FemaleList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Empty } from 'antd';
import { isEqual } from 'lodash-es';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -16,19 +17,19 @@ interface AreaListProps {

const AreaList = memo((props: AreaListProps) => {
const { currentTouchArea } = props;
const female = useSettingStore(
const items = useSettingStore(
(s) => configSelectors.getTouchActionsByGenderAndArea(s, GenderEnum.FEMALE, currentTouchArea),
isEqual,
);
const { t } = useTranslation('features');
const { t } = useTranslation(['features', 'panel']);

return (
<>
<Header
title={t('agent.female')}
extra={<AddOrEdit isEdit={false} touchArea={currentTouchArea} gender={GenderEnum.FEMALE} />}
/>
{female.map((item, index) => {
{items.map((item, index) => {
return (
<ListItem
item={item}
Expand All @@ -39,6 +40,12 @@ const AreaList = memo((props: AreaListProps) => {
/>
);
})}
{items.length === 0 && (
<Empty
description={t('touch.noTouchActions', { ns: 'panel' })}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
)}
</>
);
});
Expand Down
13 changes: 10 additions & 3 deletions src/app/settings/Settings/touch/ActionList/List/MaleList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Empty } from 'antd';
import { isEqual } from 'lodash-es';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -16,19 +17,19 @@ interface AreaListProps {

const AreaList = memo((props: AreaListProps) => {
const { currentTouchArea } = props;
const touchList = useSettingStore(
const items = useSettingStore(
(s) => configSelectors.getTouchActionsByGenderAndArea(s, GenderEnum.MALE, currentTouchArea),
isEqual,
);
const { t } = useTranslation('features');
const { t } = useTranslation(['features', 'panel']);

return (
<>
<Header
title={t('agent.male')}
extra={<AddOrEdit isEdit={false} touchArea={currentTouchArea} gender={GenderEnum.MALE} />}
/>
{touchList.map((item, index) => {
{items.map((item, index) => {
return (
<ListItem
item={item}
Expand All @@ -39,6 +40,12 @@ const AreaList = memo((props: AreaListProps) => {
/>
);
})}
{items.length === 0 && (
<Empty
description={t('touch.noTouchActions', { ns: 'panel' })}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
)}
</>
);
});
Expand Down
13 changes: 10 additions & 3 deletions src/app/settings/Settings/touch/ActionList/List/OtherList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Empty } from 'antd';
import { isEqual } from 'lodash-es';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -16,19 +17,19 @@ interface AreaListProps {

const AreaList = memo((props: AreaListProps) => {
const { currentTouchArea } = props;
const touchList = useSettingStore(
const items = useSettingStore(
(s) => configSelectors.getTouchActionsByGenderAndArea(s, GenderEnum.OTHER, currentTouchArea),
isEqual,
);
const { t } = useTranslation('features');
const { t } = useTranslation(['features', 'panel']);

return (
<>
<Header
title={t('agent.other')}
extra={<AddOrEdit isEdit={false} touchArea={currentTouchArea} gender={GenderEnum.OTHER} />}
/>
{touchList.map((item, index) => {
{items.map((item, index) => {
return (
<ListItem
item={item}
Expand All @@ -39,6 +40,12 @@ const AreaList = memo((props: AreaListProps) => {
/>
);
})}
{items.length === 0 && (
<Empty
description={t('touch.noTouchActions', { ns: 'panel' })}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
)}
</>
);
});
Expand Down
1 change: 0 additions & 1 deletion src/features/Actions/Agent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const ThemeButton = memo(() => {
overlayInnerStyle={{
padding: 0,
}}
trigger={['click']}
>
<ActionIcon icon={PlusCircle} title={t('agent.create')} />
</Popover>
Expand Down
8 changes: 6 additions & 2 deletions src/features/Actions/SubmitAgentButton/SubmitAgentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { Alert, Icon, Modal, type ModalProps } from '@lobehub/ui';
import { Button, Divider, Input, Popover, Progress, Space, Typography } from 'antd';
import { Button, Divider, Input, Popover, Progress, Space, Typography, message } from 'antd';
import { useTheme } from 'antd-style';
import isEqual from 'fast-deep-equal';
import { kebabCase } from 'lodash-es';
Expand All @@ -26,7 +26,7 @@ const SubmitAgentModal = memo<ModalProps>(({ open, onCancel }) => {
isEqual,
);
const meta = currentAgent?.meta;
const { t } = useTranslation('features');
const { t } = useTranslation(['features', 'error']);

const { uploading, uploadAgentData, percent } = useUploadAgent();

Expand All @@ -45,6 +45,10 @@ const SubmitAgentModal = memo<ModalProps>(({ open, onCancel }) => {
}

const { avatarUrl, coverUrl, modelUrl } = await uploadAgentData(agentId, meta);
if (!avatarUrl || !coverUrl || !modelUrl) {
message.error(t('fileUploadError', { ns: 'error' }));
return;
}

const body = [
'### agentId',
Expand Down
30 changes: 0 additions & 30 deletions src/features/Actions/UnSubscribeButton.tsx

This file was deleted.

35 changes: 35 additions & 0 deletions src/features/MarketInfo/actions/ChatButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Button } from 'antd';
import { useRouter } from 'next/navigation';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useGlobalStore } from '@/store/global';
import { useSessionStore } from '@/store/session';
import { Agent } from '@/types/agent';

interface ChatButtonProps {
agent: Agent;
}

const ChatButton = memo<ChatButtonProps>(({ agent }) => {
const router = useRouter();
const { t } = useTranslation('chat');
const createSession = useSessionStore((s) => s.createSession);

const [closePanel] = useGlobalStore((s) => [s.closePanel]);
return (
<Button
key="chat"
onClick={() => {
createSession(agent);
router.push('/chat');
closePanel('market');
}}
type={'primary'}
>
{t('chat')}
</Button>
);
});

export default ChatButton;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Popover, Progress, Space, message } from 'antd';
import { Button, Popover, Progress, Space } from 'antd';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';
Expand All @@ -11,16 +11,11 @@ interface SubscribeButtonProps {
agent: Agent;
}

const SubscribeButton = memo((props: SubscribeButtonProps) => {
const [removeLocalAgent, subscribed] = useAgentStore((s) => [
s.removeLocalAgent,
agentSelectors.subscribed(s),
]);

const { fetchAgentData, percent, downloading } = useDownloadAgent();

const Subscribe = memo((props: SubscribeButtonProps) => {
const { agent } = props;
const subscribed = useAgentStore((s) => agentSelectors.subscribed(s));

const { fetchAgentData, percent, downloading } = useDownloadAgent();
const isSubscribed = subscribed(agent.agentId);

const { t } = useTranslation('common');
Expand Down Expand Up @@ -49,20 +44,14 @@ const SubscribeButton = memo((props: SubscribeButtonProps) => {
key={'subscribe'}
disabled={downloading}
onClick={async () => {
if (isSubscribed) {
removeLocalAgent(agent.agentId).then(() => {
message.success(t('actions.unsubscribeSuccess'));
});
} else {
await fetchAgentData(agent);
}
await fetchAgentData(agent);
}}
type={isSubscribed ? 'default' : 'primary'}
>
{isSubscribed ? t('actions.unsubscribe') : t('actions.downloadSubscribe')}
{t('actions.downloadSubscribe')}
</Button>
</Popover>
);
});

export default SubscribeButton;
export default Subscribe;
44 changes: 44 additions & 0 deletions src/features/MarketInfo/actions/UnSubscribe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Button, Popconfirm, message } from 'antd';
import React, { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useAgentStore } from '@/store/agent';
import { useSessionStore } from '@/store/session';
import { Agent } from '@/types/agent';

interface UnSubscribeButtonProps {
agent: Agent;
}

const UnSubscribe = memo((props: UnSubscribeButtonProps) => {
const { agent } = props;
const removeLocalAgent = useAgentStore((s) => s.removeLocalAgent);
const removeSessionByAgentId = useSessionStore((s) => s.removeSessionByAgentId);
const [loading, setLoading] = useState(false);

const { t } = useTranslation(['common', 'role']);

return (
<Popconfirm
cancelText={t('cancel')}
description={t('delRoleDesc', { name: agent?.meta.name, ns: 'role' })}
key="delete"
overlayStyle={{ width: 416 }}
okText={t('confirm')}
okButtonProps={{ loading: loading, danger: true }}
onConfirm={async () => {
if (!agent) return;
setLoading(true);
await removeLocalAgent(agent.agentId);
removeSessionByAgentId(agent.agentId);
setLoading(false);
message.success(t('actions.unsubscribeSuccess'));
}}
title={t('actions.unsubscribe') + '?'}
>
<Button>{t('actions.unsubscribe')}</Button>
</Popconfirm>
);
});

export default UnSubscribe;
36 changes: 10 additions & 26 deletions src/features/MarketInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { DraggablePanel } from '@lobehub/ui';
import { Button } from 'antd';
import { createStyles } from 'antd-style';
import { useRouter } from 'next/navigation';
import React, { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import Author from '@/components/Author';
import AgentCard from '@/components/agent/AgentCard';
import SystemRole from '@/components/agent/SystemRole';
import { SIDEBAR_MAX_WIDTH, SIDEBAR_WIDTH } from '@/constants/token';
import SubscribeButton from '@/features/MarketInfo/SubscribeButton';
import { agentSelectors, useAgentStore } from '@/store/agent';
import { useGlobalStore } from '@/store/global';
import { marketStoreSelectors, useMarketStore } from '@/store/market';
import { useSessionStore } from '@/store/session';

import ChatButton from './actions/ChatButton';
import Subscribe from './actions/Subscribe';
import UnSubscribe from './actions/UnSubscribe';

const useStyles = createStyles(({ css, token }) => ({
content: css`
Expand All @@ -29,8 +27,6 @@ const useStyles = createStyles(({ css, token }) => ({

const Header = () => {
const { styles } = useStyles();
const router = useRouter();
const { t } = useTranslation('chat');
const [tempId, setTempId] = useState<string>('');
const [showAgentSidebar, activateAgent, deactivateAgent, currentAgentItem] = useMarketStore(
(s) => [
Expand All @@ -40,34 +36,22 @@ const Header = () => {
marketStoreSelectors.currentAgentItem(s),
],
);
const [closePanel] = useGlobalStore((s) => [s.closePanel]);
const [subscribed] = useAgentStore((s) => [agentSelectors.subscribed(s)]);

const createSession = useSessionStore((s) => s.createSession);

const actions = [];
if (currentAgentItem) {
const isSubscribed = subscribed(currentAgentItem.agentId);

if (isSubscribed) {
actions.push(
<Button
key="chat"
onClick={() => {
createSession(currentAgentItem);
router.push('/chat');
closePanel('market');
}}
type={'primary'}
>
{t('chat')}
</Button>,
<ChatButton key="chat" agent={currentAgentItem} />,
<UnSubscribe key="unsubscribe" agent={currentAgentItem} />,
);
} else {
actions.push(
<Subscribe agent={currentAgentItem} key={`${currentAgentItem.agentId}-subscribe`} />,
);
}

actions.push(
<SubscribeButton agent={currentAgentItem} key={`${currentAgentItem.agentId}-subscribe`} />,
);
}

return (
Expand Down
Loading

0 comments on commit 31a1d98

Please sign in to comment.