Skip to content

Commit 7401a85

Browse files
committed
migrate appContentLayout to ts
1 parent 89b8b98 commit 7401a85

6 files changed

Lines changed: 68 additions & 51 deletions

File tree

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Footer, Header } from 'src/components/Layout'
44
import { BookmarksSidebar } from 'src/features/bookmarks'
55
import { MarketingBanner } from 'src/components/Elements'
66
import ScrollCardsNavigator from './components/ScrollCardsNavigator'
7-
import AppContentLayout from './components/AppContentLayout'
7+
import { AppContentLayout } from './components/Layout'
88
import 'react-contexify/dist/ReactContexify.css'
99
import { setupAnalytics, trackPageView, setupIdentification } from 'src/lib/analytics'
1010
import { useRemoteConfigStore } from 'src/features/remoteConfig'

src/components/AppContentLayout.js

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useState } from 'react'
2+
import { BottomNavigation } from '../Elements'
3+
import { isDesktop } from 'react-device-detect'
4+
import { useUserPreferences } from 'src/stores/preferences'
5+
import { MobileCards } from './MobileCards'
6+
import { DesktopCards } from './DesktopCards'
7+
8+
export const AppContentLayout = ({
9+
setShowSettings,
10+
}: {
11+
setShowSettings: (value: boolean | ((prevVar: boolean) => boolean)) => void
12+
}) => {
13+
const { cards } = useUserPreferences()
14+
const [selectedCard, setSelectedCard] = useState(cards[0])
15+
16+
return (
17+
<>
18+
<main className="AppContent scrollable">
19+
{isDesktop ? <DesktopCards cards={cards} /> : <MobileCards selectedCard={selectedCard} />}
20+
</main>
21+
22+
<BottomNavigation
23+
selectedCard={selectedCard}
24+
setSelectedCard={setSelectedCard}
25+
setShowSettings={setShowSettings}
26+
/>
27+
</>
28+
)
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { SUPPORTED_CARDS } from 'src/config'
3+
import { SelectedCard } from 'src/types'
4+
5+
export const DesktopCards = ({ cards }: { cards: SelectedCard[] }) => {
6+
return (
7+
<>
8+
{cards.map((card, index) => {
9+
const constantCard = SUPPORTED_CARDS.find((c) => c.value === card.name)
10+
if (!constantCard) {
11+
return null
12+
}
13+
14+
return React.createElement(constantCard.component, {
15+
key: card.name,
16+
meta: constantCard,
17+
withAds: index === 0,
18+
})
19+
})}
20+
</>
21+
)
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
import { SUPPORTED_CARDS } from 'src/config'
3+
import { SelectedCard } from 'src/types'
4+
5+
export const MobileCards = ({ selectedCard }: { selectedCard: SelectedCard }) => {
6+
const currentCard = SUPPORTED_CARDS.find((c) => c.value === selectedCard.name)
7+
return currentCard
8+
? React.createElement(currentCard.component, {
9+
key: currentCard.value,
10+
meta: currentCard,
11+
withAds: true,
12+
})
13+
: null
14+
}

src/components/Layout/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./Header"
2-
export * from "./Footer"
2+
export * from "./Footer"
3+
export * from "./AppContentLayout"

0 commit comments

Comments
 (0)