Skip to content

Commit

Permalink
Merge pull request #187 from medyo/develop
Browse files Browse the repository at this point in the history
New Version #minor
  • Loading branch information
medyo authored Apr 4, 2024
2 parents 7a480d0 + 16e55a9 commit d1ee3a0
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 137 deletions.
2 changes: 1 addition & 1 deletion script/build-chrome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ yarn build:ext

# Zip the distribution folder
echo 'Zip the extension'
cd dist/ && zip -r ../chrome_extension.zip * -x "*.DS_Store" "web_manifest.json" "screenshots/*" "images/*" "favicon.ico" "robots.txt" "base.manifest.json" "chrome.manifest.json" "firefox.manifest.json" && cd ..
cd dist/ && zip -r ../chrome_extension.zip * -x "*.DS_Store" "web_manifest.json" "screenshots/*" "images/*" "robots.txt" "base.manifest.json" "chrome.manifest.json" "firefox.manifest.json" && cd ..
2 changes: 1 addition & 1 deletion script/build-firefox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ yarn build:ext

# Zip the distribution folder
echo 'Zip the extension'
cd dist/ && zip -r ../firefox_extension.zip * -x "*.DS_Store" "web_manifest.json" "screenshots/*" "images/*" "favicon.ico" "robots.txt" "base.manifest.json" "chrome.manifest.json" "firefox.manifest.json" && cd ..
cd dist/ && zip -r ../firefox_extension.zip * -x "*.DS_Store" "web_manifest.json" "screenshots/*" "images/*" "robots.txt" "base.manifest.json" "chrome.manifest.json" "firefox.manifest.json" && cd ..

#
echo 'Zip the source code'
Expand Down
4 changes: 4 additions & 0 deletions src/assets/kagi_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
6 changes: 6 additions & 0 deletions src/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ReactComponent as PhindLogo } from 'src/assets/phind_logo.svg'
import { ReactComponent as StartPageLogo } from 'src/assets/startpage_logo.svg'
import { ReactComponent as YahooLogo } from 'src/assets/yahoo_logo.svg'
import { ReactComponent as YandexLogo } from 'src/assets/yandex_logo.svg'
import { ReactComponent as KagiLogo} from 'src/assets/kagi_logo.svg'

// Keys
export const ANALYTICS_ENDPOINT = import.meta.env.VITE_AMPLITUDE_URL as string
Expand Down Expand Up @@ -70,6 +71,11 @@ export const SUPPORTED_SEARCH_ENGINES = [
logo: PhindLogo,
className: 'themeAdaptiveFillColor',
},
{
label: 'Kagi',
url: 'https://kagi.com/search?q=',
logo: KagiLogo,
},
]

export const LS_PREFERENCES_KEY = 'hackerTabPrefs'
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
18 changes: 5 additions & 13 deletions src/features/cards/components/aiCard/ArticleItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BiCommentDetail } from 'react-icons/bi'
import { GoDotFill } from 'react-icons/go'
import { MdAccessTime } from 'react-icons/md'
import { CardItemWithActions, CardLink, ClickableItem } from 'src/components/Elements'
import { CardItemWithActions, CardLink } from 'src/components/Elements'
import { Attributes } from 'src/lib/analytics'
import { useUserPreferences } from 'src/stores/preferences'
import { Article, BaseItemPropsType } from 'src/types'
Expand Down Expand Up @@ -51,18 +51,10 @@ const ArticleItem = (props: BaseItemPropsType<Article>) => {
<span className="rowItem" title={new Date(item.published_at).toUTCString()}>
<MdAccessTime className="rowItemIcon" /> {format(new Date(item.published_at))}
</span>
<ClickableItem
link={`https://news.ycombinator.com/item?id=${item.id}`}
className="rowItem rowItemClickable"
analyticsAttributes={{
[Attributes.POINTS]: item.reactions,
[Attributes.TRIGERED_FROM]: 'card',
[Attributes.TITLE]: `${item.title} comments`,
[Attributes.LINK]: `https://news.ycombinator.com/item?id=${item.id}`,
[Attributes.SOURCE]: analyticsTag,
}}>
<BiCommentDetail className="rowItemIcon" /> {item.comments} comments
</ClickableItem>
<span className="rowItem">
<BiCommentDetail className={'rowTitleIcon'} />
{item.comments} comments
</span>
</div>
)}
</>
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>
)
}
Loading

0 comments on commit d1ee3a0

Please sign in to comment.