File tree Expand file tree Collapse file tree
_components/home-caption-section Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import ShakeYMotion from "@/shared/ui/motion/shakeY-motion" ;
22import * as styles from "./home-caption-section.css" ;
33
4- const HomeCaptionSection = ( ) => {
4+ interface HomeCaptionSectionProps {
5+ totalUserCount : number ;
6+ }
7+
8+ const HomeCaptionSection = ( { totalUserCount } : HomeCaptionSectionProps ) => {
59 return (
610 < ShakeYMotion >
7- < p className = { styles . caption } > 7명이 이야기를 주고 받는 중</ p >
11+ < p className = { styles . caption } >
12+ { totalUserCount } 명이 이야기를 주고 받는 중
13+ </ p >
814 </ ShakeYMotion >
915 ) ;
1016} ;
Original file line number Diff line number Diff line change @@ -7,10 +7,18 @@ import HomeCaptionSection from "./_components/home-caption-section";
77import HomeTitleSection from "./_components/home-title-section" ;
88
99import FloatingStarsContainer from "@/shared/ui/floating-stars-container" ;
10+ import { useQuery } from "@tanstack/react-query" ;
11+ import { userQueryOptions } from "@/shared/api/queries/user" ;
1012
1113import * as styles from "./home.css" ;
1214
1315const Home = ( ) => {
16+ const { data } = useQuery (
17+ userQueryOptions . totalUserCount ( )
18+ ) ;
19+
20+ const totalUserCount = data ?. result . userTotalCount ;
21+
1422 return (
1523 < div >
1624 < main >
@@ -26,7 +34,7 @@ const Home = () => {
2634 />
2735 < HomeTitleSection />
2836 < HomeButtonSection />
29- < HomeCaptionSection />
37+ < HomeCaptionSection totalUserCount = { totalUserCount || 0 } />
3038 < div className = { styles . physicsContainer } >
3139 < Physics
3240 gravX = { 0 }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export const useCreateCapsule = () => {
1717 } ) ;
1818 } ,
1919 onSuccess : ( ) => {
20- queryClient . invalidateQueries ( { queryKey : capsuleQueryKeys . all ( ) } ) ;
20+ queryClient . invalidateQueries ( { queryKey : [ "capsule" , "my" ] } ) ;
2121 } ,
2222 } ) ;
2323} ;
@@ -31,9 +31,15 @@ export const useLikeToggle = () => {
3131 } else {
3232 await apiClient . put ( ENDPOINTS . LIKE_TOGGLE ( id ) ) ;
3333 }
34+ return id ;
3435 } ,
35- onSuccess : ( ) => {
36- queryClient . invalidateQueries ( { queryKey : capsuleQueryKeys . all ( ) } ) ;
36+ onSuccess : async ( id : string ) => {
37+ await Promise . all ( [
38+ queryClient . invalidateQueries ( {
39+ queryKey : capsuleQueryKeys . detail ( id ) ,
40+ } ) ,
41+ queryClient . invalidateQueries ( { queryKey : [ "capsule" , "my" ] } ) ,
42+ ] ) ;
3743 } ,
3844 } ) ;
3945} ;
@@ -44,8 +50,13 @@ export const useLeaveCapsule = () => {
4450 mutationFn : ( id : string ) => {
4551 return apiClient . delete ( ENDPOINTS . LEAVE_CAPSULE ( id ) ) ;
4652 } ,
47- onSuccess : ( ) => {
48- queryClient . invalidateQueries ( { queryKey : capsuleQueryKeys . all ( ) } ) ;
53+ onSuccess : async ( _data , id : string ) => {
54+ await Promise . all ( [
55+ queryClient . invalidateQueries ( { queryKey : [ "capsule" , "my" ] } ) ,
56+ queryClient . invalidateQueries ( {
57+ queryKey : capsuleQueryKeys . detail ( id ) ,
58+ } ) ,
59+ ] ) ;
4960 } ,
5061 } ) ;
5162} ;
Original file line number Diff line number Diff line change @@ -96,10 +96,10 @@ const getCapsuleLists = (
9696const getSearchCapsuleLists = (
9797 keyword : string ,
9898 page ?: number ,
99- size ?: number ,
99+ size ?: number
100100) => {
101101 return apiClient . get < CapsuleListsRes > (
102- ENDPOINTS . CAPSULE_SEARCH_LISTS ( keyword , page , size ) ,
102+ ENDPOINTS . CAPSULE_SEARCH_LISTS ( keyword , page , size )
103103 ) ;
104104} ;
105105
Original file line number Diff line number Diff line change 11import { apiClient } from "@/shared/api/api-client" ;
22import { ENDPOINTS } from "@/shared/constants/endpoints" ;
3- import type { UserInfo } from "@/shared/types/api/user" ;
3+ import type { UserInfo , TotalUserCountRes } from "@/shared/types/api/user" ;
44import { queryOptions } from "@tanstack/react-query" ;
5+ import { CACHE_TIME } from "@/shared/constants/api" ;
56
67const userQueryKeys = {
78 all : ( ) => [ "user" ] ,
89 userInfo : ( ) => [ ...userQueryKeys . all ( ) , "userInfo" ] ,
10+ totalUserCount : ( ) => [ ...userQueryKeys . all ( ) , "totalUserCount" ] ,
911} as const ;
1012
1113export const userQueryOptions = {
@@ -20,4 +22,17 @@ export const userQueryOptions = {
2022 } ,
2123 ...options ,
2224 } ) ,
25+
26+ totalUserCount : ( options ?: {
27+ enabled ?: boolean ;
28+ onError ?: ( error : Error ) => void ;
29+ } ) =>
30+ queryOptions ( {
31+ queryKey : userQueryKeys . totalUserCount ( ) ,
32+ queryFn : ( ) => {
33+ return apiClient . get < TotalUserCountRes > ( ENDPOINTS . TOTAL_USER_COUNT ) ;
34+ } ,
35+ ...options ,
36+ staleTime : CACHE_TIME . LONG ,
37+ } ) ,
2338} ;
Original file line number Diff line number Diff line change @@ -7,3 +7,9 @@ export const HTTP_STATUS_CODE = {
77 CONFLICT : 409 ,
88 INTERNAL_SERVER_ERROR : 500 ,
99} as const ;
10+
11+ export const CACHE_TIME = {
12+ SHORT : 1000 * 60 * 3 ,
13+ MEDIUM : 1000 * 60 * 5 ,
14+ LONG : 1000 * 60 * 10 ,
15+ } as const ;
Original file line number Diff line number Diff line change @@ -14,7 +14,9 @@ export const ENDPOINTS = {
1414 type === "all" ? "" : `&type=${ type } `
1515 } `,
1616 CAPSULE_SEARCH_LISTS : ( keyword : string , page = 0 , size = 20 ) =>
17- `api/v1/capsules/search?keyword=${ encodeURIComponent ( keyword ) } &page=${ page } &size=${ size } ` ,
17+ `api/v1/capsules/search?keyword=${ encodeURIComponent (
18+ keyword
19+ ) } &page=${ page } &size=${ size } `,
1820
1921 LEAVE_CAPSULE : ( id : string ) => `api/v1/capsules/${ id } /leave` ,
2022 LIKE_TOGGLE : ( id : string ) => `api/v1/capsules/${ id } /like` ,
@@ -26,7 +28,9 @@ export const ENDPOINTS = {
2628 ) =>
2729 `api/v1/capsules/my?page=${ page } &size=${ size } &sort=${ sort } &filter=${ filter } ` ,
2830
31+ // 유저
2932 USER_INFO : "api/v1/users/my-info" ,
33+ TOTAL_USER_COUNT : "api/v1/users/total-count" ,
3034
3135 // 편지
3236 WRITE_LETTER : "api/v1/letters" ,
Original file line number Diff line number Diff line change @@ -5,3 +5,9 @@ export interface UserInfo {
55 email : string ;
66 } ;
77}
8+
9+ export interface TotalUserCountRes {
10+ result : {
11+ userTotalCount : number ;
12+ } ;
13+ }
You can’t perform that action at this time.
0 commit comments