Skip to content

Commit

Permalink
feat(plugins/mpa): active tab when click the project files tree
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW committed Nov 12, 2023
1 parent f304351 commit ec0f0c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/plugins/mpa/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const useTabs = () => {
const [tabs, setTabs] = useAtom(tabsAtom, { store: useStore() })
return {
tabs,
includeTab: useCallback((id: string) => {
return tabs.some(tab => tab.id === id)
}, [tabs]),
setActiveTab: useCallback((id: string) => {
setTabs(tabs => tabs.map(tab => ({ ...tab, active: tab.id === id })))
}, [setTabs]),
Expand Down
19 changes: 19 additions & 0 deletions core/src/plugins/mpa/drawerPanels/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { DrawerPanelProps } from '../../../components/drawerPanelCreator'
import { NotImplemented } from '../../../components/NotImplemented'
import { useMenu } from '../../../hooks/useMenu'
import { useVFiles } from '../../../virtual-files'
import { useTabs } from '../atoms'

const prefix = 'ppd-drawer-panel--project'

Expand Down Expand Up @@ -87,13 +88,31 @@ export default function Project({ template, setOnKeydown }: DrawerPanelProps) {
? prefix + '--dir-type__external'
: undefined
})), [vFiles])

const { includeTab, setActiveTab, addTab } = useTabs()
return <>
{viewModeSwitcherMenuPopper}
<List
ref={listRef}
selectable
items={filesForListItem}
defaultFoldedIds={['/node_modules']}
onClickItem={(e, item, type) => {
switch (type) {
case 'click':
if (includeTab(item.id)) {
setActiveTab(item.id)
} else {
addTab({
id: item.id,
title: item.label,
icon: item.icon,
active: true
})
}
break
}
}}
/>
</>
}
Expand Down

0 comments on commit ec0f0c6

Please sign in to comment.