-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from Prography-9th-3team/feat/feed
feat: feed 구현
- Loading branch information
Showing
8 changed files
with
136 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import useAuthStore from '@/stores/authStore'; | ||
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'; | ||
import { fetchData } from '.'; | ||
import { default as apis } from './api'; | ||
import { IBookmarkListResponseDataType } from './bookmark'; | ||
|
||
export const useRecommendBookmarkList = () => { | ||
const url = apis.recommend.recommend_bookmarks; | ||
const authStore = useAuthStore(); | ||
|
||
return useInfiniteQuery<any, unknown, IBookmarkListResponseDataType, any>({ | ||
queryKey: [apis.bookmark.bookmark_list], | ||
queryFn: async ({ pageParam }) => { | ||
const res = await fetchData.get(url, { | ||
params: { pageNumber: pageParam, size: 8 }, | ||
}); | ||
|
||
return res.data; | ||
}, | ||
initialPageParam: 0, | ||
getNextPageParam: (page: any) => { | ||
const { lastPage, pageNumber } = page.result.pageInfo; | ||
|
||
return !lastPage ? pageNumber + 1 : null; | ||
}, | ||
select: (res: InfiniteData<{ result: IBookmarkListResponseDataType }>) => { | ||
const content = res.pages.reduce((prev: any, cur: any) => { | ||
return [...prev, ...cur.result.content]; | ||
}, []); | ||
|
||
return { | ||
content, | ||
pageInfo: res.pages[0].result.pageInfo, | ||
}; | ||
}, | ||
staleTime: 1000 * 60 * 10, | ||
gcTime: 1000 * 60 * 10, | ||
enabled: authStore.isLogin(), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { useRecommendBookmarkList } from '@/apis/recommend'; | ||
import { cn } from '@/lib/utils'; | ||
import { usePathname } from 'next/navigation'; | ||
import BookmarkCard from '../BookmarkCard'; | ||
|
||
const Feed = () => { | ||
const pathName = usePathname(); | ||
|
||
const pathList = ['/login', '/onboarding', '/oauth2/redirect']; | ||
|
||
const { data: bookmarkData } = useRecommendBookmarkList(); | ||
|
||
const handleOpenBlank = ({ url }: { url: string }) => { | ||
window.open(url, '_blank'); | ||
}; | ||
|
||
return ( | ||
<> | ||
{!pathList.includes(pathName) && ( | ||
<div | ||
className={cn( | ||
'overflow-scroll h-full w-[260px] right-0 flex px-12 pt-40 gap-[14px] flex-col bg-surface', | ||
'border-l border-[#E9E9EA] styled-scroll', | ||
)} | ||
> | ||
<h1 className='heading-lg-bd'>이런 사이트는 어때요?</h1> | ||
<div className='flex flex-col gap-24'> | ||
{bookmarkData?.content.map((item) => ( | ||
<BookmarkCard | ||
key={item.bookMarkId} | ||
{...item} | ||
imageUUID={item.userInsertRepresentImage?.uuid} | ||
onClick={() => handleOpenBlank({ url: item.url })} | ||
isRecommendCard={true} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Feed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const isValidUrl = (url: string) => { | ||
try { | ||
new URL(url); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |