Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/components/Elements/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
import React from 'react'
import React, { useEffect, useState } from 'react'
import { isDesktop } from 'react-device-detect'
import { SortableKnob } from 'react-easy-sort'
import { BsBoxArrowInUpRight } from 'react-icons/bs'
import { MdOutlineDragIndicator } from 'react-icons/md'
import { ref } from 'src/config'
import { AdvBanner } from 'src/features/adv'
import { useRemoteConfigStore } from 'src/features/remoteConfig'
import { useUserPreferences } from 'src/stores/preferences'
import { SupportedCardType } from 'src/types'

type CardProps = {
children: React.ReactNode
card: SupportedCardType
withAds?: boolean
titleComponent?: React.ReactNode
fullBlock?: boolean
}

export const Card = ({ card, titleComponent, children, fullBlock = false }: CardProps) => {
export const Card = ({
card,
titleComponent,
withAds = false,
children,
fullBlock = false,
}: CardProps) => {
const { openLinksNewTab } = useUserPreferences()
const { link, icon, label, badge } = card
const [canAdsLoad, setCanAdsLoad] = useState(true)
const { adsConfig } = useRemoteConfigStore()

useEffect(() => {
if (!adsConfig.enabled || !withAds) {
return
}

const handleClassChange = () => {
if (document.documentElement.classList.contains('dndState')) {
setCanAdsLoad(false)
} else {
setCanAdsLoad(true)
}
}

const observer = new MutationObserver(handleClassChange)
observer.observe(document.documentElement, { attributes: true })

return () => {
observer.disconnect()
}
}, [withAds, adsConfig.enabled])

const handleHeaderLinkClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault()
let url = `${link}?${ref}`
Expand All @@ -42,6 +75,8 @@ export const Card = ({ card, titleComponent, children, fullBlock = false }: Card
{badge && <span className="blockHeaderBadge">{badge}</span>}
</div>

{canAdsLoad && adsConfig.enabled && withAds && <AdvBanner />}

<div className="blockContent scrollable">{children}</div>
</div>
)
Expand Down
33 changes: 1 addition & 32 deletions src/components/List/ListComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { ReactNode, useEffect } from 'react'
import React, { ReactNode } from 'react'
import { Placeholder } from 'src/components/placeholders'
import { MAX_ITEMS_PER_CARD } from 'src/config'
import { AdvBanner } from 'src/features/adv'
import { useRemoteConfigStore } from 'src/features/remoteConfig'
import { BaseEntry } from 'src/types'

type PlaceholdersProps = {
Expand All @@ -23,7 +21,6 @@ export type ListComponentPropsType<T extends BaseEntry> = {
items: T[]
isLoading: boolean
renderItem: (item: T, index: number) => React.ReactNode
withAds: boolean
placeholder?: React.ReactNode
header?: React.ReactNode
refresh?: boolean
Expand All @@ -37,34 +34,10 @@ export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType
isLoading,
error,
renderItem,
withAds,
header,
placeholder = <Placeholder />,
limit = MAX_ITEMS_PER_CARD,
} = props
const { adsConfig } = useRemoteConfigStore()
const [canAdsLoad, setCanAdsLoad] = React.useState(true)

useEffect(() => {
if (!adsConfig.enabled || !withAds) {
return
}

const handleClassChange = () => {
if (document.documentElement.classList.contains('dndState')) {
setCanAdsLoad(false)
} else {
setCanAdsLoad(true)
}
}

const observer = new MutationObserver(handleClassChange)
observer.observe(document.documentElement, { attributes: true })

return () => {
observer.disconnect()
}
}, [withAds, adsConfig.enabled])

if (error) {
return <p className="errorMsg">{error?.message || error}</p>
Expand All @@ -81,10 +54,6 @@ export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType
content.unshift(header)
}

if (canAdsLoad && adsConfig.enabled && withAds && index === adsConfig.rowPosition) {
content.unshift(<AdvBanner key={'hello-word'} />)
}

return content
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/features/adv/components/AdvBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const AdvBanner = () => {
</a>
</span>
</div>
{ad.viewUrl && <img src={ad.viewUrl} key={ad.viewUrl} className="hidden" alt="" />}
{ad.viewUrl &&
ad.viewUrl
.split('||')
.map((viewUrl, i) => <img key={i} src={viewUrl} className="hidden" alt="" />)}
</div>
)
}
8 changes: 4 additions & 4 deletions src/features/adv/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type AdProvider = {
name: string,
title: string,
link?: string,
name: string
title: string
link?: string
}

type NextAdType = {
Expand All @@ -18,4 +18,4 @@ export type Ad = {
backgroundColor?: string
provider: AdProvider
nextAd?: NextAdType
}
}
3 changes: 1 addition & 2 deletions src/features/cards/components/aiCard/AICard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function AICard({ meta, withAds }: CardPropsType) {
)

return (
<Card card={meta}>
<Card card={meta} withAds={withAds}>
<ListComponent
items={articles}
error={error}
Expand Down Expand Up @@ -65,7 +65,6 @@ export function AICard({ meta, withAds }: CardPropsType) {
}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
/>
</Card>
)
Expand Down
16 changes: 5 additions & 11 deletions src/features/cards/components/conferencesCard/ConferencesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Card } from 'src/components/Elements'
import { ListComponent } from 'src/components/List'
import { useGetConferences } from '../../api/getConferences'
import { Conference, CardPropsType } from 'src/types'
import { useUserPreferences } from 'src/stores/preferences'
import { getCardTagsValue } from 'src/utils/DataEnhancement'
import { CardPropsType, Conference } from 'src/types'
import { filterUniqueEntries, getCardTagsValue } from 'src/utils/DataEnhancement'
import { useGetConferences } from '../../api/getConferences'
import ConferenceItem from './ConferenceItem'
import { filterUniqueEntries } from 'src/utils/DataEnhancement'

export function ConferencesCard({ meta, withAds }: CardPropsType) {
const { userSelectedTags } = useUserPreferences()
Expand Down Expand Up @@ -35,13 +34,8 @@ export function ConferencesCard({ meta, withAds }: CardPropsType) {
)

return (
<Card card={meta}>
<ListComponent
items={getData()}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
/>
<Card card={meta} withAds={withAds}>
<ListComponent items={getData()} isLoading={isLoading} renderItem={renderItem} />
</Card>
)
}
9 changes: 2 additions & 7 deletions src/features/cards/components/devtoCard/DevtoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ export function DevtoCard({ withAds, meta }: CardPropsType) {
}

return (
<Card card={meta} titleComponent={<HeaderTitle />}>
<Card card={meta} titleComponent={<HeaderTitle />} withAds={withAds}>
<FloatingFilter card={meta} filters={['language']} />
<ListComponent
items={getData()}
isLoading={getIsLoading()}
renderItem={renderItem}
withAds={withAds}
/>
<ListComponent items={getData()} isLoading={getIsLoading()} renderItem={renderItem} />
</Card>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,9 @@ export function FreecodecampCard({ meta, withAds }: CardPropsType) {
}

return (
<Card card={meta} titleComponent={<HeaderTitle />}>
<Card card={meta} titleComponent={<HeaderTitle />} withAds={withAds}>
<FloatingFilter card={meta} filters={['language']} />
<ListComponent
items={getData()}
isLoading={getIsLoading()}
renderItem={renderItem}
withAds={withAds}
/>
<ListComponent items={getData()} isLoading={getIsLoading()} renderItem={renderItem} />
</Card>
)
}
3 changes: 1 addition & 2 deletions src/features/cards/components/githubCard/GithubCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ export function GithubCard({ meta, withAds }: CardPropsType) {
}
}
return (
<Card fullBlock={true} card={meta} titleComponent={<HeaderTitle />}>
<Card fullBlock={true} card={meta} titleComponent={<HeaderTitle />} withAds={withAds}>
<FloatingFilter card={meta} filters={['datesRange', 'language']} />
<ListComponent
items={getData()}
error={getError()}
isLoading={getIsLoading()}
renderItem={renderItem}
withAds={withAds}
/>
</Card>
)
Expand Down
12 changes: 3 additions & 9 deletions src/features/cards/components/hackernewsCard/HackernewsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from 'src/components/Elements'
import { ListComponent } from 'src/components/List'
import { useGetHackertNewsArticles } from '../../api/getHackerNewsArticles'
import { Article, CardPropsType } from 'src/types'
import { useGetHackertNewsArticles } from '../../api/getHackerNewsArticles'
import ArticleItem from './ArticleItem'

