File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed
components/search/SearchResults Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ import { CommandItem } from "@/components/ui/command";
44import { useSearchStore } from "@/store/useSearchStore" ;
55import { SearchResult } from "@/types/search" ;
66
7- export default function SearchResultItem ( { title , blogName , path } : SearchResult ) {
7+ export default function SearchResultItem ( { id , title , blogName } : SearchResult ) {
88 const { searchParam } = useSearchStore ( ) ;
99 return (
1010 < CommandItem className = "flex flex-col items-start" >
11- < a href = { path } className = "hover:underline" >
11+ < a href = { ` ${ id } ` } className = "hover:underline" >
1212 < p className = " text-sm text-500" >
1313 < SearchHighlight text = { title } highlight = { searchParam } />
1414 </ p >
Original file line number Diff line number Diff line change @@ -23,9 +23,7 @@ export const usePostCardActions = (post: Post) => {
2323 const incrementView = ( { post, isWindowOpened } : PostWithState ) : PostWithState => {
2424 if ( isWindowOpened ) {
2525 mutate ( undefined , {
26- onSuccess : ( ) => {
27- console . log ( "조회수 증가 성공" ) ;
28- } ,
26+ onSuccess : ( ) => { } ,
2927 onError : ( error ) => {
3028 console . error ( "조회수 증가 실패" , error ) ;
3129 } ,
@@ -41,3 +39,17 @@ export const usePostCardActions = (post: Post) => {
4139
4240 return { openPost, incrementView } ;
4341} ;
42+ export function useIncrementViewByPostId ( id : number ) {
43+ const { mutate } = usePostViewIncrement ( id ) ;
44+
45+ const increment = ( ) => {
46+ mutate ( undefined , {
47+ onSuccess : ( ) => { } ,
48+ onError : ( error ) => {
49+ console . error ( "조회수 증가 실패" , error ) ;
50+ } ,
51+ } ) ;
52+ } ;
53+
54+ return increment ;
55+ }
Original file line number Diff line number Diff line change 1- import { useRef } from "react" ;
1+ import { useEffect , useRef } from "react" ;
22import { useParams } from "react-router-dom" ;
33
44import { PostContent } from "@/components/common/Card/detail/PostContent" ;
@@ -8,16 +8,25 @@ import Header from "@/components/layout/Header";
88import Loading from "@/pages/Loading" ;
99import NotFound from "@/pages/NotFound" ;
1010
11+ import { useIncrementViewByPostId } from "@/hooks/common/usePostCardActions" ;
1112import { usePostDetail } from "@/hooks/queries/usePostDetail" ;
1213
1314export default function PostDetailPage ( ) {
1415 const { id } = useParams ( ) ;
15- if ( id && ! / ^ \d + $ / . test ( id ) ) {
16+
17+ const numericId = Number ( id ) ;
18+ const increment = useIncrementViewByPostId ( numericId ) ;
19+ const { data, isLoading, error } = usePostDetail ( numericId ) ;
20+ const modalRef = useRef < HTMLDivElement > ( null ) ;
21+
22+ useEffect ( ( ) => {
23+ increment ( ) ;
24+ } , [ id ] ) ;
25+
26+ if ( ! id || ! / ^ \d + $ / . test ( id ) ) {
1627 return < NotFound /> ;
1728 }
1829
19- const { data, isLoading, error } = usePostDetail ( Number ( id ) ) ;
20- const modalRef = useRef < HTMLDivElement > ( null ) ;
2130 if ( isLoading ) {
2231 return < Loading /> ;
2332 }
You can’t perform that action at this time.
0 commit comments