Commit ecc2ffda authored by StyleZhang's avatar StyleZhang

feat: refact nav

parent 17d19612
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13.6666 4.85185L7.99998 8M7.99998 8L2.33331 4.85185M7.99998 8L8 14.3333M14 10.7057V5.29431C14 5.06588 14 4.95167 13.9663 4.8498C13.9366 4.75969 13.8879 4.67696 13.8236 4.60717C13.7509 4.52828 13.651 4.47281 13.4514 4.36188L8.51802 1.62114C8.32895 1.5161 8.23442 1.46358 8.1343 1.44299C8.0457 1.42477 7.95431 1.42477 7.8657 1.44299C7.76559 1.46358 7.67105 1.5161 7.48198 1.62114L2.54865 4.36188C2.34896 4.47281 2.24912 4.52828 2.17642 4.60717C2.11211 4.67697 2.06343 4.75969 2.03366 4.84981C2 4.95167 2 5.06588 2 5.29431V10.7057C2 10.9341 2 11.0484 2.03366 11.1502C2.06343 11.2403 2.11211 11.3231 2.17642 11.3929C2.24912 11.4718 2.34897 11.5272 2.54865 11.6382L7.48198 14.3789C7.67105 14.4839 7.76559 14.5365 7.8657 14.557C7.95431 14.5753 8.0457 14.5753 8.1343 14.557C8.23442 14.5365 8.32895 14.4839 8.51802 14.3789L13.4514 11.6382C13.651 11.5272 13.7509 11.4718 13.8236 11.3929C13.8879 11.3231 13.9366 11.2403 13.9663 11.1502C14 11.0484 14 10.9341 14 10.7057Z" stroke="#667085" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.29782 0.790031C8.12061 0.753584 7.93783 0.753584 7.76062 0.790031C7.55577 0.832161 7.37268 0.934712 7.22712 1.01624L7.18744 1.03841C6.01215 1.69134 4.02394 2.79644 2.90301 3.41952C2.63085 3.5708 2.49477 3.64644 2.44929 3.74641C2.40965 3.83357 2.4094 3.93356 2.4486 4.02091C2.49357 4.12111 2.62938 4.19751 2.90101 4.3503L7.76772 7.08785C7.8631 7.1415 7.91079 7.16832 7.96135 7.17884C8.0061 7.18814 8.05229 7.18814 8.09703 7.17884C8.1476 7.16832 8.19529 7.1415 8.29067 7.08785L13.1574 4.35029C13.429 4.1975 13.5649 4.12111 13.6098 4.02091C13.649 3.93355 13.6488 3.83356 13.6091 3.74641C13.5637 3.64644 13.4276 3.57079 13.1554 3.41951C12.0345 2.79644 10.0463 1.69134 8.871 1.03841L8.83132 1.01624C8.68576 0.934713 8.50267 0.832161 8.29782 0.790031Z" fill="#155EEF"/>
<path d="M14.6932 5.92676C14.6929 5.62787 14.6928 5.47842 14.6297 5.39117C14.5748 5.31504 14.4902 5.26564 14.3969 5.25511C14.2899 5.24305 14.1594 5.31646 13.8984 5.46329L8.96774 8.23679C8.86877 8.29246 8.81928 8.3203 8.78326 8.35968C8.75139 8.39452 8.72729 8.43573 8.71254 8.48059C8.69588 8.53129 8.69588 8.58807 8.69588 8.70163V14.1518C8.69588 14.4499 8.69588 14.599 8.75856 14.6862C8.81326 14.7623 8.89744 14.8118 8.9905 14.8227C9.09716 14.8352 9.22706 14.763 9.48688 14.6188C10.5978 14.0019 12.6169 12.8807 13.8043 12.221L13.8464 12.1977C14.0005 12.1128 14.1943 12.0061 14.343 11.8447C14.4717 11.7051 14.569 11.5397 14.6286 11.3594C14.6975 11.1509 14.6966 10.9298 14.696 10.7538L14.6959 10.7058C14.6959 9.39704 14.6942 7.17087 14.6932 5.92676Z" fill="#155EEF"/>
<path d="M6.57155 14.6187C6.83137 14.763 6.96128 14.8352 7.06793 14.8227C7.16099 14.8118 7.24518 14.7623 7.29987 14.6862C7.36255 14.599 7.36255 14.4499 7.36255 14.1518V8.70166C7.36255 8.5881 7.36255 8.53132 7.34589 8.48062C7.33114 8.43576 7.30704 8.39455 7.27517 8.35971C7.23915 8.32033 7.18966 8.29249 7.09069 8.23682L2.16004 5.4633C1.89902 5.31648 1.76851 5.24306 1.66154 5.25513C1.56823 5.26565 1.48367 5.31506 1.42869 5.39118C1.36566 5.47844 1.36553 5.62789 1.36528 5.92678C1.36424 7.17088 1.36255 9.39704 1.36255 10.7058L1.36243 10.7538C1.36179 10.9298 1.36099 11.1509 1.42986 11.3594C1.48941 11.5397 1.58676 11.7051 1.71539 11.8447C1.86417 12.0061 2.0579 12.1128 2.21199 12.1977L2.2541 12.221C3.44156 12.8807 5.46065 14.0019 6.57155 14.6187Z" fill="#155EEF"/>
</svg>
{
"icon": {
"type": "element",
"isRootNode": true,
"name": "svg",
"attributes": {
"width": "16",
"height": "16",
"viewBox": "0 0 16 16",
"fill": "none",
"xmlns": "http://www.w3.org/2000/svg"
},
"children": [
{
"type": "element",
"name": "path",
"attributes": {
"d": "M13.6666 4.85185L7.99998 8M7.99998 8L2.33331 4.85185M7.99998 8L8 14.3333M14 10.7057V5.29431C14 5.06588 14 4.95167 13.9663 4.8498C13.9366 4.75969 13.8879 4.67696 13.8236 4.60717C13.7509 4.52828 13.651 4.47281 13.4514 4.36188L8.51802 1.62114C8.32895 1.5161 8.23442 1.46358 8.1343 1.44299C8.0457 1.42477 7.95431 1.42477 7.8657 1.44299C7.76559 1.46358 7.67105 1.5161 7.48198 1.62114L2.54865 4.36188C2.34896 4.47281 2.24912 4.52828 2.17642 4.60717C2.11211 4.67697 2.06343 4.75969 2.03366 4.84981C2 4.95167 2 5.06588 2 5.29431V10.7057C2 10.9341 2 11.0484 2.03366 11.1502C2.06343 11.2403 2.11211 11.3231 2.17642 11.3929C2.24912 11.4718 2.34897 11.5272 2.54865 11.6382L7.48198 14.3789C7.67105 14.4839 7.76559 14.5365 7.8657 14.557C7.95431 14.5753 8.0457 14.5753 8.1343 14.557C8.23442 14.5365 8.32895 14.4839 8.51802 14.3789L13.4514 11.6382C13.651 11.5272 13.7509 11.4718 13.8236 11.3929C13.8879 11.3231 13.9366 11.2403 13.9663 11.1502C14 11.0484 14 10.9341 14 10.7057Z",
"stroke": "currentColor",
"stroke-width": "1.25",
"stroke-linecap": "round",
"stroke-linejoin": "round"
},
"children": []
}
]
},
"name": "Container"
}
\ No newline at end of file
// GENERATE BY script
// DON NOT EDIT IT MANUALLY
import * as React from 'react'
import data from './Container.json'
import IconBase from '@/app/components/base/icons/IconBase'
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
props,
ref,
) => <IconBase {...props} ref={ref} data={data as IconData} />)
export default Icon
{
"icon": {
"type": "element",
"isRootNode": true,
"name": "svg",
"attributes": {
"width": "17",
"height": "16",
"viewBox": "0 0 17 16",
"fill": "none",
"xmlns": "http://www.w3.org/2000/svg"
},
"children": [
{
"type": "element",
"name": "path",
"attributes": {
"d": "M8.29782 0.790031C8.12061 0.753584 7.93783 0.753584 7.76062 0.790031C7.55577 0.832161 7.37268 0.934712 7.22712 1.01624L7.18744 1.03841C6.01215 1.69134 4.02394 2.79644 2.90301 3.41952C2.63085 3.5708 2.49477 3.64644 2.44929 3.74641C2.40965 3.83357 2.4094 3.93356 2.4486 4.02091C2.49357 4.12111 2.62938 4.19751 2.90101 4.3503L7.76772 7.08785C7.8631 7.1415 7.91079 7.16832 7.96135 7.17884C8.0061 7.18814 8.05229 7.18814 8.09703 7.17884C8.1476 7.16832 8.19529 7.1415 8.29067 7.08785L13.1574 4.35029C13.429 4.1975 13.5649 4.12111 13.6098 4.02091C13.649 3.93355 13.6488 3.83356 13.6091 3.74641C13.5637 3.64644 13.4276 3.57079 13.1554 3.41951C12.0345 2.79644 10.0463 1.69134 8.871 1.03841L8.83132 1.01624C8.68576 0.934713 8.50267 0.832161 8.29782 0.790031Z",
"fill": "currentColor"
},
"children": []
},
{
"type": "element",
"name": "path",
"attributes": {
"d": "M14.6932 5.92676C14.6929 5.62787 14.6928 5.47842 14.6297 5.39117C14.5748 5.31504 14.4902 5.26564 14.3969 5.25511C14.2899 5.24305 14.1594 5.31646 13.8984 5.46329L8.96774 8.23679C8.86877 8.29246 8.81928 8.3203 8.78326 8.35968C8.75139 8.39452 8.72729 8.43573 8.71254 8.48059C8.69588 8.53129 8.69588 8.58807 8.69588 8.70163V14.1518C8.69588 14.4499 8.69588 14.599 8.75856 14.6862C8.81326 14.7623 8.89744 14.8118 8.9905 14.8227C9.09716 14.8352 9.22706 14.763 9.48688 14.6188C10.5978 14.0019 12.6169 12.8807 13.8043 12.221L13.8464 12.1977C14.0005 12.1128 14.1943 12.0061 14.343 11.8447C14.4717 11.7051 14.569 11.5397 14.6286 11.3594C14.6975 11.1509 14.6966 10.9298 14.696 10.7538L14.6959 10.7058C14.6959 9.39704 14.6942 7.17087 14.6932 5.92676Z",
"fill": "currentColor"
},
"children": []
},
{
"type": "element",
"name": "path",
"attributes": {
"d": "M6.57155 14.6187C6.83137 14.763 6.96128 14.8352 7.06793 14.8227C7.16099 14.8118 7.24518 14.7623 7.29987 14.6862C7.36255 14.599 7.36255 14.4499 7.36255 14.1518V8.70166C7.36255 8.5881 7.36255 8.53132 7.34589 8.48062C7.33114 8.43576 7.30704 8.39455 7.27517 8.35971C7.23915 8.32033 7.18966 8.29249 7.09069 8.23682L2.16004 5.4633C1.89902 5.31648 1.76851 5.24306 1.66154 5.25513C1.56823 5.26565 1.48367 5.31506 1.42869 5.39118C1.36566 5.47844 1.36553 5.62789 1.36528 5.92678C1.36424 7.17088 1.36255 9.39704 1.36255 10.7058L1.36243 10.7538C1.36179 10.9298 1.36099 11.1509 1.42986 11.3594C1.48941 11.5397 1.58676 11.7051 1.71539 11.8447C1.86417 12.0061 2.0579 12.1128 2.21199 12.1977L2.2541 12.221C3.44156 12.8807 5.46065 14.0019 6.57155 14.6187Z",
"fill": "currentColor"
},
"children": []
}
]
},
"name": "Container"
}
\ No newline at end of file
// GENERATE BY script
// DON NOT EDIT IT MANUALLY
import * as React from 'react'
import data from './Container.json'
import IconBase from '@/app/components/base/icons/IconBase'
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
props,
ref,
) => <IconBase {...props} ref={ref} data={data as IconData} />)
export default Icon
import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment } from 'next/navigation'
import useSWRInfinite from 'swr/infinite'
import { flatten } from 'lodash-es'
import Nav from '../nav'
import { fetchAppList } from '@/service/apps'
import NewAppDialog from '@/app/(commonLayout)/apps/NewAppDialog'
import { Container } from '@/app/components/base/icons/src/vender/line/development'
import type { AppListResponse } from '@/models/app'
const getKey = (pageIndex: number, previousPageData: AppListResponse) => {
if (!pageIndex || previousPageData.has_more)
return { url: 'apps', params: { page: pageIndex + 1, limit: 30 } }
return null
}
const AppNav = () => {
const { t } = useTranslation()
const [showNewAppDialog, setShowNewAppDialog] = useState(false)
const { data: appsData, isLoading, setSize } = useSWRInfinite(false ? getKey : () => null, fetchAppList, { revalidateFirstPage: false })
// const { datasets, currentDataset } = useDatasetsContext()
// const router = useRouter()
// const showEnvTag = langeniusVersionInfo.current_env === 'TESTING' || langeniusVersionInfo.current_env === 'DEVELOPMENT'
const selectedSegment = useSelectedLayoutSegment()
console.log(selectedSegment)
console.log(usePathname(), useSearchParams(), useRouter(), useParams())
// const isPluginsComingSoon = selectedSegment === 'plugins-coming-soon'
// const isExplore = selectedSegment === 'explore'
// const [starCount, setStarCount] = useState(0)
const appItems = flatten(appsData?.map(appData => appData.data))
const handleLoadmore = useCallback(() => {
if (isLoading)
return
setSize(size => size + 1)
}, [setSize, isLoading])
return (
<>
<Nav
icon={<Container />}
text={t('common.menus.apps')}
activeSegment={['apps', 'app']}
link='/apps'
curNav={appItems.find(appItem => appItem.id === '')}
navs={appItems.map(item => ({
id: item.id,
name: item.name,
link: `/app/${item.id}/overview`,
icon: item.icon,
icon_background: item.icon_background,
}))}
createText={t('common.menus.newApp')}
onCreate={() => setShowNewAppDialog(true)}
onLoadmore={handleLoadmore}
/>
<NewAppDialog show={showNewAppDialog} onClose={() => setShowNewAppDialog(false)} />
</>
)
}
export default AppNav
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment