Skip to content

Commit 074305c

Browse files
committed
feat: implement getFeed API and update Feed component to use it
1 parent 87244eb commit 074305c

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/features/cards/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './api/getAIArticles'
1+
export * from '../feed/api/getFeed'
22
export * from './api/getRssFeed'
33
export * from './components/aiCard'
44
export * from './components/conferencesCard'
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { useInfiniteQuery } from '@tanstack/react-query'
22
import { axios } from 'src/lib/axios'
33
import { InfiniteQueryConfig } from 'src/lib/react-query'
4-
import { FeedItem } from 'src/types'
4+
import { FeedItemData } from 'src/types'
55

66
type Response = {
7-
data: FeedItem[]
7+
data: FeedItemData[]
88
metadata: {
99
next: string | null
1010
hasNextPage: boolean
1111
}
1212
}
13-
const getAIArticles = async ({
13+
const getFeed = async ({
1414
tags,
1515
next,
1616
}: {
1717
tags: string[]
1818
next?: string | null
1919
}): Promise<Response> => {
20-
return axios.get('/TO_ADD', {
20+
return axios.get('', {
2121
auth: {
22-
username: 'hidden',
23-
password: 'hidden',
22+
username: '',
23+
password: '',
2424
},
2525
params: {
2626
tags: [...tags].sort().join(','),
@@ -30,18 +30,18 @@ const getAIArticles = async ({
3030
})
3131
}
3232

33-
type QueryFnType = typeof getAIArticles
33+
type QueryFnType = typeof getFeed
3434

3535
type UseGetArticlesOptions = {
3636
tags: string[]
3737
config?: InfiniteQueryConfig<QueryFnType>
3838
}
3939

40-
export const useGetAIArticles = ({ tags, config }: UseGetArticlesOptions) => {
40+
export const useGetFeed = ({ tags, config }: UseGetArticlesOptions) => {
4141
return useInfiniteQuery<Response>({
4242
...config,
4343
queryKey: ['feed', 'v2', tags.join(',')],
44-
queryFn: ({ pageParam }) => getAIArticles({ tags, next: pageParam }),
44+
queryFn: ({ pageParam }) => getFeed({ tags, next: pageParam }),
4545
getNextPageParam: (lastPage) => {
4646
return lastPage.metadata.hasNextPage ? JSON.stringify(lastPage.metadata.next) : undefined
4747
},

src/features/feed/components/Feed.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import useInfiniteScroll from 'react-infinite-scroll-hook'
22
import { PropagateLoader } from 'react-spinners'
3-
import { useGetAIArticles } from 'src/features/cards'
3+
import { useGetFeed } from 'src/features/cards'
44
import { useUserPreferences } from 'src/stores/preferences'
55
import './feed.css'
6-
import { FeedItem } from './FeedItem'
76
import { AdvFeedItem } from './feedItems/AdvFeedItem'
7+
import { FeedItem } from './feedItems/FeedItem'
88

99
export const Feed = () => {
1010
const { userSelectedTags } = useUserPreferences()
@@ -17,7 +17,7 @@ export const Feed = () => {
1717
error,
1818
isFetchingNextPage,
1919
fetchNextPage,
20-
} = useGetAIArticles({
20+
} = useGetFeed({
2121
tags: userSelectedTags.map((tag) => tag.label.toLocaleLowerCase()),
2222
})
2323

src/features/feed/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
export * from './api/getFeed'
12
export * from './components/Feed'
3+
export * from './components/feedItems/FeedItem'

0 commit comments

Comments
 (0)