Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fixing lazy component (#136)
Browse files Browse the repository at this point in the history
* fixing lazy component

* adding lifecycle for tabbar and beagleChildren for lazy-component
  • Loading branch information
Tiagoperes authored Sep 3, 2020
1 parent 4b6123d commit 554ab03
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/beagle-react/src/components/BeagleLazy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import React, { FC, useEffect } from 'react'
import { LoadParams } from '@zup-it/beagle-web'
import { LoadParams, BeagleChildren } from '@zup-it/beagle-web'
import { BeagleComponent } from 'common/types'

export interface BeagleLazyInterface extends BeagleComponent {
Expand All @@ -28,7 +28,11 @@ const BeagleLazy: FC<BeagleLazyInterface> = ({ path, children, viewContentManage
path,
shouldShowLoading: false,
}
viewContentManager && viewContentManager.replaceComponent(params)
viewContentManager && viewContentManager.getView().fetch(
params,
viewContentManager.getElementId(),
'replaceComponent',
)
}, [])

return (
Expand All @@ -38,4 +42,6 @@ const BeagleLazy: FC<BeagleLazyInterface> = ({ path, children, viewContentManage
)
}

BeagleChildren({ property: 'initialState' })(BeagleLazy)

export default BeagleLazy
5 changes: 4 additions & 1 deletion packages/beagle-react/src/components/BeagleTabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

import React, { FC } from 'react'
import { BeforeViewSnapshot } from '@zup-it/beagle-web'
import { BeagleDefaultComponent } from '../types'
import withTheme from '../utils/withTheme'
import { ImagePath } from '../BeagleImage'
import { transformItems } from './lifecycles'
import {
StyledTabBar,
StyledBeagleTabItem,
Expand All @@ -39,7 +41,6 @@ export interface BeagleTabBarInterface extends BeagleDefaultComponent {
}

const BeagleTabBar: FC<BeagleTabBarInterface> = ({ onTabSelection, currentTab, items }) => {

const changeSelectedTab = (index: number) => {
if (!onTabSelection) return
onTabSelection(index)
Expand All @@ -64,4 +65,6 @@ const BeagleTabBar: FC<BeagleTabBarInterface> = ({ onTabSelection, currentTab, i
)
}

BeforeViewSnapshot(transformItems)(BeagleTabBar)

export default withTheme(BeagleTabBar)
24 changes: 24 additions & 0 deletions packages/beagle-react/src/components/BeagleTabBar/lifecycles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* 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 function transformItems(tabBar: Record<string, any>) {
if (!Array.isArray(tabBar.items)) return
tabBar.children = tabBar.items.map(item => ({
_beagleComponent_: 'beagle:tabitem',
id: `${tabBar.id}_${item.title}`,
...item,
}))
}

0 comments on commit 554ab03

Please sign in to comment.