diff --git a/myApp/HaruDanim/IOS/Views/ActionViews.swift b/myApp/HaruDanim/IOS/Views/ActionViews.swift index bdac8c1..8e60844 100644 --- a/myApp/HaruDanim/IOS/Views/ActionViews.swift +++ b/myApp/HaruDanim/IOS/Views/ActionViews.swift @@ -131,6 +131,7 @@ struct ActionListView: View { .swipeActions(edge: .leading, allowsFullSwipe: true) { Button { action.isFavorite.toggle() + DataChange.commit(context: context) } label: { Label( action.isFavorite ? String(localized: "즐겨찾기 해제") : String(localized: "즐겨찾기"), @@ -174,8 +175,13 @@ struct ActionRow: View { struct TagOrderSheet: View { @Environment(\.dismiss) private var dismiss + @Environment(\.modelContext) private var context @Query(sort: [SortDescriptor(\Tag.sortOrder), SortDescriptor(\Tag.createdAt)]) private var tags: [Tag] + /// 드래그로 순서가 바뀌었는지 — 시트가 닫힐 때 한 번만 커밋해 + /// 드래그마다 위젯·워치 갱신이 연발되지 않게 한다 + @State private var orderChanged = false + var body: some View { NavigationStack { List { @@ -191,6 +197,7 @@ struct TagOrderSheet: View { for (index, tag) in ordered.enumerated() { tag.sortOrder = index } + orderChanged = true } } .environment(\.editMode, .constant(.active)) @@ -203,6 +210,11 @@ struct TagOrderSheet: View { } } .presentationDetents([.medium, .large]) + .onDisappear { + // 꼬리표 순서는 워치 앱 그룹핑 순서에도 쓰이므로 닫힐 때 커밋 + // ('완료' 버튼과 스와이프 내리기 둘 다 이 경로를 지난다) + if orderChanged { DataChange.commit(context: context) } + } } } @@ -224,7 +236,11 @@ struct ActionDetailView: View { Spacer() Text(action.name).foregroundStyle(.secondary) } - Toggle(isOn: Bindable(action).isFavorite) { + // 리스트 스와이프 토글과 동일하게 변경 즉시 커밋 (저장 확정) + Toggle(isOn: Binding( + get: { action.isFavorite }, + set: { action.isFavorite = $0; DataChange.commit(context: context) } + )) { Label { Text("즐겨찾기") } icon: {