Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Festivelo_frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Festivelo
Festivelo_frontend
Commits
0d6ea686
Commit
0d6ea686
authored
6 months ago
by
pjookim
Browse files
Options
Downloads
Patches
Plain Diff
fix: implement API call throttling in AddPlace component
parent
849b0755
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/AddPlace.js
+26
-13
26 additions, 13 deletions
src/components/AddPlace.js
src/pages/Home.js
+3
-2
3 additions, 2 deletions
src/pages/Home.js
with
29 additions
and
15 deletions
src/components/AddPlace.js
+
26
−
13
View file @
0d6ea686
...
...
@@ -15,6 +15,8 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa
const
[
favorites
,
setFavorites
]
=
useState
(
new
Set
());
const
[
favoriteItems
,
setFavoriteItems
]
=
useState
([]);
const
[
debouncedKeyword
,
setDebouncedKeyword
]
=
useState
(
searchKeyword
);
const
[
lastApiCall
,
setLastApiCall
]
=
useState
(
0
);
const
API_CALL_INTERVAL
=
2000
;
// 2초
const
[
tabStates
,
setTabStates
]
=
useState
({
attractions
:
{
...
...
@@ -72,11 +74,6 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa
}
};
const
cachedData
=
useRef
({
attractions
:
{
data
:
null
},
festivals
:
{
data
:
null
}
});
useEffect
(()
=>
{
const
handler
=
setTimeout
(()
=>
{
setDebouncedKeyword
(
searchKeyword
);
...
...
@@ -261,15 +258,31 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa
};
const
observerCallback
=
useCallback
(
entries
=>
{
console
.
log
(
'
스크롤 끝 인식
'
);
const
target
=
entries
[
0
];
const
currentState
=
tabStates
[
activeTab
];
if
(
target
.
isIntersecting
&&
currentState
.
hasMore
&&
!
currentState
.
loading
)
{
const
now
=
Date
.
now
();
const
timeToWait
=
API_CALL_INTERVAL
-
(
now
-
lastApiCall
);
if
(
timeToWait
<=
0
)
{
updateTabState
(
activeTab
,
{
pageNo
:
currentState
.
pageNo
+
1
});
setLastApiCall
(
now
);
console
.
log
(
'
API 호출 준비 완료
'
);
}
else
{
console
.
log
(
`API 호출 간격이 너무 짧습니다.
${
timeToWait
}
ms 후 재시도...`
);
setTimeout
(()
=>
{
updateTabState
(
activeTab
,
{
pageNo
:
currentState
.
pageNo
+
1
});
setLastApiCall
(
Date
.
now
());
console
.
log
(
'
대기 후 API 호출 준비 완료
'
);
},
timeToWait
);
}
},
[
tabStates
,
activeTab
]);
}
},
[
tabStates
,
activeTab
,
lastApiCall
]);
useEffect
(()
=>
{
const
observer
=
new
IntersectionObserver
(
observerCallback
,
{
...
...
@@ -382,8 +395,8 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa
items
.
map
(
async
(
item
)
=>
{
try
{
const
detailResponse
=
await
fetch
(
`
${
TOUR_API_BASE_URL
}
/detailIntro1?
`
+
`ServiceKey=
${
TOUR_API_KEY
}
`
+
`
${
TOUR_API_BASE_URL
}
/detailIntro1? +
`
`ServiceKey=
${
TOUR_API_KEY
}
`
+
`&contentId=
${
item
.
contentid
}
`
+
`&contentTypeId=15`
+
`&MobileOS=ETC`
+
...
...
This diff is collapsed.
Click to expand it.
src/pages/Home.js
+
3
−
2
View file @
0d6ea686
...
...
@@ -520,10 +520,11 @@ const Home = () => {
<
div
className
=
{
`map-container
${
showNewTrip
?
'
hidden
'
:
''
}
`
}
>
{
!
showNewTrip
&&
!
showDirection
&&
!
selectedPlace
&&
(
<
MapSearch
onPlaceSelect
=
{
handlePlaceSelect
}
map
=
{
map
}
markers
=
{
markers
}
onSearchResult
=
{
handleSearchResult
}
clearMap
=
{
clearMap
}
setMarkers
=
{
setMarkers
}
trips
=
{
trips
}
/
>
)}
<
Map
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment