|
1 | 1 | import { useQuery } from '@tanstack/react-query' |
| 2 | +import { axios } from 'src/lib/axios' |
2 | 3 | import { ExtractFnReturnType, QueryConfig } from 'src/lib/react-query' |
3 | 4 | import { Ad } from '../types' |
4 | | -import { axios } from 'src/lib/axios' |
5 | 5 |
|
6 | | -const getAd = async (keywords: string[]): Promise<Ad | null> => { |
7 | | - let url = new URL(window.location.href); |
8 | | - let ref = url.searchParams.get("ref"); |
9 | | - return axios.get('/engine/ads/', {params: { ref, keywords: keywords.join(",") }}) |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +const getAd = async ( |
| 10 | + keywords: string[], |
| 11 | + aditionalAdQueries: { [key: string]: string } | undefined |
| 12 | +): Promise<Ad | null> => { |
| 13 | + let params = { keywords: keywords.join(',') } |
| 14 | + if (aditionalAdQueries) { |
| 15 | + params = { ...params, ...aditionalAdQueries } |
| 16 | + } |
| 17 | + return axios.get('/engine/ads/', { params }) |
10 | 18 | } |
11 | 19 |
|
12 | 20 | type QueryFnType = typeof getAd |
13 | 21 |
|
14 | 22 | type UseGetAdOptions = { |
15 | | - keywords: string[]; |
| 23 | + keywords: string[] |
16 | 24 | config?: QueryConfig<QueryFnType> |
| 25 | + aditionalAdQueries: { [key: string]: string } | undefined |
17 | 26 | } |
18 | | -export const useGetAd = ({ keywords, config }: UseGetAdOptions) => { |
| 27 | +export const useGetAd = ({ keywords, config, aditionalAdQueries }: UseGetAdOptions) => { |
19 | 28 | return useQuery<ExtractFnReturnType<QueryFnType>>({ |
20 | 29 | ...config, |
21 | 30 | queryKey: ['ad'], |
22 | | - queryFn: () => getAd(keywords), |
| 31 | + queryFn: () => getAd(keywords, aditionalAdQueries), |
23 | 32 | }) |
24 | 33 | } |
0 commit comments