export function HackernewsCard({ meta, withAds }: CardPropsType) {
Expand All @@ -12,14 +12,8 @@ export function HackernewsCard({ meta, withAds }: CardPropsType) {
)

return (
<Card card={meta}>
<ListComponent
items={articles}
error={error}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
/>
<Card card={meta} withAds={withAds}>
<ListComponent items={articles} error={error} isLoading={isLoading} renderItem={renderItem} />
</Card>
)
}
9 changes: 2 additions & 7 deletions src/features/cards/components/hashnodeCard/HashnodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,9 @@ export function HashnodeCard({ withAds, meta }: CardPropsType) {
}

return (
<Card card={meta} titleComponent={<HeaderTitle />}>
<Card card={meta} titleComponent={<HeaderTitle />} withAds={withAds}>
<FloatingFilter card={meta} filters={['language']} />
<ListComponent
items={getData()}
isLoading={getIsLoading()}
renderItem={renderItem}
withAds={withAds}
/>
<ListComponent items={getData()} isLoading={getIsLoading()} renderItem={renderItem} />
</Card>
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from 'src/components/Elements'
import { ListComponent } from 'src/components/List'
import { useGetIndieHackersArticles } from '../../api/getIndieHackersArticles'
import { Article, CardPropsType } from 'src/types'
import { useGetIndieHackersArticles } from '../../api/getIndieHackersArticles'
import { ArticleItem } from './ArticleItem'

export function IndiehackersCard({ meta, withAds }: CardPropsType) {
Expand All @@ -12,14 +12,8 @@ export function IndiehackersCard({ meta, withAds }: CardPropsType) {
)

return (
<Card card={meta}>
<ListComponent
items={articles}
error={error}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
/>
<Card card={meta} withAds={withAds}>
<ListComponent items={articles} error={error} isLoading={isLoading} renderItem={renderItem} />
</Card>
)
}
12 changes: 3 additions & 9 deletions src/features/cards/components/lobstersCard/LobstersCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from 'src/components/Elements'
import { ListComponent } from 'src/components/List'
import { useGetLobstersArticles } from '../../api/getLobstersArticles'
import { Article, CardPropsType } from 'src/types'
import { useGetLobstersArticles } from '../../api/getLobstersArticles'
import ArticleItem from './ArticleItem'

export function LobstersCard({ withAds, meta }: CardPropsType) {
Expand All @@ -12,14 +12,8 @@ export function LobstersCard({ withAds, meta }: CardPropsType) {
)

return (
<Card card={meta}>
<ListComponent
items={articles}
error={error}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
/>
<Card card={meta} withAds={withAds}>
<ListComponent items={articles} error={error} isLoading={isLoading} renderItem={renderItem} />
</Card>
)
}
9 changes: 2 additions & 7 deletions src/features/cards/components/mediumCard/MediumCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ export function MediumCard({ meta, withAds }: CardPropsType) {
}

return (
<Card card={meta} titleComponent={<HeaderTitle />}>
<Card card={meta} titleComponent={<HeaderTitle />} withAds={withAds}>
<FloatingFilter card={meta} filters={['language']} />
<ListComponent
items={getData()}
isLoading={getIsLoading()}
renderItem={renderItem}
withAds={withAds}
/>
<ListComponent items={getData()} isLoading={getIsLoading()} renderItem={renderItem} />
</Card>
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Card } from 'src/components/Elements'
import { ListComponent } from 'src/components/List'
import { useGeProductHuntProducts } from '../../api/getProductHuntProducts'
import { Article, CardPropsType } from 'src/types'
import { ProductHuntPlaceholder } from 'src/components/placeholders'
import { Article, CardPropsType } from 'src/types'
import { useGeProductHuntProducts } from '../../api/getProductHuntProducts'
import ArticleItem from './ArticleItem'

export function ProductHuntCard({ meta, withAds }: CardPropsType) {
Expand All @@ -22,13 +22,12 @@ export function ProductHuntCard({ meta, withAds }: CardPropsType) {
)

return (
<Card card={meta}>
<Card card={meta} withAds={withAds}>
<ListComponent
items={products}
error={error}
isLoading={isLoading}
renderItem={renderItem}
withAds={withAds}
placeholder={<ProductHuntPlaceholder />}
/>
</Card>
Expand Down
Loading