Skip to content

Commit bfc7cb0

Browse files
rtcode337claude
andauthored
経路表示中のリストから訪問済みスポットを自動で外す (#47)
地図で訪問予定リストを経路表示中に、そのリスト内のスポットへ新しく訪問記録を つけたら、自動でそのスポットをリストから外す。SpotDetailModal に新規訪問記録 専用の onVisitRecorded(spotId) を追加(編集・削除では発火しない)し、MapView 側で 表示中リスト(filters.planListId)に含まれるスポットなら update で除外する。 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1222d8a commit bfc7cb0

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

components/MapView.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,32 @@ export default function MapView({
10471047
cancelled = true;
10481048
};
10491049
}, [filters.planListId, planLists, spotById]);
1050+
1051+
// 地図で訪問予定リストを経路表示中に、そのリスト内のスポットへ新しく訪問記録したら、
1052+
// 自動でそのスポットをリストから外す(訪問済みが経路に残り続けないように)。
1053+
// 表示中のリスト(filters.planListId)にそのスポットが含まれるときだけ動く
1054+
const handleVisitRecorded = useCallback(
1055+
async (spotId: string) => {
1056+
const listId = filters.planListId;
1057+
if (!listId) return;
1058+
const list = planLists.find((l) => l.id === listId);
1059+
if (!list || !list.spot_ids.includes(spotId)) return;
1060+
const nextSpotIds = list.spot_ids.filter((id) => id !== spotId);
1061+
const { data } = await api.visitPlanLists.update(listId, {
1062+
title: list.title,
1063+
description: list.description,
1064+
start_date: list.start_date,
1065+
end_date: list.end_date,
1066+
spot_ids: nextSpotIds,
1067+
});
1068+
setPlanLists((prev) =>
1069+
prev.map((l) =>
1070+
l.id === listId ? (data ?? { ...l, spot_ids: nextSpotIds }) : l
1071+
)
1072+
);
1073+
},
1074+
[filters.planListId, planLists]
1075+
);
10501076
// マウント時と、マウント中に種別が切り替わった場合に、その種別の保存済み条件を読む
10511077
useEffect(() => {
10521078
setFiltersState(loadSavedFilters(spotTypeKey));
@@ -2718,6 +2744,7 @@ export default function MapView({
27182744
spots={spots}
27192745
onClose={() => setDetailSpotId(null)}
27202746
onVisitChange={loadVisits}
2747+
onVisitRecorded={handleVisitRecorded}
27212748
onSpotChange={(spot) => {
27222749
spotCache.applySpotChange(spot);
27232750
loadPrivateSpots();

components/SpotDetailModal.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default function SpotDetailModal({
7070
readOnly = false,
7171
onClose,
7272
onVisitChange,
73+
onVisitRecorded,
7374
onSpotChange,
7475
onSpotDeleted,
7576
onVisitPlanChange,
@@ -88,6 +89,10 @@ export default function SpotDetailModal({
8889
onClose: () => void;
8990
/** 訪問記録の追加・削除があったときに呼ばれる(呼び出し元の一覧・バッジ更新用) */
9091
onVisitChange?: () => void;
92+
/** 新しい訪問記録が追加されたときだけ、そのスポットIDとともに呼ばれる
93+
* (地図で経路表示中の訪問予定リストから、訪問済みスポットを自動で外すのに使う。
94+
* 訪問記録の編集・削除では呼ばれない) */
95+
onVisitRecorded?: (spotId: string) => void;
9196
/** スポット自体の編集・承認/却下で内容が変わったときに、変更後の内容とともに呼ばれる
9297
* (呼び出し元の一覧の再取得・公開スポットキャッシュの更新用) */
9398
onSpotChange?: (spot: Spot) => void;
@@ -648,6 +653,8 @@ export default function SpotDetailModal({
648653
// 訪問記録時、サーバー側で訪問予定からも自動的に外れる
649654
onVisitPlanChange?.();
650655
onReviewChange?.();
656+
// 地図で経路表示中の訪問予定リストから、訪問済みスポットを自動で外す
657+
onVisitRecorded?.(spot.id);
651658
}}
652659
/>
653660
)}

0 commit comments

Comments
 (0)