File tree Expand file tree Collapse file tree 14 files changed +258
-73
lines changed
app/[locale]/home/components Expand file tree Collapse file tree 14 files changed +258
-73
lines changed Original file line number Diff line number Diff line change 1+ import { IResponseReview } from "@/lib/types/travel" ;
12import React from "react" ;
23import ReviewCard from "@/components/ui/cards/ReviewCard" ;
34import WithTitleWrapper from "@/components/common/WithTitleWrapper" ;
45
5- const ReviewList = ( ) => {
6+ async function getReviews ( ) {
7+ const response = await fetch ( `${ process . env . API_HOST } /review` ) ;
8+
9+ const reviews : IResponseReview = await response . json ( ) ;
10+
11+ return reviews ;
12+ }
13+
14+ const ReviewList = async ( ) => {
15+ const reviews = await getReviews ( ) ;
16+
617 return (
718 < WithTitleWrapper title = "지금뜨는 리뷰" moreHref = "reviews" >
819 < div className = "flex flex-col gap-2" >
9- < ReviewCard />
10- < ReviewCard />
20+ { [ ...reviews . data ] . slice ( 0 , 2 ) . map ( review => (
21+ < ReviewCard key = { review . id } review = { review } />
22+ ) ) }
1123 </ div >
1224 </ WithTitleWrapper >
1325 ) ;
Original file line number Diff line number Diff line change 1+ import { IResponseTravelStory } from "@/lib/types/travel" ;
12import React from "react" ;
23import TravelStoryCard from "@/components/ui/cards/TravelStoryCard" ;
34import WithTitleWrapper from "@/components/common/WithTitleWrapper" ;
45
5- const TravelStoryList = ( ) => {
6+ async function getTravelStories ( ) {
7+ const response = await fetch ( `${ process . env . API_HOST } /story` ) ;
8+
9+ const stories : IResponseTravelStory = await response . json ( ) ;
10+
11+ return stories ;
12+ }
13+
14+ const TravelStoryList = async ( ) => {
15+ const stories = await getTravelStories ( ) ;
16+
617 return (
718 < WithTitleWrapper title = "지금뜨는 여행기" moreHref = "stories" >
819 < div className = "flex flex-col gap-2" >
9- < TravelStoryCard />
10- < TravelStoryCard />
20+ { [ ...stories . data ] . slice ( 0 , 2 ) . map ( story => (
21+ < TravelStoryCard key = { story . id } story = { story } />
22+ ) ) }
1123 </ div >
1224 </ WithTitleWrapper >
1325 ) ;
Original file line number Diff line number Diff line change 11"use client" ;
22
33import Card from "./context/CardProvider" ;
4+ import { IReview } from "@/lib/types/travel" ;
45import React from "react" ;
56
6- const ReviewCard = ( ) => {
7- const card = {
8- starRating : 4 ,
9- commentCount : 5 ,
10- imageSrc : "https://www.ghibli.jp/gallery/ponyo016.jpg" ,
11- title : "세번째 카드 종류" ,
12- description : "설명도 있음" ,
13- userName : "yunnnn" ,
14- userImageSrc : "https://www.ghibli.jp/gallery/ponyo016.jpg" ,
15- } ;
7+ interface Props {
8+ review : IReview ;
9+ }
10+
11+ const ReviewCard = ( { review } : Props ) => {
1612 return (
1713 < div className = "flex items-center gap-4 px-4 py-4 border rounded-md bg-white" >
18- < Card card = { card } >
14+ < Card card = { review } >
1915 < Card . CardImage />
2016 < div className = "flex flex-col gap-2 flex-1" >
2117 < Card . CardTitle />
Original file line number Diff line number Diff line change 11"use client" ;
22
33import Card from "./context/CardProvider" ;
4+ import { ITravelStory } from "@/lib/types/travel" ;
45import React from "react" ;
56
6- const TravelStoryCard = ( ) => {
7- const card = {
8- isLike : true ,
9- likeCount : 10 ,
10- commentCount : 5 ,
11- imageSrc : "https://www.ghibli.jp/gallery/ponyo016.jpg" ,
12- tagList : [ "#서울" , "#대전" ] ,
13- title : "첫번째 카드" ,
14- userName : "신윤철" ,
15- userImageSrc : "https://www.ghibli.jp/gallery/ponyo016.jpg" ,
16- } ;
7+ interface Props {
8+ story : ITravelStory ;
9+ }
1710
11+ const TravelStoryCard = ( { story } : Props ) => {
1812 return (
1913 < div className = "flex items-center gap-4 px-4 py-4 border rounded-md bg-white" >
20- < Card card = { card } >
14+ < Card card = { story } >
2115 < Card . CardImage />
2216 < div className = "flex flex-col gap-2 flex-1" >
2317 < Card . CardTags />
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ interface ICard {
1212 isLike ?: boolean ;
1313 likeCount ?: number ;
1414 commentCount : number ;
15- starRating ?: number ;
15+ score ?: number ;
1616 imageSrc ?: string ;
1717 tagList ?: string [ ] ;
1818 title : string ;
Original file line number Diff line number Diff line change 1- import React , { useState } from "react" ;
2-
31import { Button } from "../../Button" ;
2+ import React from "react" ;
43import StarIcon from "@/components/icons/StartIcon" ;
54import { cn } from "@/lib/utils/cn" ;
65import { useCardContext } from "./CardProvider" ;
@@ -9,8 +8,7 @@ const StarButton = React.forwardRef<
98 HTMLButtonElement ,
109 React . HTMLAttributes < HTMLButtonElement >
1110> ( ( { className, ...props } , ref ) => {
12- const { starRating } = useCardContext ( ) ;
13- const [ star , setStar ] = useState ( false ) ;
11+ const { score } = useCardContext ( ) ;
1412
1513 return (
1614 // [todo]: change click event to update like Api
@@ -19,15 +17,10 @@ const StarButton = React.forwardRef<
1917 size = "icon"
2018 variant = "ghost"
2119 className = { cn ( "flex items-center gap-1" , className ) }
22- onClick = { ( ) => {
23- setStar ( ! star ) ;
24- } }
2520 { ...props }
2621 >
2722 < StarIcon className = "w-4 h-4" />
28- < span className = "flex items-center text-[#b8b8b8] text-xs" >
29- { starRating }
30- </ span >
23+ < span className = "flex items-center text-[#b8b8b8] text-xs" > { score } </ span >
3124 </ Button >
3225 ) ;
3326} ) ;
Original file line number Diff line number Diff line change 1+ export interface IResponseTravelStory {
2+ pageInfo : {
3+ page : number ;
4+ hasNext : number ;
5+ hasPrevious : number ;
6+ totalElements : number ;
7+ totalPages : number ;
8+ } ;
9+ data : ITravelStory [ ] ;
10+ }
11+
12+ export interface ITravelStory {
13+ id : number ;
14+ isLike : boolean ;
15+ likeCount : number ;
16+ commentCount : number ;
17+ imageSrc : string ;
18+ title : string ;
19+ tagList : string [ ] ;
20+ userName : string ;
21+ userImageSrc : string ;
22+ }
23+
24+ export interface IResponseReview {
25+ pageInfo : {
26+ page : number ;
27+ hasNext : number ;
28+ hasPrevious : number ;
29+ totalElements : number ;
30+ totalPages : number ;
31+ } ;
32+ data : IReview [ ] ;
33+ }
34+
35+ export interface IReview {
36+ id : number ;
37+ score : number ;
38+ commentCount : number ;
39+ imageSrc : string ;
40+ title : string ;
41+ description : string ;
42+ userName : string ;
43+ userImageSrc : string ;
44+ }
Original file line number Diff line number Diff line change 1- import { HttpResponse , http } from "msw" ;
1+ import { getPlaces } from "./handlers/place" ;
2+ import { getReviews } from "./handlers/review" ;
3+ import { getTravelStories } from "./handlers/travelStory" ;
24
3- import { IResponsePlace } from "@/lib/types/place" ;
4-
5- export const handlers = [
6- http . get < never , never , IResponsePlace > (
7- "http://jandp-travel.kro.kr/place" ,
8- ( ) => {
9- return HttpResponse . json ( {
10- pageInfo : {
11- page : 1 ,
12- hasNext : 1 ,
13- hasPrevious : 0 ,
14- totalElements : 2 ,
15- totalPages : 1 ,
16- } ,
17- data : [
18- {
19- id : 1 ,
20- placeId : "hdaasdasdasdasas" ,
21- name : "서울" ,
22- subName : "서울" ,
23- } ,
24- {
25- id : 2 ,
26- placeId : "asdasfasfasfas" ,
27- name : "대전" ,
28- subName : "대전" ,
29- } ,
30- ] ,
31- } ) ;
32- }
33- ) ,
34- ] ;
5+ export const handlers = [ getPlaces , getTravelStories , getReviews ] ;
Original file line number Diff line number Diff line change 1+ import { HttpResponse , http } from "msw" ;
2+
3+ import { IResponsePlace } from "@/lib/types/place" ;
4+ import { placeResponse } from "../response/place" ;
5+
6+ export const getPlaces = http . get < never , never , IResponsePlace > (
7+ `${ process . env . API_HOST } /place` ,
8+ ( ) => {
9+ return HttpResponse . json ( placeResponse ) ;
10+ }
11+ ) ;
Original file line number Diff line number Diff line change 1+ import { HttpResponse , http } from "msw" ;
2+
3+ import { reviewResponse } from "../response/review" ;
4+
5+ export const getReviews = http . get ( `${ process . env . API_HOST } /review` , ( ) => {
6+ return HttpResponse . json ( reviewResponse ) ;
7+ } ) ;
You can’t perform that action at this time.
0 commit comments