Skip to content

Commit 9c1bcb8

Browse files
authored
Merge pull request #292 from medyo/develop
refactor: export Ad and StickyAd types for better accessibility in th…
2 parents 86db5f9 + 79ddcca commit 9c1bcb8

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/features/adv/api/getAd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useQuery } from '@tanstack/react-query'
22
import { axios } from 'src/lib/axios'
33
import { ExtractFnReturnType, QueryConfig } from 'src/lib/react-query'
4+
import { Ad } from '../types'
45

56
const getAd = async (keywords: string[]): Promise<Ad[]> => {
67
let params = { keywords: keywords.join(',') }

src/features/adv/components/StickyBanner.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import jsonPath from 'jsonpath'
22
import { useEffect, useMemo } from 'react'
33
import { useMediaQuery } from 'react-responsive'
44
import { useAdStore } from 'src/features/adv/stores/AdStore'
5+
import type { StickyAd } from 'src/features/adv/types'
56
import { useAuth } from 'src/features/auth'
67
import { trackAdvOpen, trackAdvView } from 'src/lib/analytics'
78
import { useUserPreferences } from 'src/stores/preferences'
@@ -15,7 +16,8 @@ export const StickyBanner = () => {
1516
const isMobile = useMediaQuery({ maxWidth: 767 })
1617
const { ads } = useAdStore()
1718

18-
const ad = ads.length > 0 ? ads.find((ad) => ad.type === 'sticky-ad') : null
19+
const ad =
20+
ads.length > 0 ? (ads.find((ad) => ad.type === 'sticky-ad') as StickyAd | undefined) : null
1921

2022
const onAdClick = () => {
2123
if (ad?.id) {

src/features/adv/stores/AdStore.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { create } from 'zustand'
2+
import { Ad } from '../types'
23

34
type AdStore = {
45
ads: Ad[]

src/features/adv/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type LargeImageAd = CommonAdFields & {
2929
imageUrl: string
3030
}
3131

32-
type StickyAd = CommonAdFields & {
32+
export type StickyAd = CommonAdFields & {
3333
type: 'sticky-ad'
3434
title: string
3535
imageUrl: string
@@ -39,4 +39,4 @@ type StickyAd = CommonAdFields & {
3939
dismissible?: boolean
4040
}
4141

42-
type Ad = SmallImageAd | LargeImageAd | StickyAd
42+
export type Ad = SmallImageAd | LargeImageAd | StickyAd

0 commit comments

Comments
 (0)