Skip to content

Commit

Permalink
feat: modify removeTour action
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed Sep 29, 2024
1 parent 7e10446 commit 5cd60ee
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/features/trip/trip.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const useTripStore = create<TripState & TripAction>((set, get) => ({

const DAY = 60 * 60 * 24 * 1000;
const days =
Math.round(tourInfo.endTime.getTime() - tourInfo.startTime.getTime()) /
(Math.round(tourInfo.endTime.getTime() - tourInfo.startTime.getTime()) +
1) /
DAY;

return {
Expand All @@ -134,13 +135,19 @@ export const useTripStore = create<TripState & TripAction>((set, get) => ({
}),

removeTour: (day) =>
set((prev) => ({
...prev,
activities: [
...prev.activities.slice(0, day - 1),
...prev.activities.slice(day),
],
})),
set((prev) => {
const { tourInfo, activities } = prev;
if (!tourInfo.startTime || !tourInfo.endTime) return prev;

return {
...prev,
tourInfo: {
...tourInfo,
endTime: new Date(tourInfo.endTime.getTime() - 60 * 60 * 24 * 1000),
},
activities: [...activities.slice(0, day - 1), ...activities.slice(day)],
};
}),

addActivity: (day, activity) =>
set((prev) => ({
Expand Down

0 comments on commit 5cd60ee

Please sign in to comment.