feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
.explore-list-container {
|
||||
.spin {
|
||||
height: 200px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type FC } from 'react';
|
||||
|
||||
import { useRequest } from 'ahooks';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { IconCozIllusError } from '@coze-arch/coze-design/illustrations';
|
||||
import { EmptyState } from '@coze-arch/coze-design';
|
||||
|
||||
import styles from './index.module.less';
|
||||
|
||||
export const PageList: FC<{
|
||||
title: string;
|
||||
renderCard: (cardData: unknown) => React.ReactNode;
|
||||
renderCardSkeleton: () => React.ReactNode;
|
||||
getDataList: () => Promise<unknown[]>;
|
||||
}> = ({ title, renderCard, getDataList, renderCardSkeleton }) => {
|
||||
const {
|
||||
data: cardList,
|
||||
loading,
|
||||
error,
|
||||
refresh,
|
||||
} = useRequest(async () => {
|
||||
const dataList = await getDataList();
|
||||
return dataList;
|
||||
});
|
||||
console.log('data:', { cardList, loading, error });
|
||||
return (
|
||||
<div className={styles['explore-list-container']}>
|
||||
<h2 className="leading-[72px] text-[20px] m-[0] pl-[24px] pr-[24px]">
|
||||
{title}
|
||||
</h2>
|
||||
|
||||
{error && !loading ? (
|
||||
<EmptyState
|
||||
size="full_screen"
|
||||
icon={<IconCozIllusError className="coz-fg-dim text-32px" />}
|
||||
title={I18n.t('inifinit_list_load_fail')}
|
||||
buttonText={I18n.t('inifinit_list_retry')}
|
||||
onButtonClick={() => {
|
||||
refresh();
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 auto-rows-min gap-[20px] [@media(min-width:1600px)]:grid-cols-4 pl-[24px] pr-[24px]">
|
||||
{loading
|
||||
? new Array(20).fill(0).map((_, index) => renderCardSkeleton?.())
|
||||
: cardList?.map(item => renderCard(item))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
.explore-sub-menu {
|
||||
.text {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import {
|
||||
IconCozTemplate,
|
||||
IconCozTemplateFill,
|
||||
IconCozPlugin,
|
||||
IconCozPluginFill,
|
||||
} from '@coze-arch/coze-design/icons';
|
||||
import { Space } from '@coze-arch/coze-design';
|
||||
import { SubMenuItem } from '@coze-community/components';
|
||||
|
||||
import { useExploreRoute } from '../../hooks/use-explore-route';
|
||||
|
||||
const getMenuConfig = () => [
|
||||
{
|
||||
type: 'plugin',
|
||||
icon: <IconCozPlugin />,
|
||||
activeIcon: <IconCozPluginFill />,
|
||||
title: I18n.t('Plugins'),
|
||||
isActive: true,
|
||||
path: '/explore/plugin',
|
||||
},
|
||||
{
|
||||
icon: <IconCozTemplate />,
|
||||
activeIcon: <IconCozTemplateFill />,
|
||||
title: I18n.t('template_name'),
|
||||
isActive: true,
|
||||
type: 'template',
|
||||
path: '/explore/template',
|
||||
},
|
||||
];
|
||||
|
||||
export const ExploreSubMenu = () => {
|
||||
const navigate = useNavigate();
|
||||
const { type } = useExploreRoute();
|
||||
const menuConfig = getMenuConfig();
|
||||
return (
|
||||
<Space spacing={4} vertical>
|
||||
<p className="text-[14px] w-full text-left font-medium coz-fg-secondary ">
|
||||
{I18n.t('menu_title_personal_space')}
|
||||
</p>
|
||||
{menuConfig.map(item => (
|
||||
<SubMenuItem
|
||||
{...item}
|
||||
isActive={item.type === type}
|
||||
onClick={() => {
|
||||
navigate(item.path);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useRouteConfig } from '@coze-arch/bot-hooks';
|
||||
import { type TRouteConfigGlobal } from '@coze-arch/bot-hooks';
|
||||
|
||||
export interface ExploreRouteType extends TRouteConfigGlobal {
|
||||
type?: 'template' | 'plugin';
|
||||
}
|
||||
export const useExploreRoute = useRouteConfig<ExploreRouteType>;
|
||||
19
frontend/packages/community/explore/src/index.tsx
Normal file
19
frontend/packages/community/explore/src/index.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ExploreSubMenu } from './components/sub-menu';
|
||||
export { TemplatePage } from './pages/template';
|
||||
export { PluginPage } from './pages/plugin';
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { explore } from '@coze-studio/api-schema';
|
||||
|
||||
import {
|
||||
PluginCard,
|
||||
type PluginCardProps,
|
||||
PluginCardSkeleton,
|
||||
} from '@coze-community/components';
|
||||
|
||||
import { PageList } from '../../components/page-list';
|
||||
|
||||
export const PluginPage = () => (
|
||||
<PageList
|
||||
title={I18n.t('Plugins')}
|
||||
getDataList={getPluginData}
|
||||
renderCard={data => <PluginCard {...(data as PluginCardProps)} />}
|
||||
renderCardSkeleton={() => <PluginCardSkeleton />}
|
||||
/>
|
||||
);
|
||||
|
||||
const getPluginData = async () => {
|
||||
const result = await explore.PublicGetProductList({
|
||||
entity_type: explore.product_common.ProductEntityType.Plugin,
|
||||
sort_type: explore.product_common.SortType.Newest,
|
||||
page_num: 0,
|
||||
page_size: 1000,
|
||||
});
|
||||
return result.data?.products || [];
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { explore } from '@coze-studio/api-schema';
|
||||
import {
|
||||
TemplateCard,
|
||||
type TemplateCardProps,
|
||||
TemplateCardSkeleton,
|
||||
} from '@coze-community/components';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import { PageList } from '../../components/page-list';
|
||||
|
||||
export const TemplatePage = () => (
|
||||
<PageList
|
||||
title={I18n.t('template_name')}
|
||||
getDataList={() => getTemplateData()}
|
||||
renderCard={data => <TemplateCard {...(data as TemplateCardProps)} />}
|
||||
renderCardSkeleton={() => <TemplateCardSkeleton />}
|
||||
/>
|
||||
);
|
||||
|
||||
const getTemplateData = async () => {
|
||||
const result = await explore.PublicGetProductList({
|
||||
entity_type: explore.product_common.ProductEntityType.TemplateCommon,
|
||||
sort_type: explore.product_common.SortType.Newest,
|
||||
page_num: 0,
|
||||
page_size: 1000,
|
||||
});
|
||||
return result.data?.products || [];
|
||||
};
|
||||
17
frontend/packages/community/explore/src/typings.d.ts
vendored
Normal file
17
frontend/packages/community/explore/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
Reference in New Issue
Block a user